Helper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
//检测端口是否使用
public static bool VerifyListenerPort(int port)
{
    bool inUse = false;
    System.Net.NetworkInformation.IPGlobalProperties ipProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
    IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
    if (port > 65535) return true;// 超出范围
    foreach (IPEndPoint endPoint in ipEndPoints)
    {
        if (endPoint.Port == port)
        {
            inUse = true;
            break;
        }
    }
    return inUse;
}
 
 
public class rep_QueryACLReviewHistInfo
    {
        private int _result;
        private string _errorDesc = "";
        private long _histListNo;
        private static int MAX_REVIEW_HIST_CNT = 100;
        private ArrayWrapper<Typ_ACLReviewHistInfo> _histList = new ArrayWrapper<Typ_ACLReviewHistInfo>(MAX_REVIEW_HIST_CNT);
 
        public int result
        {
            get { return _result; }
            set { _result = value; }
        }
 
        public string errorDesc
        {
            get { return _errorDesc; }
            set { _errorDesc = value; }
        }
 
        public long histListNo
        {
            get { return _histListNo; }
            set
            {
                if (value > MAX_REVIEW_HIST_CNT)
                {
                    throw new Exception("histListNo must be less than MAX_REVIEW_HIST_CNT (100).");
                }
                _histListNo = value;
            }
        }
 
        public ArrayWrapper<Typ_ACLReviewHistInfo> histList
        {
            get { return _histList; }
        }
    }
