Example #1
0
        /// <summary>
        /// 保存配置到XML
        /// </summary>
        /// <returns></returns>
        private bool AddStationToXML(Clazz.Config.ClientConfig.XML_Station station)
        {
            try
            {
                XmlDocument XDoc = new XmlDocument();
                XDoc.Load(Path); //加载XML文档

                XmlElement ListTestEl = (XmlElement)XDoc.SelectSingleNode(@"/ClientConfig/Stations");

                XmlElement xe = XDoc.CreateElement("Station");
                xe.SetAttribute("UniqueId", station.UniqueId.ToString());
                xe.SetAttribute("TransferCode", station.TransferCode);
                xe.SetAttribute("StationId", station.StationId.ToString());
                xe.SetAttribute("OrgId", station.OrgId);
                xe.SetAttribute("站点名称", station.StationName);
                ListTestEl.AppendChild(xe);

                XDoc.Save(Path);
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
                return(false);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// 返回所有站点
        /// </summary>
        /// <returns></returns>
        public List <Clazz.Config.ClientConfig.XML_Station> GetAllStation()
        {
            List <Clazz.Config.ClientConfig.XML_Station> list = new List <Clazz.Config.ClientConfig.XML_Station>();

            try
            {
                XmlNodeList ListNode = Utility.XmlHelper.GetXmlNodeListByXpath(Path, "/ClientConfig/Stations/Station");
                foreach (XmlNode item in ListNode)
                {
                    XmlElement xe = (XmlElement)item;

                    Clazz.Config.ClientConfig.XML_Station _station = new Clazz.Config.ClientConfig.XML_Station();
                    _station.UniqueId     = int.Parse(xe.GetAttribute("UniqueId"));
                    _station.TransferCode = xe.GetAttribute("TransferCode");
                    _station.StationId    = int.Parse(xe.GetAttribute("StationId"));
                    _station.OrgId        = xe.GetAttribute("OrgId");
                    _station.StationName  = xe.GetAttribute("站点名称");
                    list.Add(_station);
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
            return(list);
        }
Example #3
0
        /// <summary>
        /// 根据传输编码获得stationid
        /// </summary>
        /// <param name="transferCode"></param>
        /// <returns></returns>
        public int GetStationIdByTransferCode(string transferCode)
        {
            int stationId = 0;

            try
            {
                Clazz.Config.ClientConfig.XML_Station station = AllStation.SingleOrDefault(c => c.TransferCode == transferCode);
                if (station != null)
                {
                    stationId = station.StationId;
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
            return(stationId);
        }
Example #4
0
        /// <summary>
        /// 根据传输编码获得orgid
        /// </summary>
        /// <param name="transferCode"></param>
        /// <returns></returns>
        public string GetOrgIdByTransferCode(string transferCode)
        {
            string orgid = "";

            try
            {
                Clazz.Config.ClientConfig.XML_Station station = AllStation.SingleOrDefault(c => c.TransferCode == transferCode);
                if (station != null)
                {
                    orgid = station.OrgId;
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
            return(orgid);
        }
Example #5
0
 /// <summary>
 /// 删除站点
 /// </summary>
 /// <param name="stationId"></param>
 /// <param name="stationName"></param>
 /// <param name="orgId"></param>
 /// <param name="transferCode"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public bool DelStation(int uniqueId, ref string msg)
 {
     Clazz.Config.ClientConfig.XML_Station station = AllStation.SingleOrDefault(c => c.UniqueId == uniqueId);
     if (station != null)
     {
         lock (AllStation)
         {
             AllStation.Remove(station);
             DelStationFromXML(uniqueId);
             return(true);
         }
     }
     else
     {
         msg = "不存在这个站点";
         return(false);
     }
 }
Example #6
0
        /// <summary>
        /// 添加站点
        /// </summary>
        /// <param name="station"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool AddStation(Clazz.Config.ClientConfig.XML_Station station, ref string msg)
        {
            bool flag = true;

            try
            {
                if (AllStation.Exists(c => c.StationId == station.StationId && c.OrgId == station.OrgId))
                {
                    msg = "已存在站点Id:" + station.StationId;
                    return(false);
                }
                if (AllStation.Exists(c => c.TransferCode == station.TransferCode))
                {
                    msg = "已存在传输编码:" + station.TransferCode;
                    return(false);
                }
                if (AllStation.Exists(c => c.StationName == station.StationName))
                {
                    msg = "已存在站点名称:" + station.StationName;
                    return(false);
                }

                lock (AllStation)
                {
                    int uniqueId = AllStation.Max(c => c.UniqueId);
                    station.UniqueId = uniqueId + 1;
                    AllStation.Add(station);
                    flag = AddStationToXML(station);
                }
            }
            catch (Exception ex)
            {
                flag = false;
                LogMg.AddError(ex);
            }
            return(flag);
        }
        /// <summary>
        /// 添加客户端
        /// </summary>
        private static void AddClient(string orgId, int stationId)
        {
            try
            {
                //如果站点Id为0   那就不用执行下去了
                if (stationId != 0)
                {
                    Clazz.Config.ClientConfig.XML_Station XML_station = SysConfig.clientConfig.AllStation.SingleOrDefault(c => c.StationId == stationId && c.OrgId == orgId);
                    if (XML_station != null)
                    {
                        lock (ClientSockets)
                        {
                            Clazz.ClientInfo client = ClientSockets.SingleOrDefault(c => c.TransferCode == XML_station.TransferCode);
                            if (client == null)
                            {
                                Clazz.Config.XML_Org _org = SysConfig.orgConfig.GetOrgByOrgId(orgId);
                                if (_org == null)
                                {
                                    //将信息写入到日志文件中    orgid为***的污水厂不存在
                                    LogMg.AddError(String.Format("OrgId:{0}  不存在", orgId));
                                    //isSuccess = false;
                                }
                                else
                                {
                                    SWSDataContext  db      = new SWSDataContext(GetConnection(_org.DBName));
                                    string          name    = "未知的客户端";
                                    country_station station = db.country_station.SingleOrDefault(c => c.id == stationId);
                                    if (station != null)
                                    {
                                        name = station.name;
                                    }

                                    client = new Clazz.ClientInfo();
                                    client.TransferCode  = XML_station.TransferCode;
                                    client.StationId     = stationId;
                                    client.RegisterTime  = DateTime.Now;
                                    client.LastVisitTime = DateTime.Now;
                                    client.Name          = name;
                                    ClientSockets.Add(client);
                                }
                            }
                            else
                            {
                                client.RegisterTime  = DateTime.Now;
                                client.LastVisitTime = DateTime.Now;
                            }
                        }
                    }

                    ///执行委托
                    if (ClientChangeHander != null)
                    {
                        ClientChangeHander();
                    }
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }
        }
Example #8
0
        public static void DownLoad(Socket socket, string json)
        {
            S_To_C_Data <ClientConfig> sendObj = new S_To_C_Data <ClientConfig>();
            ClientConfig _clientConfig         = new ClientConfig();

            try
            {
                C_To_S_Data <ClientConfig>            obj      = Utility.JsonHelper.JsonDeserialize <C_To_S_Data <ClientConfig> >(json);
                Clazz.Config.ClientConfig.XML_Station _station = SysConfig.clientConfig.AllStation.SingleOrDefault(c => c.TransferCode == obj.TransferCode);

                if (_station == null)
                {
                    LogMg.AddDebug("TransferCode:" + obj.TransferCode + " 不存在");
                }
                else
                {
                    _clientConfig.OrgId           = SysConfig.clientConfig.GetOrgIdByTransferCode(obj.TransferCode);
                    _clientConfig.StationId       = SysConfig.clientConfig.GetStationIdByTransferCode(obj.TransferCode);
                    _clientConfig.ListCountryTest = (from c in SysConfig.clientConfig.AllCountryTest
                                                     where c.StationUniqueId == _station.UniqueId
                                                     select new CSDataStandard.Config.CountryTest
                    {
                        NodeId = c.NodeId,
                        TestId = c.TestId,
                        Multiple = c.Multiple
                    }).ToList();
                    _clientConfig.ListDevice = new List <DeviceControl>();
                    //(from c in SysConfig.clientConfig.AllDevice
                    //                        where c.StationUniqueId == _station.UniqueId
                    //                        select new CSDataStandard.Config.DeviceControl
                    //                        {
                    //                            Number = c.Number,
                    //                            DeviceId = c.DeviceId
                    //                        }).ToList();
                    _clientConfig.ListPMQCTest = (from c in SysConfig.clientConfig.AllPMQCTest
                                                  where c.StationUniqueId == _station.UniqueId
                                                  select new CSDataStandard.Config.PMQCTest
                    {
                        X = c.X,
                        Y = c.Y,
                        TestId = c.TestId,
                        Id = c.Id,
                        Name = c.Name
                    }).ToList();
                    _clientConfig.ListMobileDetection = (from c in SysConfig.clientConfig.AllMobileDetection
                                                         where c.StationUniqueId == _station.UniqueId
                                                         select new CSDataStandard.Config.MobileDetection
                    {
                        TestId = c.TestId,
                        TestTarger = c.TestTarger
                    }).ToList();
                    _clientConfig.ListMcgsTest = (from c in SysConfig.clientConfig.AllMCGSTest
                                                  where c.StationUniqueId == _station.UniqueId
                                                  select new CSDataStandard.Config.MCGSTest
                    {
                        TestId = c.TestId,
                        ColumnName = c.ColumnName,
                        TestName = c.TestName
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                LogMg.AddError(ex);
            }

            sendObj.Data = new List <ClientConfig>();
            sendObj.Data.Add(_clientConfig);                                 //添加数据
            sendObj.Flag    = CSDataStandard.Enum.HandleFlag.DownLoadConfig; //类型为  下载配置文件
            sendObj.Success = true;

            string sendJSON = Utility.JsonHelper.JsonSerializer(sendObj);

            socket.Send(Encoding.Unicode.GetBytes(sendJSON));
        }