Exemplo n.º 1
0
 /// <summary>
 /// 更新站点在线信息
 /// </summary>
 /// <param name="db"></param>
 /// <param name="p"></param>
 public static void updateStationOnlineInfo(SWSDataContext db, int stationId)
 {
     try
     {
         country_station station = db.country_station.SingleOrDefault(c => c.id == stationId);
         if (station != null)
         {
             station_online_info online_info = db.station_online_info.SingleOrDefault(c => c.stationid == stationId);
             if (online_info != null)
             {
                 online_info.name            = station.name;
                 online_info.register_time   = DateTime.Now;
                 online_info.last_visit_time = DateTime.Now;
                 online_info.stationid       = stationId;
             }
             else
             {
                 online_info                 = new station_online_info();
                 online_info.name            = station.name;
                 online_info.register_time   = DateTime.Now;
                 online_info.last_visit_time = DateTime.Now;
                 online_info.stationid       = stationId;
                 db.station_online_info.InsertOnSubmit(online_info);
             }
             List <station_online_info> deletes = db.station_online_info.Where(c => c.stationid == online_info.stationid && c.id != online_info.id).ToList();
             if (deletes.Count > 0)
             {
                 db.station_online_info.DeleteAllOnSubmit(deletes);
             }
             db.SubmitChanges();
         }
     }
     catch (Exception ex)
     {
         LogMg.AddError("保存广岱客户端在线信息失败,\r\n" + ex.ToString());
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 保存客户端的连接信息到数据库
        /// </summary>
        private void SaveOnlineInfo()
        {
            while (true)
            {
                try
                {
                    foreach (XML_Org org in SysConfig.orgConfig.Orgs)
                    {
                        try
                        {
                            SWSDataContext db = new SWSDataContext(Util.ServerSocketHelper.GetConnection(org.DBName));


                            //采用有屏版电控柜的客户端遍历
                            List <Clazz.Config.ClientConfig.XML_Station> list_station = SysConfig.clientConfig.AllStation.Where(c => c.OrgId == org.OrgId).ToList();
                            for (int i = 0; i < list_station.Count; i++)
                            {
                                ClientInfo client_info = ServerSocketHelper.ClientSockets.SingleOrDefault(c => c.TransferCode == list_station[i].TransferCode);
                                if (client_info != null)
                                {
                                    station_online_info online_info = db.station_online_info.SingleOrDefault(c => c.transfer_code == list_station[i].TransferCode);
                                    if (online_info != null)
                                    {
                                        online_info.name            = client_info.Name;
                                        online_info.register_time   = client_info.RegisterTime;
                                        online_info.last_visit_time = client_info.LastVisitTime;
                                        online_info.stationid       = client_info.StationId;
                                    }
                                    else
                                    {
                                        online_info = new station_online_info();
                                        online_info.transfer_code   = client_info.TransferCode;
                                        online_info.name            = client_info.Name;
                                        online_info.register_time   = client_info.RegisterTime;
                                        online_info.last_visit_time = client_info.LastVisitTime;
                                        online_info.stationid       = client_info.StationId;
                                        db.station_online_info.InsertOnSubmit(online_info);
                                    }
                                    List <station_online_info> deletes = db.station_online_info.Where(c => c.stationid == online_info.stationid && c.id != online_info.id).ToList();
                                    if (deletes.Count > 0)
                                    {
                                        db.station_online_info.DeleteAllOnSubmit(deletes);
                                    }
                                }
                            }

                            //采用DTU电控柜的客户端遍历
                            List <XML_Station> list_DTU_Station = SysConfig.DTU_StationConfig.Stations.Where(c => c.OrgId == org.OrgId).ToList();
                            for (int i = 0; i < list_DTU_Station.Count; i++)
                            {
                                DTUClientInfo DTU_clientinfo = DTU_ClientManager.Clients.SingleOrDefault(c => c.TelOrGprsId == list_DTU_Station[i].Tel);
                                if (DTU_clientinfo != null)
                                {
                                    station_online_info online_info = db.station_online_info.SingleOrDefault(c => c.dtu_tel == DTU_clientinfo.TelOrGprsId);
                                    if (online_info != null)
                                    {
                                        online_info.stationid       = DTU_clientinfo.StationId;
                                        online_info.name            = DTU_clientinfo.Name;
                                        online_info.register_time   = DTU_clientinfo.RegisterTime;
                                        online_info.last_visit_time = DTU_clientinfo.LastVisitTime;
                                    }
                                    else
                                    {
                                        online_info                 = new station_online_info();
                                        online_info.stationid       = DTU_clientinfo.StationId;
                                        online_info.name            = DTU_clientinfo.Name;
                                        online_info.register_time   = DTU_clientinfo.RegisterTime;
                                        online_info.last_visit_time = DTU_clientinfo.LastVisitTime;
                                        online_info.dtu_tel         = DTU_clientinfo.TelOrGprsId;
                                        db.station_online_info.InsertOnSubmit(online_info);
                                    }
                                    List <station_online_info> deletes = db.station_online_info.Where(c => c.stationid == online_info.stationid && c.id != online_info.id).ToList();
                                    if (deletes.Count > 0)
                                    {
                                        db.station_online_info.DeleteAllOnSubmit(deletes);
                                    }
                                }
                            }
                            db.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                            LogMg.AddError("保存客户端在线数据时失败,\r\n" + ex.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogMg.AddError(ex);
                }

                Thread.Sleep(60000);
            }
        }