public static bool rqst_QueryReviewHistInfo_to_XMLObject(rqst_QueryACLReviewHistInfo userData, ref string xmlStr, out string errDesc)
        {
            bool funcResult = false;
            errDesc = "";
            StringBuilder tmpStr = null;
            StringWriter xmlWriter = null;
            XmlTextWriter textWriter = null;
 
            try
            {
                tmpStr = new StringBuilder(xmlStr);
                xmlWriter = new StringWriter();
                textWriter = new XmlTextWriter(xmlWriter);
                textWriter.WriteStartElement("msgBody");
                textWriter.WriteElementString("instanceSysId", userData.instanceSysId);
                textWriter.WriteElementString("reviewNo", userData.reviewNo.ToString());
 
                textWriter.WriteEndElement();
                xmlStr = tmpStr.Append(xmlWriter.ToString()).ToString();
                funcResult = true;
            }
            catch (Exception e)
            {
                errDesc = e.Message;
                funcResult = false;
            }
            finally
            {
                xmlWriter.Close();
                textWriter.Close();
            }
 
            return funcResult;
        }
 
        public static bool rep_QueryReviewHistInfo_from_XMLObject(string xmlStr, ref rep_QueryACLReviewHistInfo userData, out string errDesc)
        {
            bool funcResult = false;
            errDesc = "";
            StringReader xmlReader = null;
            XmlTextReader textReader = null;
            Dictionary<string, bool> dicFlag = null;
            bool OuterxmlFlag = false;
 
            try
            {
                xmlReader = new StringReader(xmlStr);
                textReader = new XmlTextReader(xmlReader);
                dicFlag = new Dictionary<string, bool>();
                int histListIndex = 0;
 
                while (!textReader.EOF)
                {
                    if (OuterxmlFlag == true)
                    {
                        OuterxmlFlag = false;
                    }
                    else
                    {
                        textReader.Read();
                    }
 
                    dicFlag[textReader.Name] = true;
                    if (textReader.IsEmptyElement)
                    {
                        continue;
                    }
 
                    if (textReader.NodeType == XmlNodeType.Element)
                    {
                        switch (textReader.Name)
                        {
                            case "result":
                                userData.result = int.Parse(textReader.ReadString());
                                break;
 
                            case "errorDesc":
                                userData.errorDesc = textReader.ReadString();
                                break;
 
                            case "histListNo":
                                userData.histListNo = int.Parse(textReader.ReadString());
                                break;
 
                            case "histList":
                                string tempStr = textReader.ReadOuterXml();
                                OuterxmlFlag = true;
                                Typ_ACLReviewHistInfo temp_Typ_ACLReviewHistInfo = new Typ_ACLReviewHistInfo();
                                if (MsgTyp.Typ_ACLReviewHistInfo_from_XMLObject(tempStr, ref temp_Typ_ACLReviewHistInfo, out errDesc))
                                {
                                    userData.histList[histListIndex] = temp_Typ_ACLReviewHistInfo;
                                    histListIndex++;
                                }
                                else
                                {
                                    return false;
                                }
                                break;
                        }
                    }
                }
 
                if (!dicFlag.ContainsKey("result"))
                {
                    errDesc = "rep_QueryACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'result' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("errorDesc"))
                {
                    errDesc = "rep_QueryACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'errorDesc' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("histListNo"))
                {
                    errDesc = "rep_QueryACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'histListNo' not found";
                    return funcResult;
                }
 
                if (userData.histListNo > 0)
                {
                    if (!dicFlag.ContainsKey("histList"))
                    {
                        errDesc = "rep_QueryACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'histList' not found";
                        return funcResult;
                    }
                }
 
                funcResult = true;
            }
            catch (Exception e)
            {
                errDesc = e.Message;
                funcResult = false;
            }
            finally
            {
                xmlReader.Close();
                textReader.Close();
            }
 
            return funcResult;
        }
 
        public static bool Typ_ACLReviewHistInfo_from_XMLObject(string xmlStr, ref Typ_ACLReviewHistInfo userData, out string errDesc)
        {
            bool funcResult = false;
            errDesc = "";
            StringReader xmlReader = null;
            XmlTextReader textReader = null;
            Dictionary<string, bool> dicFlag = null;
 
            try
            {
                xmlReader = new StringReader(xmlStr);
                textReader = new XmlTextReader(xmlReader);
                dicFlag = new Dictionary<string, bool>();
 
                while (!textReader.EOF)
                {
                    textReader.Read();
 
                    dicFlag[textReader.Name] = true;
                    if (textReader.IsEmptyElement)
                    {
                        continue;
                    }
 
                    if (textReader.NodeType == XmlNodeType.Element)
                    {
                        switch (textReader.Name)
                        {
                            case "userId":
                                userData.userId = textReader.ReadString();
                                break;
 
                            case "activity":
                                userData.activity = textReader.ReadString();
                                break;
 
                            case "txnTime":
                                userData.txnTime = textReader.ReadString();
                                break;
 
                            case "txnComment":
                                userData.txnComment = textReader.ReadString();
                                break;
 
                            case "costTime":
                                userData.costTime = textReader.ReadString();
                                break;
 
                            case "choosedPathDesc":
                                userData.choosedPathDesc = textReader.ReadString();
                                break;
 
                            case "reviewNo":
                                userData.reviewNo = textReader.ReadString();
                                break;
 
                            case "stepSeq":
                                userData.stepSeq = textReader.ReadString();
                                break;
 
                            case "stepName":
                                userData.stepName = textReader.ReadString();
                                break;
 
                            case "txnSysId":
                                userData.txnSysId = textReader.ReadString();
                                break;
                        }
                    }
                }
 
                if (!dicFlag.ContainsKey("userId"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'userId' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("activity"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'activity' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("txnTime"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'txnTime' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("txnComment"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'txnComment' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("costTime"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'costTime' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("choosedPathDesc"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'choosedPathDesc' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("reviewNo"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'reviewNo' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("stepSeq"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'stepSeq' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("stepName"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'stepName' not found";
                    return funcResult;
                }
 
                if (!dicFlag.ContainsKey("txnSysId"))
                {
                    errDesc = "Typ_ACLReviewHistInfo_from_XMLObject: Parse from XML failed,item 'txnSysId' not found";
                    return funcResult;
                }
 
                funcResult = true;
            }
            catch (Exception e)
            {
                errDesc = e.Message;
                funcResult = false;
            }
            finally
            {
                xmlReader.Close();
                textReader.Close();
            }
 
            return funcResult;
        }
 
         
        public static void Typ_MsgHdr_to_XMLObject(Typ_MsgHdr userData, out string XmlMsgStr)
        {
            XmlMsgStr = "";
 
            try
            {
                XElement MsgHeader = XElement.Parse(SFWUtility.SFW_MSG_HEADER);
                MsgHeader.Element(SFWUtility.SFW_MSG_SRVADDR).Value = userData.SrvAddr;
                MsgHeader.Element(SFWUtility.SFW_MSG_REQADDR).Value = userData.ReqAddr;
                MsgHeader.Element(SFWUtility.SFW_MSG_MESSAGEOWNER).Value = userData.MsgOwner;
                MsgHeader.Element(SFWUtility.SFW_MSG_SERVERMETHOD).Value = userData.SrvMethod;
                MsgHeader.Element(SFWUtility.SFW_MSG_SERVERID).Value = userData.SrvId;
                MsgHeader.Element(SFWUtility.SFW_MSG_TIMESTAMP).Value = userData.TimeStamp.ToString();
                MsgHeader.Element(SFWUtility.SFW_MSG_TIMEOUT).Value = userData.Timeout.ToString();
                MsgHeader.Element(SFWUtility.SFW_MSG_TRANSID).Value = userData.TransId.ToString();
                MsgHeader.Element(SFWUtility.SFW_MSG_LOCALE).Value = userData.Locale;
                MsgHeader.Element(SFWUtility.SFW_MSG_RETCODE).Value = ((int)userData.RetCode).ToString();
                MsgHeader.Element(SFWUtility.SFW_MSG_RETMSG).Value = userData.RetMsg;
                XmlMsgStr = MsgHeader.ToString(SaveOptions.DisableFormatting);
            }
            catch (Exception e)
            {
                Log.WriteLog(MethodBase.GetCurrentMethod().ReflectedType.ToString() + ": " + MethodBase.GetCurrentMethod().Name + ": " + e.Message);
            }
        }
 
        public static void Typ_MsgHdr_from_XMLObject(string XmlMsgStr, out Typ_MsgHdr userData)
        {
            userData = new Typ_MsgHdr();
  
            try
            {
                XElement MsgHeader = XElement.Parse(XmlMsgStr);
                userData.SrvAddr = MsgHeader.Element(SFWUtility.SFW_MSG_SRVADDR).Value;
                userData.ReqAddr = MsgHeader.Element(SFWUtility.SFW_MSG_REQADDR).Value;
                userData.MsgOwner = MsgHeader.Element(SFWUtility.SFW_MSG_MESSAGEOWNER).Value;
                userData.SrvMethod = MsgHeader.Element(SFWUtility.SFW_MSG_SERVERMETHOD).Value;
                userData.SrvId = MsgHeader.Element(SFWUtility.SFW_MSG_SERVERID).Value;
                userData.TimeStamp = Convert.ToDateTime(MsgHeader.Element(SFWUtility.SFW_MSG_TIMEOUT).Value);
                userData.Timeout = int.Parse(MsgHeader.Element(SFWUtility.SFW_MSG_TIMEOUT).Value);
                userData.TransId = int.Parse(MsgHeader.Element(SFWUtility.SFW_MSG_TRANSID).Value);
                userData.Locale = MsgHeader.Element(SFWUtility.SFW_MSG_LOCALE).Value;
                userData.RetCode = int.Parse(MsgHeader.Element(SFWUtility.SFW_MSG_RETCODE).Value);
            }
            catch (Exception e)
            {
                Log.WriteLog(MethodBase.GetCurrentMethod().ReflectedType.ToString() + ": " + MethodBase.GetCurrentMethod().Name + ": " + e.Message);
            }
        }

  

posted @   彪悍的代码不需要注释  阅读(431)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
39
0
点击右上角即可分享
微信分享提示