FMStocks7 , 不错的一个.NET 示例程序
生活随笔
收集整理的這篇文章主要介紹了
FMStocks7 , 不错的一个.NET 示例程序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這個示例程序估計很多人都用過。沒有用過的話可以從
http://www.microsoft.com/downloads/details.aspx?FamilyID=966C3279-2EE9-4E14-A4F7-D4807239A396&displaylang=en 下載
一個簡單的股票買賣程序,數(shù)據(jù)庫訪問和部分業(yè)務邏輯提供了 COM+ 企業(yè)服務和 DotNet Remoting 兩種方式。
具體的架構參考一下圖:
兩種分布式應用,有一下特征,呵呵。 msdn 說得
1。清晰的應用程序架構,由于問題比較簡單。很容易整理清楚
2。 很好的coding 風格。最近在整理公司的代碼規(guī)范,發(fā)現(xiàn) FMStocks7 的代碼注釋確實不錯。
比如一下是 買一個新股票的 DAO 代碼
????????/**////????<summary>
????????///????Purchase?shares?of?a?specific?stock.????????
????????///?<param?name='accountID'>The?accountID?number</param>
????????///????<param?name='txID'>The?transaction?ID</param>
????????///????<param?name='ticker'>The?ticker?symbol?to?be?purchased</param>
????????///????<param?name='shares'>Amount?of?shares</param>
????????///????<param?name='sharePrice'>The?share?price</param>
????????///????<param?name='commission'>The?buy?commission</param>
????????///????<returns>BrokerStatus?enum?value</returns>
????????///?</summary>
????????public?BrokerStatus?Buy(?int?accountID,?int?txID,?string?ticker,?int?shares,?decimal?sharePrice,?decimal?commission?)
????????{
????????????Debug.Assert(?sproc?==?null?);
????????????try????{
????????????????BrokerStatus?status;
????????????
????????????????//?Initialize?order?info
????????????????Order?order;
????????????????order.AccountID??=?accountID;
????????????????order.TxID???????=?txID;
????????????????order.Ticker?????=?ticker;
????????????????order.Shares?????=?shares;
????????????????order.SharePrice?=?sharePrice;
????????????????order.Commission?=?commission;
????????????????//?Debit?account?balance
????????????????decimal?debitAmt?=?(?decimal?)order.Shares?*?order.SharePrice?+?order.Commission;
????????????????GAM?gam?=?new?GAM();
????????????????if?(?gam.DebitAccountBalance(?order.AccountID,?debitAmt??)?==?0?)
????????????????{
????????????????????status?=?BrokerStatus.InsufficientFunds;
????????????????????ContextUtil.SetAbort();
????????????????}
????????????????else
????????????????{
??????????????????????//?Create?parameter?array
????????????????????SqlParameter[]?parameters?=
????????????????????{
????????????????????????new?SqlParameter(?"@TxID",???????SqlDbType.Int,???4?),?//?0
????????????????????????new?SqlParameter(?"@AccountID",??SqlDbType.Int,???4?),?//?1
????????????????????????new?SqlParameter(?"@Ticker",?????SqlDbType.NChar,?6?),?//?2
????????????????????????new?SqlParameter(?"@Shares",?????SqlDbType.Int,???4?),?//?3
????????????????????????new?SqlParameter(?"@SharePrice",?SqlDbType.Money,?8?),?//?4
????????????????????????new?SqlParameter(?"@Commission",?SqlDbType.Money,?8?),?//?5
????????????????????};
????????????????????//?Set?parameter?values?and?directions
????????????????????parameters[?0?].Value?=?order.TxID;
????????????????????parameters[?1?].Value?=?order.AccountID;
????????????????????parameters[?2?].Value?=?order.Ticker;
????????????????????parameters[?3?].Value?=?order.Shares;
????????????????????parameters[?4?].Value?=?order.SharePrice;
????????????????????parameters[?5?].Value?=?order.Commission;
????????????????????//?Run?the?stored?procedure
????????????????????sproc?=?new?StoredProcedure(?"Broker_Buy",?parameters?);
????????????????????int?error?=?sproc.Run();
????????????????????Debug.Assert(?error?==?0?);
????????????????????status?=?BrokerStatus.Success;
????????????????????ContextUtil.SetComplete();
????????????????}
????????????????return?status;
????????????}
????????????catch
????????????{
????????????????ContextUtil.SetAbort();
????????????????throw;
????????????}
????????}
有幾點很符合代碼規(guī)范
1。合理的使用斷言
2。// 注釋風格
3。異常處理
4。。。。
http://www.microsoft.com/downloads/details.aspx?FamilyID=966C3279-2EE9-4E14-A4F7-D4807239A396&displaylang=en 下載
一個簡單的股票買賣程序,數(shù)據(jù)庫訪問和部分業(yè)務邏輯提供了 COM+ 企業(yè)服務和 DotNet Remoting 兩種方式。
具體的架構參考一下圖:
兩種分布式應用,有一下特征,呵呵。 msdn 說得
- ASP.NET 應用程序(通過 IIS)承載遠程組件以利用進程回收等功能和應用程序配置。
- 通過 HTTP 信道使用二進制格式化程序進行遠程調用。使用 HTTP 信道將能夠使用 IIS 承載組件,而二進制格式化程序的性能優(yōu)于 SOAP 格式化程序。
- GAM 和 BLL 對象都是無狀態(tài)的,這使得可以在 Application Center 群集中承載它們。
- 雖然 GAM 和 BLL 對象是無狀態(tài)的,但 Fitch and Mather 7.0 使用實例方法(與靜態(tài)方法相對)以便能夠遠程處理方法調用。靜態(tài)方法總是在本地執(zhí)行,即與調用方在同一個 AppDomain 類中執(zhí)行。有關更多信息,請參見。
當然對于第一點,你也可以host? Remoting 對象在一個 console 應用程序或者 windows 服務中。從而可以使用 TCP/Binary. 缺點TCP 需要自己去考慮安全監(jiān)聽。
1。清晰的應用程序架構,由于問題比較簡單。很容易整理清楚
2。 很好的coding 風格。最近在整理公司的代碼規(guī)范,發(fā)現(xiàn) FMStocks7 的代碼注釋確實不錯。
比如一下是 買一個新股票的 DAO 代碼
????????/**////????<summary>
????????///????Purchase?shares?of?a?specific?stock.????????
????????///?<param?name='accountID'>The?accountID?number</param>
????????///????<param?name='txID'>The?transaction?ID</param>
????????///????<param?name='ticker'>The?ticker?symbol?to?be?purchased</param>
????????///????<param?name='shares'>Amount?of?shares</param>
????????///????<param?name='sharePrice'>The?share?price</param>
????????///????<param?name='commission'>The?buy?commission</param>
????????///????<returns>BrokerStatus?enum?value</returns>
????????///?</summary>
????????public?BrokerStatus?Buy(?int?accountID,?int?txID,?string?ticker,?int?shares,?decimal?sharePrice,?decimal?commission?)
????????{
????????????Debug.Assert(?sproc?==?null?);
????????????try????{
????????????????BrokerStatus?status;
????????????
????????????????//?Initialize?order?info
????????????????Order?order;
????????????????order.AccountID??=?accountID;
????????????????order.TxID???????=?txID;
????????????????order.Ticker?????=?ticker;
????????????????order.Shares?????=?shares;
????????????????order.SharePrice?=?sharePrice;
????????????????order.Commission?=?commission;
????????????????//?Debit?account?balance
????????????????decimal?debitAmt?=?(?decimal?)order.Shares?*?order.SharePrice?+?order.Commission;
????????????????GAM?gam?=?new?GAM();
????????????????if?(?gam.DebitAccountBalance(?order.AccountID,?debitAmt??)?==?0?)
????????????????{
????????????????????status?=?BrokerStatus.InsufficientFunds;
????????????????????ContextUtil.SetAbort();
????????????????}
????????????????else
????????????????{
??????????????????????//?Create?parameter?array
????????????????????SqlParameter[]?parameters?=
????????????????????{
????????????????????????new?SqlParameter(?"@TxID",???????SqlDbType.Int,???4?),?//?0
????????????????????????new?SqlParameter(?"@AccountID",??SqlDbType.Int,???4?),?//?1
????????????????????????new?SqlParameter(?"@Ticker",?????SqlDbType.NChar,?6?),?//?2
????????????????????????new?SqlParameter(?"@Shares",?????SqlDbType.Int,???4?),?//?3
????????????????????????new?SqlParameter(?"@SharePrice",?SqlDbType.Money,?8?),?//?4
????????????????????????new?SqlParameter(?"@Commission",?SqlDbType.Money,?8?),?//?5
????????????????????};
????????????????????//?Set?parameter?values?and?directions
????????????????????parameters[?0?].Value?=?order.TxID;
????????????????????parameters[?1?].Value?=?order.AccountID;
????????????????????parameters[?2?].Value?=?order.Ticker;
????????????????????parameters[?3?].Value?=?order.Shares;
????????????????????parameters[?4?].Value?=?order.SharePrice;
????????????????????parameters[?5?].Value?=?order.Commission;
????????????????????//?Run?the?stored?procedure
????????????????????sproc?=?new?StoredProcedure(?"Broker_Buy",?parameters?);
????????????????????int?error?=?sproc.Run();
????????????????????Debug.Assert(?error?==?0?);
????????????????????status?=?BrokerStatus.Success;
????????????????????ContextUtil.SetComplete();
????????????????}
????????????????return?status;
????????????}
????????????catch
????????????{
????????????????ContextUtil.SetAbort();
????????????????throw;
????????????}
????????}
有幾點很符合代碼規(guī)范
1。合理的使用斷言
2。// 注釋風格
3。異常處理
4。。。。
總結
以上是生活随笔為你收集整理的FMStocks7 , 不错的一个.NET 示例程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于编译C#文件
- 下一篇: ASP.NET AJAX入门系列(10)