private void MQRecieve() //MQ接收函数
{
try
{
bool isWebServiceSuccess = WebServiceStart(); //通过WebService传请求条件
if (isWebServiceSuccess == false)
{
System.Windows.Forms.MessageBox.Show("调用webservice出错...", "提示", MessageBoxButtons.OK);
ThreadClose();
return;
}
using (MqConsumer mqConsumer = new MqConsumer(uri, curLogRequestCondition.destination, false, false))
{
TMsgHandler callback = new TMsgHandler(RecieveData); //回调函数绑定处理接收数据的函数
mqConsumer.SetMsgHandler(callback);
mqConsumer.runConsumer();
while (!isStopped)
{
Thread.Sleep(5000);
}
mqConsumer.CloseMq();
}
}
catch
{
isStopped = true;
}
}
protected void RecieveData(string message) //处理接收数据的函数
{
try
{
iflag++;
if (message.IndexOf("END_") == -1)//不是END_
{
dataList.Add(message);
}
if (message.IndexOf("END_") != -1)//接收结束
{
GetLogDataEvent.Invoke(dataList);
dataList.Clear();
if (iflag == 1)
{
MessageBox.Show("没有查到符号条件的日志信息");
}
}
else if (iflag % 1000 == 0)
{
GetLogDataEvent.Invoke(dataList);
dataList.Clear();
}
}
catch
{
isStopped = true;
}
}
private bool
WebServiceStart() {
try
{
OSSDOM.CMT.CommonUse.LogService.LogRequest curCondition = curLogRequestCondition;
OSSDOM.CMT.CommonUse.LogService.Service1 logService1 = new OSSDOM.CMT.CommonUse.LogService.Service1();
logService1.Url = OSSDOM.Common.Function.PubFunction.ReadXmlFileNode("Config\\WebServiceConfig.xml", "/configuration/LogService");
if (ServerConnState.serverConnected == false)
{
logService1.Url = logService1.Url.Replace(MakeOptionDatas.MakeOptionDataInstance.proxy.strProxyIP, MakeOptionDatas.MakeOptionDataInstance.StandbyProxy.strProxyIP);
}
bool isTranSuccess = logService1.GetLogRequest(curCondition);
return isTranSuccess;
}
catch
{
return false;
}
}
1using System;
2using System.Collections.Generic;
3using MqWrapper;
4using System.Threading;
5using System.Text;
6using OSSDOM.Common;
7using System.Windows.Forms;
8using OSSDOM.CMT.ConfigData;
9
10namespace OSSDOM.CMT.CommonUse.MQ
11{
12 public delegate void GetLogDataHandle(List<string> logRecData);
13 public class MQReceive_Log
14 {
15 variable#region variable
16 //请求条件
17 private OSSDOM.CMT.CommonUse.LogService.LogRequest curLogRequestCondition = new OSSDOM.CMT.CommonUse.LogService.LogRequest();
18
19 //
20 private volatile bool isStopped = false;
21 private Thread recThread = null;
22
23 private string uri;
24 public event GetLogDataHandle GetLogDataEvent;
25 #endregion
26
27 property#region property
28 public OSSDOM.CMT.CommonUse.LogService.LogRequest CurLogRequestCondition
29 {
30 get { return curLogRequestCondition; }
31 set { curLogRequestCondition = value; }
32 }
33
34 public string Uri
35 {
36 get { return uri; }
37 set { uri = value; }
38 }
39 #endregion
40
41 Method#region Method
42 public void MQReceiveDataStart()
43 {
44 try
45 {
46 recThread = new Thread(new ThreadStart(MQRecieve));
47 recThread.IsBackground = true;
48 recThread.Start();
49 }
50 catch(Exception ex)
51 {
52 System.Windows.Forms.MessageBox.Show(ex.Message + " " + ex.StackTrace);
53 ThreadClose();
54 }
55 }
56 public void ThreadClose()
57 {
58 if (recThread != null && recThread.ThreadState == ThreadState.Running)
59 {
60 recThread.Abort();
61 isStopped = true;
62 }
63 }
64 private void MQRecieve()
65 {
66 try
67 {
68 bool isWebServiceSuccess = WebServiceStart();
69 if (isWebServiceSuccess == false)
70 {
71 System.Windows.Forms.MessageBox.Show("调用webservice出错", "提示", MessageBoxButtons.OK);
72 ThreadClose();
73 return;
74 }
75 using (MqConsumer mqConsumer = new MqConsumer(uri, curLogRequestCondition.destination, false, false))
76 {
77 TMsgHandler callback = new TMsgHandler(RecieveData);
78 mqConsumer.SetMsgHandler(callback);
79
80 mqConsumer.runConsumer();
81 while (!isStopped)
82 {
83 Thread.Sleep(5000);
84 }
85 mqConsumer.CloseMq();
86 }
87 }
88 catch
89 {
90 isStopped = true;
91 }
92 }
93 private int iflag = 0;
94 List<string> dataList = new List<string>();
95 protected void RecieveData(string message)
96 {
97 try
98 {
99 iflag++;
100 if (message.IndexOf("END_") == -1)//不是END_
101 {
102 dataList.Add(message);
103 }
104 if (message.IndexOf("END_") != -1)//接收结束
105 {
106 GetLogDataEvent.Invoke(dataList);
107 dataList.Clear();
108 if (iflag == 1)
109 {
110 MessageBox.Show("没有查到符号条件的日志信息");
111 }
112 }
113 else if (iflag % 1000 == 0)
114 {
115 GetLogDataEvent.Invoke(dataList);
116 dataList.Clear();
117 }
118 }
119 catch
120 {
121 isStopped = true;
122 }
123 }
124 private bool WebServiceStart()
125 {
126 try
127 {
128 OSSDOM.CMT.CommonUse.LogService.LogRequest curCondition = curLogRequestCondition;
129 OSSDOM.CMT.CommonUse.LogService.Service1 logService1 = new OSSDOM.CMT.CommonUse.LogService.Service1();
130 logService1.Url = OSSDOM.Common.Function.PubFunction.ReadXmlFileNode("Config\\WebServiceConfig.xml", "/configuration/LogService");
131 if (ServerConnState.serverConnected == false)
132 {
133 logService1.Url = logService1.Url.Replace(MakeOptionDatas.MakeOptionDataInstance.proxy.strProxyIP, MakeOptionDatas.MakeOptionDataInstance.StandbyProxy.strProxyIP);
134 }
135 bool isTranSuccess = logService1.GetLogRequest(curCondition);
136 return isTranSuccess;
137 }
138 catch
139 {
140 return false;
141 }
142 }
143 #endregion
144 }
145}
146
posted on 2010-02-08 09:04
天书 阅读(570)
评论(0) 编辑 收藏 引用