/[projects]/dao/DaoMqPump2/MQFilter/FilterService.cs
ViewVC logotype

Annotation of /dao/DaoMqPump2/MQFilter/FilterService.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2160 - (hide annotations) (download)
Fri May 16 15:44:17 2014 UTC (10 years ago) by torben
File size: 4279 byte(s)
Add verybasic filter code(template)
1 torben 2160 using System;
2     using System.Threading;
3    
4     using System.Diagnostics;
5    
6     using System.ServiceModel;
7     using System.ServiceModel.Description;
8    
9    
10     namespace MQFilter
11     {
12    
13     [System.ComponentModel.DesignerCategory("Code")]
14     class PumpService : System.ServiceProcess.ServiceBase
15     {
16     const int INTERVAL = 5;
17     TimeSpan m_delay = new TimeSpan(0, 0, 0, INTERVAL, 0);
18    
19     private Thread m_thread = null;
20     private static ManualResetEvent m_shutdownEvent = new ManualResetEvent(false);
21    
22    
23    
24    
25    
26     FilterController filterController = null;
27    
28    
29     ServiceHost selfHost;
30    
31    
32     protected void InitializeComponent()
33     {
34    
35     // Initialize the operating properties for the service.
36     this.CanPauseAndContinue = false;
37     this.CanShutdown = true;
38     this.CanHandleSessionChangeEvent = true;
39     this.ServiceName = "DaoMqPump2";
40     }
41    
42     // Start the service.
43     protected override void OnStart(string[] args)
44     {
45     try
46     {
47     //first load transports
48     filterController = FilterController.getInstance();
49    
50    
51     //finally start the worker thread
52     // create our threadstart object to wrap our delegate method
53     ThreadStart ts = new ThreadStart(this.ServiceWorkerMethod);
54    
55     // create the manual reset event and
56     // set it to an initial state of unsignaled
57     m_shutdownEvent = new ManualResetEvent(false);
58    
59     // create the worker thread
60     m_thread = new Thread(ts);
61    
62     // go ahead and start the worker thread
63     m_thread.Start();
64    
65     }
66     catch (Exception e)
67     {
68     EventLog.WriteEntry("MQFilter", "Error starting DaoMqPump2: " + e.Message, EventLogEntryType.Error);
69     throw e;
70     }
71     }
72    
73     // Stop this service.
74     protected override void OnStop()
75     {
76     // New in .NET Framework version 2.0.
77     this.RequestAdditionalTime(10000);
78    
79     // signal the event to shutdown
80     m_shutdownEvent.Set();
81    
82     // wait for the thread to stop giving it 10 seconds
83     m_thread.Join(10000);
84    
85     // call the base class
86     base.OnStop();
87    
88     this.ExitCode = 0;
89     }
90    
91    
92     public void ServiceWorkerMethod()
93     {
94     bool bSignaled = false;
95     int count = 20; //count starts high so we get to pump during the first iteration
96     try
97     {
98     do
99     {
100     // Block if the service is paused or is shutting down.
101     bSignaled = m_shutdownEvent.WaitOne(m_delay, true);
102    
103     // if we were signaled to shutdow, exit the loop
104     if (bSignaled == true)
105     break;
106    
107     count ++;
108    
109     int elapsed = INTERVAL * count;
110     if (elapsed >= 30) // only run every 30th second
111     {
112     filterController.transportAllMessages();
113     count = 0;//reset counter
114     }
115    
116     }
117     while (true);
118     }
119     catch (ThreadAbortException)
120     {
121     // Another thread has signalled that this worker
122     // thread must terminate. Typically, this occurs when
123     // the main service thread receives a service stop
124     // command.
125    
126     // Write a trace line indicating that the worker thread
127     // is exiting. Notice that this simple thread does
128     // not have any local objects or data to clean up.
129     }
130     }
131    
132    
133     }
134    
135     public class GrantningAuthorizationManager : ServiceAuthorizationManager
136     {
137     protected override bool CheckAccessCore(OperationContext operationContext)
138     {
139     return true;
140     }
141     }
142     }

  ViewVC Help
Powered by ViewVC 1.1.20