Exemplo n.º 1
0
 public XComInstanceInfo(XComInfo info, Type type)
 {
     Info = info;
     Type = type;
 }
Exemplo n.º 2
0
 private static bool Load()
 {
     if (XComCfg == null)
         return false;
     try
     {
         var queryVendor = XComCfg.Doc.Descendants(XComCfg.NameSpace + "XCom").Descendants().Select(n => new { n.Name, n });
         foreach (var item in queryVendor)
         {
             XComInfo xComInfo = new XComInfo();
             xComInfo.Type = item.Name.LocalName;
             if (xComInfo.Type == "XSerialPort")
             {
                 XSerialParameter para = new XSerialParameter();
                 for (XAttribute attr = item.n.FirstAttribute; attr != null; attr = attr.NextAttribute)
                 {
                     switch (attr.Name.LocalName)
                     {
                         case "PortName":
                             para.PortName = attr.Value;
                             break;
                         case "Baudrate":
                             para.Baudrate = int.Parse(attr.Value);
                             break;
                         case "Parity":
                             para.Parity = (Parity)Enum.Parse(typeof(Parity), attr.Value);
                             break;
                         case "DataBits":
                             para.DataBits = int.Parse(attr.Value);
                             break;
                         case "StopBits":
                             para.StopBits = (StopBits)Enum.Parse(typeof(StopBits), attr.Value);
                             break;
                         case "Handshake":
                             para.Handshake = (Handshake)Enum.Parse(typeof(Handshake), attr.Value);
                             break;
                         case "Key":
                             xComInfo.Key = attr.Value;
                             break;
                         default:
                             break;
                     }
                 }
                 xComInfo.Parameter = para;
             }
             else if((xComInfo.Type == "XUdpClient") || (xComInfo.Type == "XTcpClient"))
             {
                 NetParameter para = new NetParameter();
                 for (XAttribute attr = item.n.FirstAttribute; attr != null; attr = attr.NextAttribute)
                 {
                     switch (attr.Name.LocalName)
                     {
                         case "ServerIP":
                             para.ServerIp = attr.Value;
                             break;
                         case "ServerPort":
                             para.ServerPort = int.Parse(attr.Value);
                             break;
                         case "Timeout":
                             para.Timeout = int.Parse(attr.Value);
                             break;
                         case "LocalEthIndex":
                             para.LocalEthIndex = int.Parse(attr.Value);
                             break;
                         case "LocalPort":
                             para.LocalPort = int.Parse(attr.Value);
                             break;
                         case "Key":
                             xComInfo.Key = attr.Value;
                             break;
                         default:
                             break;
                     }
                 }
                 xComInfo.Parameter = para;
             }
             _xComInfo.Add(xComInfo);
         }
     }
     catch(Exception e)
     {
         throw new APXExeception(e.Message);
     }
     return true;
 }