Пример #1
0
        /// <summary>
        /// 跨天处理
        /// </summary>
        private void CrossDay(DateTime nowTime, DateTime tomorrowTime)
        {
            try
            {
                //DateTime nowTime = time;
                //nowTime = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59);

                //DateTime tomorrowTime = nowTime.AddDays(1);
                //tomorrowTime = new DateTime(tomorrowTime.Year, tomorrowTime.Month, tomorrowTime.Day, 0, 0, 0);

                List <Jc_DefInfo> pointDefineItems;
                List <Jc_DevInfo> pointDevItems;
                Jc_DevInfo        pointDevItem;
                IDriver           driverObj = null;

                pointDefineItems = CacheDataHelper.GetAllSystemPointDefineItems();
                pointDefineItems = pointDefineItems.Where(a => a.DevPropertyID == (int)DeviceProperty.Substation).ToList();
                pointDevItems    = CacheDataHelper.GetAllDevItems();

                foreach (Jc_DefInfo station in pointDefineItems)
                {
                    pointDevItem = pointDevItems.FirstOrDefault(a => a.Devid == station.Devid);
                    if (pointDevItem != null)
                    {
                        if (GlobleStaticVariable.driverHandle.DriverItems.ContainsKey(pointDevItem.Sysid))
                        {
                            driverObj = GlobleStaticVariable.driverHandle.DriverItems[pointDevItem.Sysid].DLLObj;
                            DriverTransferInterface.Drv_CrossDayPro(driverObj, station.Fzh, nowTime, tomorrowTime);
                        }
                    }
                }
                //人员定位报警表跨天处理  20171206
                KJ237CacheHelper.Drv_CrossDayPro(nowTime, tomorrowTime);
            }
            catch (Exception ex)
            {
                LogHelper.Error("CrossDay Error:" + ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 跨天和五分钟处理方法
        /// </summary>
        private void CrossDayAndFiveMinite()
        {
            DateTime          fiveMiniteProcMinite = DateTime.Now;
            DateTime          nowTime = DateTime.Now;
            List <Jc_DefInfo> pointDefineItems;
            List <Jc_DevInfo> pointDevItems;
            Jc_DevInfo        pointDevItem;
            IDriver           driverObj = null;
            int totalcount = 0;

            bool doFiveMinData = false; //是否要处理五分钟数据  2017.9.15 by

            for (; ;)
            {
                try
                {
                    doFiveMinData = false;

                    if (isStop)
                    {
                        LogHelper.Info("停止数据处理模块【跨天和五分钟处理方法处理完成】!");
                        break;
                    }

                    if (DateTime.Now.Day != nowTime.Day)
                    {
                        //2017.12.18 by 异常处理跨天(手动修改电脑时间)
                        CrossDay(new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59),
                                 new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0));
                    }

                    nowTime = DateTime.Now;

                    //if (nowTime.Hour == 0 && nowTime.Minute == 0)
                    //{
                    //    doFiveMinData = false;  //刚跨天00:00:00 满足写记录条件,但不应该写记录
                    //}
                    //else  if (nowTime.Hour == 23 && nowTime.Minute == 59 && nowTime.Second > 40 && nowTime.Minute != fiveMiniteProcMinite.Minute) //2017.9.15 by
                    //{
                    //    doFiveMinData = true;
                    //}
                    //else
                    if ((nowTime.Minute % 5 == 0) && (nowTime.Minute != fiveMiniteProcMinite.Minute))
                    {
                        doFiveMinData = true;
                    }

                    //if ((nowTime.Minute % 5 == 0) && (nowTime.Minute != fiveMiniteProcMinite.Minute))
                    if (doFiveMinData)
                    {
                        fiveMiniteProcMinite = nowTime;
                        #region ----五分钟数据处理----
                        pointDefineItems = CacheDataHelper.GetKJPointDefineItems();
                        pointDefineItems = pointDefineItems.Where(a => a.DevPropertyID == (int)DeviceProperty.Substation).ToList();
                        pointDevItems    = CacheDataHelper.GetAllDevItems();

                        foreach (Jc_DefInfo station in pointDefineItems)
                        {
                            pointDevItem = pointDevItems.FirstOrDefault(a => a.Devid == station.Devid);
                            if (pointDevItem != null)
                            {
                                if (GlobleStaticVariable.driverHandle.DriverItems.ContainsKey(pointDevItem.Sysid))
                                {
                                    driverObj = GlobleStaticVariable.driverHandle.DriverItems[pointDevItem.Sysid].DLLObj;
                                    DriverTransferInterface.Drv_FiveMinPro(driverObj, station.Fzh, nowTime);
                                }
                            }
                        }

                        #endregion
                    }
                    if (nowTime.Hour == 23 && nowTime.Minute == 59 && nowTime.Second > 50)
                    {
                        isCrossDay = true;
                        #region ----跨天处理----
                        //判断数据处理线程数据是否处理完成,处理完成才继续进行跨天处理  20170703
                        while (DataProcHandle.Instance.GetArriveDataCount() > 0)
                        {
                            Thread.Sleep(200);
                        }
                        //处理时已跨天  输出日志  20170703
                        if (DateTime.Now.Day != nowTime.Day)
                        {
                            Basic.Framework.Logging.LogHelper.Error("处理跨天数据时,时间已到第二天!");
                        }

                        //DateTime nowTime = time;
                        //nowTime = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59);

                        //DateTime tomorrowTime = nowTime.AddDays(1);
                        //tomorrowTime = new DateTime(tomorrowTime.Year, tomorrowTime.Month, tomorrowTime.Day, 0, 0, 0);
                        CrossDay(new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59),
                                 new DateTime(nowTime.AddDays(1).Year, nowTime.AddDays(1).Month, nowTime.AddDays(1).Day, 0, 0, 0)); //2017.12.18 by  增加手动修改电脑日期处理时增加

                        while (true)
                        {
                            Thread.Sleep(200);
                            if (DateTime.Now.Hour != 23)
                            {
                                CreatDayTable(DateTime.Now);
                                break;
                            }
                        }

                        #endregion
                        isCrossDay = false;
                        nowTime    = DateTime.Now; //正常跨天处理完成,将时间赋值到第二天
                    }
                    totalcount++;
                    if (totalcount >= 20)//每4秒记算一次馈电信息
                    {
                        totalcount = 0;
                        CheckAlarmFeeding();
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error("CrossDayAndFiveMinite Error:" + ex.Message);
                }
                Thread.Sleep(200);
            }
        }
Пример #3
0
        /// <summary>
        /// 本地驱动加载
        /// </summary>
        /// <returns></returns>
        public bool LoadLocalDrivers()
        {
            //日志
            string strLog = "";
            //驱动类名
            string fileName = "";
            //驱动程序集名称
            string assemblyName = "";
            //驱动文件所在路径
            //string path = Application.StartupPath + "\\Driver\\";
            string path = "";

            path = AppDomain.CurrentDomain.BaseDirectory + @"Driver\";
            //if (System.Environment.CurrentDirectory + "\\" == AppDomain.CurrentDomain.BaseDirectory)//Windows应用程序则相等
            //{
            //    path = AppDomain.CurrentDomain.BaseDirectory + @"\Driver\";
            //}
            //else
            //{
            //    path = AppDomain.CurrentDomain.BaseDirectory + @"Bin\Driver\";
            //}
            //加载是否成功
            bool flag = true;
            //驱动对象结构体
            DriverItem drvObj;
            //驱动文件夹
            DirectoryInfo dir = new DirectoryInfo(path);
            //驱动程序集
            Assembly assembly;
            Type     dllTypes;

            if (!System.IO.Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            #region 加载所有驱动
            try
            {
                if (dir.GetFiles("Sys.*.Driver.dll").Count() < 1)
                {
                    strLog = path + "没有驱动文件,程序将无法正常运行.............................................................";
                    LogHelper.Error(strLog);
                    return(false);
                }
                foreach (System.IO.FileInfo file in dir.GetFiles("Sys.*.Driver.dll"))
                {
                    assembly = null;
                    drvObj   = new DriverItem();
                    try
                    {
                        //加载程序集
                        assemblyName = file.Name;
                        if (assemblyName == "Sys.*.Driver.dll")
                        {
                            continue;
                        }
                        assembly = Assembly.LoadFrom(path + assemblyName);
                    }
                    catch
                    {
                        assembly = null;
                    }
                    if (assembly != null)
                    {
                        //驱动命名空间必须为DriverNameSpace
                        //fileName = "Basic.*.Drivers." + file.Name.Substring(15).Replace(file.Extension, "");
                        fileName = assemblyName.Replace(file.Extension, "") + "." + assemblyName.Split('.')[1];
                        //获取程序集中的指定类型-即驱动对象类型
                        dllTypes = assembly.GetType(fileName);

                        if (dllTypes != null)
                        {
                            //根据程序集中的类型实例化对象
                            drvObj.DLLObj = Activator.CreateInstance(dllTypes) as IDriver;

                            //当为第一次加载或是该驱动对象在内存中不存在时,就添加到驱动内存中
                            if (DriverItems.Count == 0 ||
                                !DriverItems.ContainsKey(DriverTransferInterface.Get_Drv_ID(drvObj.DLLObj)))
                            {
                                #region 驱动存在
                                drvObj.NDriverID            = DriverTransferInterface.Get_Drv_ID(drvObj.DLLObj);
                                drvObj.StrDriverName        = DriverTransferInterface.Get_Drv_StrDriverName(drvObj.DLLObj);
                                drvObj.StrDriverSource      = DriverTransferInterface.Get_Drv_StrDriverSource(drvObj.DLLObj);
                                drvObj.StrDriverVersion     = DriverTransferInterface.Get_Drv_StrDriverVersion(drvObj.DLLObj);
                                drvObj.DttDriverVersionTime = DriverTransferInterface.Get_Drv_DttDriverVersionTime(drvObj.DLLObj);
                                DriverItems.Add(drvObj.NDriverID, drvObj);
                                strLog = "加载驱动【" + drvObj.StrDriverSource + " " + drvObj.DttDriverVersionTime.ToString("yyyyMMdd") + "】成功 √";
                                LogHelper.Info(strLog);
                                //GlobalCnfgInfo.AddLogs(strLog);
                                #endregion
                            }
                            else if (DriverItems.ContainsKey(DriverTransferInterface.Get_Drv_ID(drvObj.DLLObj)))
                            {
                                #region 驱动存在则需比较驱动时间
                                DriverItem drvObjTemp = DriverItems[DriverTransferInterface.Get_Drv_ID(drvObj.DLLObj)];
                                if (drvObjTemp.DttDriverVersionTime < drvObj.DttDriverVersionTime)
                                {
                                    drvObj.NDriverID              = DriverTransferInterface.Get_Drv_ID(drvObj.DLLObj);
                                    drvObj.StrDriverName          = DriverTransferInterface.Get_Drv_StrDriverName(drvObj.DLLObj);
                                    drvObj.StrDriverSource        = DriverTransferInterface.Get_Drv_StrDriverSource(drvObj.DLLObj);
                                    drvObj.StrDriverVersion       = DriverTransferInterface.Get_Drv_StrDriverVersion(drvObj.DLLObj);
                                    drvObj.DttDriverVersionTime   = DriverTransferInterface.Get_Drv_DttDriverVersionTime(drvObj.DLLObj);
                                    DriverItems[drvObj.NDriverID] = drvObj;
                                    strLog = "加载驱动【" + drvObj.StrDriverSource + " " + drvObj.DttDriverVersionTime.ToString("yyyyMMdd") + "】更新成功 √";
                                    LogHelper.Info(strLog);
                                    //GlobalCnfgInfo.AddLogs(strLog);
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            strLog = "加载驱动【" + fileName + "】失败 ×";
                            LogHelper.Info(strLog);
                            //GlobalCnfgInfo.AddLogs(strLog);
                            flag = false;
                        }
                    }
                }

                OnLoadDriverSuccessEvent();
            }
            catch (Exception ex)
            {
                strLog = ex.Message + "加载程序集出错(" + assemblyName + ")";
                LogHelper.Error(strLog);
                flag = false;
            }
            #endregion
            return(flag);
        }