程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#消息隊列應用程序(3)

C#消息隊列應用程序(3)

編輯:關於C語言

對此信息的訪問通過來自 System.Configuration 程序集的 ConfigManager 類來管理。靜態 Get 方法返回信息的集合,這些集合將被枚舉以獲得單個屬性。這些屬性集的設置決定了輔助對象的運行時特征。除了這一配置文件,您還應該創建定義 XML 文件結構的圖元文件,並在其中引用位於服務器 Machine.cfg 配置文件中的圖元文件:

<?XML version ="1.0"?>
<MetaData XMLns="x-schema:CatMeta.xms">
 <DatabaseMeta InternalName="MessageService">
 <ServerWiring Interceptor="Core_XMLInterceptor"/>
 <Collection
   InternalName="Process" PublicName="ProcessList"
   PublicRowName="ProcessDefinition"
   SchemaGeneratorFlags="EMITXMLSCHEMA">
  <Property InternalName="ProcessName" Type="String" MetaFlags="PRIMARYKEY" />
  <Property InternalName="ProcessDesc" Type="String" />
  <Property InternalName="ProcessType" Type="Int32" DefaultValue="RoundRobin" >
   <Enum InternalName="RoundRobin" Value="0"/>
   <Enum InternalName="APPSpecific" Value="1"/>
   <Enum InternalName="Assembly" Value="2"/>
  </Property>
  <Property InternalName="ProcessThreads" Type="Int32" DefaultValue="1" />
  <Property InternalName="InputQueue" Type="String" />
  <Property InternalName="ErrorQueue" Type="String" />
  <Property InternalName="OutputName" Type="String" />
  <QueryMeta InternalName="All" MetaFlags="ALL" />
  <QueryMeta InternalName="QueryByFile" CellName="__FILE" Operator="EQUAL" />
 </Collection>
 <Collection
   InternalName="Output" PublicName="OutputList"
   PublicRowName="OutputDefinition"
   SchemaGeneratorFlags="EMITXMLSCHEMA">
  <Property InternalName="ProcessName" Type="String" MetaFlags="PRIMARYKEY" />
  <Property InternalName="OutputName" Type="String" MetaFlags="PRIMARYKEY" />
   <QueryMeta InternalName="All" MetaFlags="ALL" />
   <QueryMeta InternalName="QueryByFile" CellName="__FILE" Operator="EQUAL" />
  </Collection>
 </DatabaseMeta>
 <RelationMeta
   PrimaryTable="Process" PrimaryColumns="ProcessName"
   ForeignTable="Output" ForeignColumns="ProcessName"
   MetaFlags="USECONTAINMENT"/>
</MetaData>

由於 Service 類必須維護一個已創建輔助對象的列表,因此使用了 Hashtable 集合,用於保持類型對象的名稱/數值對列表。Hashtable 不僅支持枚舉,還允許通過關鍵字來查詢值。在應用程序中,XML 進程名稱是唯一的關鍵字:

private Hashtable htWorkers = new Hashtable();
IConfigCollection cWorkers = ConfigManager.Get("ProcessList", new AppDomainSelector());
foreach (IConfigItem ciWorker in cWorkers)
{
 WorkerFormatter sfWorker = new WorkerFormatter();
 sfWorker.ProcessName = (string)ciWorker["ProcessName"];
 sfWorker.ProcessDesc = (string)ciWorker["ProcessDesc"];
 sfWorker.NumberThreads = (int)ciWorker["ProcessThreads"];
 sfWorker.InputQueue = (string)ciWorker["InputQueue"];
 sfWorker.ErrorQueue = (string)ciWorker["ErrorQueue"];
 // 計算並定義進程類型
 switch ((int)ciWorker["ProcessType"])
 {
  case 0:
   sfWorker.ProcessType = WorkerFormatter.SFProcessType.ProcessRoundRobin;
   break;
  case 1:
   sfWorker.ProcessType = WorkerFormatter.SFProcessType.ProcessAPPSpecific;
   break;
  case 2:
   sfWorker.ProcessType = WorkerFormatter.SFProcessType.ProcessAssembly;
   break;
  default:
  throw new Exception("Unknown Processing Type");
 }
 // 執行更多的工作以讀取輸出信息
 string sProcessName = (string)ciWorker["ProcessName"];
 if (htWorkers.ContainsKey(sProcessName))
  throw new ArgumentException("Process Name Must be Unique: " + sProcessName);
  htWorkers.Add(sProcessName, new CWorker(sfWorker));
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved