Example #1
0
		private Thread ConfigureBatchAgent(Processor processorInstance, bool startAtOnce)
		{
			string strInboundQ, strOutboundQ;
			string strQueueReceiveSP;
			string strQueueSendSP;
			string strQueueRemoveSP;
			bool blnUseSqlAgent = false;

			// Work out which Batch Agent type to use, pass the Processor to it, and configure inter-class calls
			blnUseSqlAgent = bool.Parse(ConfigurationManager.AppSettings.Get("UseSqlBatchAgent"));
			if (blnUseSqlAgent == false)
			{
				// Create instance of the Message Queue Based Agent that will perform Batch Mode processing
                strInboundQ = ConfigurationManager.AppSettings.Get("InboundQueuePath");
                strOutboundQ = ConfigurationManager.AppSettings.Get("OutboundQueuePath");
				mobjBatchAgent = new BatchAgent(strInboundQ, strOutboundQ, processorInstance);

				// Configure Polling Interval at which BatchAgent queries Inbound Queue
                if (ConfigurationManager.AppSettings.Get("InboundPollingInterval") != null)
				{
					int intPollingMinutes;
                    intPollingMinutes = int.Parse(ConfigurationManager.AppSettings.Get("InboundPollingInterval"));
					mobjBatchAgent.PollingInterval = new TimeSpan(0, 0, intPollingMinutes, 0, 0);
				}

				// Wire child BatchAgent class to Pass Exceptions up to Service instance 
				mobjBatchAgent.OnException -= new BatchAgent.HandleException(mobjBatchAgent.InvokeHandleException);
				mobjBatchAgent.OnException += new BatchAgent.HandleException(this.InvokeHandleException);

				// Wire Service instance to call BatchAgent copy of method for OnCallback
				// The main Service thread passes thru requests from Servers to the Batch Agent
				this.OnCallback -= new ParentCallback(this.InvokeParentCallback);
				this.OnCallback += new ParentCallback(mobjBatchAgent.InvokeParentCallback);

				// Allocate Agent to thread
				mobjBatchThread = new Thread(new ThreadStart(mobjBatchAgent.Poll));
			}
			else
			{
				//// Create instance of the Sql Server Based Agent that will perform Batch Mode processing
				//strQueueReceiveSP = ConfigurationSettings.AppSettings.Get("QueueReceiveSP");
				//strQueueSendSP = ConfigurationSettings.AppSettings.Get("QueueSendSP");
				//strQueueRemoveSP = ConfigurationSettings.AppSettings.Get("QueueRemoveSP");
				//mobjSqlBatchAgent = new SqlBatchAgent(strQueueReceiveSP,strQueueSendSP,strQueueRemoveSP,objProcessor);

				//// Configure Polling Interval at which SqlBatchAgent queries SQL Server Queue table
				//if (ConfigurationSettings.AppSettings.Get("SqlQueuePollingInterval") != null)
				//{
				//    int intPollingMinutes;
				//    intPollingMinutes=int.Parse(ConfigurationSettings.AppSettings.Get("SqlQueuePollingInterval"));
				//    mobjSqlBatchAgent.PollingInterval=new TimeSpan(0,0,intPollingMinutes,0,0);
				//}

				//// Wire Service instance to call BatchAgent copy of method for OnCallback
				//// The main Service thread passes thru requests from Servers to the Batch Agent
				//this.OnCallback-= new ParentCallback(this.InvokeParentCallback);
				//this.OnCallback+= new ParentCallback(mobjSqlBatchAgent.InvokeParentCallback);

				//// Wire child SqlBatchAgent class to Pass Exceptions up to Service instance 
				//mobjSqlBatchAgent.OnException -= new SqlBatchAgent.HandleException(mobjSqlBatchAgent.InvokeHandleException);
				//mobjSqlBatchAgent.OnException += new SqlBatchAgent.HandleException(this.InvokeHandleException);

				//// Allocate Agent to thread
				//mobjBatchThread = new Thread(new ThreadStart(mobjSqlBatchAgent.Poll));
			}

			// Run on a background thread
			mobjBatchThread.Name = "Thread_BatchAgent";
			mobjBatchThread.IsBackground = true;
			if (startAtOnce == true)
			{
				mobjBatchThread.Start();
			}

			return mobjBatchThread;
		}
Example #2
0
		protected override void Dispose(bool disposing) 
		{
			if (disposing) 
			{
				// Release managed resources.
			}
			// Release local resources.

			/*
			// Kill external processes
			if (mobjExternalProcess != null)
			{
				mobjExternalProcess.Kill();
				mobjExternalProcess= null;
			}
			*/

			// Work Manager disposal
			if (mobjWorkManager != null)
			{
				mobjWorkManager.Shutdown();
				mobjWorkManager = null;
			}

			// Batch Agent disposal
			if (mobjBatchThread != null)
			{
				mobjBatchThread.Abort();
				mobjBatchThread=null;
			}
			if (mobjBatchAgent != null)
			{
				mobjBatchAgent.Shutdown();
				mobjBatchAgent=null;
			}

			// Batch Monitor disposal
			if (mobjMonitorThread != null)
			{
				mobjMonitorThread.Abort();
				mobjMonitorThread=null;
			}
			//if (mobjBatchMonitor != null)
			//{
			//    mobjBatchMonitor.Shutdown();
			//    mobjBatchMonitor=null;
			//}

			// Destroy Tcp Servers, including all their Tcp Clients and asynch threads
			if (marrServers != null)
			{
				foreach (Server objServer in marrServers)
				{
					objServer.Shutdown();
				}
				marrServers=null;
			}

			//// Call Dispose on Base
			//Base.Dispose(disposing);
		}
Example #3
0
		private Thread ConfigureWorkManager(bool startAtOnce)
		{
			// Create a Processor instance that will physically process all incoming work
			mobjWorkManager = new Processor(); 

			// Wire child Work Manager class to Pass Exceptions up to Service instance 
			mobjWorkManager.OnException -= new Processor.HandleException(mobjWorkManager.InvokeHandleException);
			mobjWorkManager.OnException += new Processor.HandleException(this.InvokeHandleException);

			// Wire Service instance to call Work Manager copy of method for OnCallback
			// The main Service thread passes thru requests from Servers to the Work Manager
			this.OnCallback -= new ParentCallback(this.InvokeParentCallback);
			this.OnCallback += new ParentCallback(mobjWorkManager.InvokeParentCallback);

			// Allocate Agent to thread
			mobjWorkManagerThread = new Thread(new ThreadStart(mobjWorkManager.Process));

			// Run on a background thread
			mobjWorkManagerThread.Name = "Thread_WorkManager";
			mobjWorkManagerThread.IsBackground = true;
			if (startAtOnce == true)
			{
				mobjWorkManagerThread.Start();
			}

			return mobjWorkManagerThread;
		}