Exemplo n.º 1
0
 /// <summary>
 /// 复位委托函数,调用外部接口执行。
 /// </summary>
 /// <param name="netMacObject">网络模块</param>
 /// <param name="resetTwo">表示是否需要连续复位2次</param>
 /// <param name="setType">表示此次复位是什么条件发起的=1 表示强制重启,=2表示无连接号超时,重启;=3表示有连接但是超时无数据</param>
 private void ResetNetWork(NetworkDeviceInfo netMacObject, byte setType, bool resetTwo = false)
 {
     if (OnExcuteDriverCommand != null)//修正一下,如果是第一次进来时,连接两次
     {
         bool result = false;
         DriverCommandEventArgs args         = new DriverCommandEventArgs();
         DeviceResetCommand     resetcommand = new DeviceResetCommand();
         resetcommand.Mac     = netMacObject.MAC;
         resetcommand.Timeout = 2000;
         args.CommandType     = 1;
         args.JsonData        = Basic.Framework.Common.JSONHelper.ToJSONString(resetcommand);
         result = OnExcuteDriverCommand(this, args);
         if (resetTwo && !result)//如果失败需要连续复位,在此执行
         {
             Thread.Sleep(200);
             result = OnExcuteDriverCommand(this, args);
         }
         if (result)
         {
             LogHelper.Info("对" + netMacObject.MAC + "-" + netMacObject.IP + "复位成功-" + setType.ToString());
         }
         else
         {
             LogHelper.Info("对" + netMacObject.MAC + "-" + netMacObject.IP + "复位失败-" + setType.ToString());
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 处理驱动命令事件(特殊处理)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        private bool Driver_OnExcuteDriverCommand(object sender, DriverCommandEventArgs args)
        {
            if (args.CommandType == 1)
            {
                DeviceResetCommand resetCommand = Basic.Framework.Common.JSONHelper.ParseJSONString <DeviceResetCommand>(args.JsonData);
                return(Sys.DataCollection.Communications.Provider.C8962UdpCommunication.ResetDevice(resetCommand.Mac, resetCommand.Timeout));
            }
            else if (args.CommandType == 2)
            {//20181013
                List <ClientConntion> connCommand = Basic.Framework.Common.JSONHelper.ParseJSONString <List <ClientConntion> >(args.JsonData);
                GatewayManager.CommunicationManager.ConnetionServer("CS001", connCommand);
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 网络模块复位处理线程
        /// </summary>
        private void NetWorkResetThread()
        {
            CommSendData          commdata     = new CommSendData();
            int                   iclientCount = 0;
            List <ClientConntion> lstConnetion;

            if (Directory.Exists("C:\\NetSource\\") == false)
            {
                Directory.CreateDirectory("C:\\NetSource\\");
            }
            string   strCur    = "";
            DateTime t_dayTime = new DateTime(1999, 1, 1);

            string[] strP = { "debug", "error", "info", "system", "warn" };
            int      i    = 0;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            for (; ;)
            {
                try
                {
                    sw.Restart();

                    #region 更新四舍五入标记、源码输出
                    try
                    {
                        System.Configuration.ConfigurationManager.RefreshSection("appSettings");
                        strCur = Basic.Framework.Configuration.ConfigurationManager.FileConfiguration.GetString("B4c5r", "1");
                        if (strCur.Trim() == "2")
                        {
                            Cache.B4c5r = true;
                        }
                        else
                        {
                            Cache.B4c5r = false;
                        }
                        strCur            = Basic.Framework.Configuration.ConfigurationManager.FileConfiguration.GetString("FeedTimeOut", "5");
                        Cache.FeedTimeOut = Convert.ToInt32(strCur);

                        strCur          = Basic.Framework.Configuration.ConfigurationManager.FileConfiguration.GetString("ShowYmOut", "0");
                        Cache.ShowYmOut = Convert.ToInt32(strCur);
                        if (Cache.ShowYmOut == 1)//有源码输出才进行相关的处理
                        {
                            while (Cache.LstCommData.Count > 0)
                            {
                                lock (Cache.LockCommData)
                                {
                                    commdata = Basic.Framework.Common.ObjectConverter.DeepCopy <CommSendData>(Cache.LstCommData[0]);
                                    Cache.LstCommData.RemoveAt(0);
                                }
                                ShowNetDataToComputer(commdata.data, commdata.Mac, commdata.Flag);
                            }
                        }
                        else//不带源码输出直接清空
                        {
                            lock (Cache.LockCommData)
                            {
                                Cache.LstCommData.Clear();
                            }
                        }

                        strCur = Basic.Framework.Configuration.ConfigurationManager.FileConfiguration.GetString("FeedComplexFailure", "1");
                        if (strCur == "1")
                        {
                            Cache.FeedComplexFailure = true;
                        }
                        else
                        {
                            Cache.FeedComplexFailure = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error("更新四舍五入、源码输出标记错误:" + ex.Message);
                    }
                    #endregion

                    #region 如处于客户端模式,定期进行连接和关闭判断

                    iclientCount++;
                    strCur = Basic.Framework.Configuration.ConfigurationManager.FileConfiguration.GetString("ServerOrClient", "1");
                    if ((iclientCount >= 3) && (strCur == "1"))
                    {
                        iclientCount = 0;
                        if (OnExcuteDriverCommand != null)//修正一下,如果是第一次进来时,连接两次
                        {
                            DriverCommandEventArgs args         = new DriverCommandEventArgs();
                            DeviceResetCommand     resetcommand = new DeviceResetCommand();
                            args.CommandType = 2;
                            lstConnetion     = GetFzhIP();
                            args.JsonData    = Basic.Framework.Common.JSONHelper.ToJSONString(lstConnetion);
                            OnExcuteDriverCommand(this, args);
                        }
                    }

                    #endregion

                    #region   自动删除数据
                    //自动删除 20个月前的源码数据
                    if (t_dayTime.Day != DateTime.Now.Day)
                    {
                        t_dayTime = DateTime.Now;
                        try
                        {
                            DateTime dt = new DateTime();
                            foreach (string d in Directory.GetFileSystemEntries("C:\\NetSource\\"))
                            {
                                if (File.Exists(d))
                                {
                                    FileInfo fi = new FileInfo(d);
                                    if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                                    {
                                        fi.Attributes = FileAttributes.Normal;
                                    }

                                    dt = new DateTime(Convert.ToInt32(fi.Name.Substring(0, 4)), Convert.ToInt32(fi.Name.Substring(4, 2)), Convert.ToInt32(fi.Name.Substring(6, 2)));
                                    if ((DateTime.Now - dt).TotalDays >= 20)
                                    {
                                        File.Delete(d);//直接删除其中的文件
                                    }
                                }
                            }
                            for (i = 0; i < 5; i++)
                            {
                                strCur = "C:\\log\\Sys.DataCollection.ConsoleHost\\" + strP[i];
                                //判断文件夹是否还存在
                                if (Directory.Exists(strCur))
                                {
                                    foreach (string f in Directory.GetFileSystemEntries(strCur))
                                    {
                                        strCur = f.ToString();
                                        strCur = strCur.Substring(strCur.LastIndexOf('\\') + 1);
                                        dt     = new DateTime(Convert.ToInt32(strCur.Substring(0, 4)), Convert.ToInt32(strCur.Substring(4, 2)), Convert.ToInt32(strCur.Substring(6, 2)));
                                        if ((DateTime.Now - dt).TotalDays >= 20)
                                        {
                                            foreach (string f1 in Directory.GetFileSystemEntries(f))
                                            {
                                                if (File.Exists(f1))
                                                {//如果有子文件删除文件
                                                    File.Delete(f1);
                                                }
                                            }
                                            Directory.Delete(f);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error("NetWorkReset【删除源码文件失败】" + ex.ToString());
                        }
                    }
                    #endregion
                    sw.Stop();
                    if (sw.ElapsedMilliseconds > 3000)
                    {//操作了3秒就输出日志出来
                        LogHelper.Info("网关超时判断:" + sw.ElapsedMilliseconds);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error("NetWorkReset【NetWorkResetThread】:" + ex.ToString());
                }
                Thread.Sleep(1000);
            }
        }