Helper
//检测端口是否使用 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); } }
彪悍的人生不需要解释,彪悍的代码不需要注释。