Exemple #1
0
        static void Main(string[] args)
        {
            //先设置当前工作目录为进程目录
            Console.WriteLine("原工作目录:"+Directory.GetCurrentDirectory());
            Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
            Console.WriteLine("现在工作目录:" + Directory.GetCurrentDirectory());

            //从后台维护数据表中设置错误码静态数据
            //ErrorcodeService.GetInstance().setErrorStaticData();

            string validdog = ConfigurationSettings.AppSettings["validdog"];//是否验证狗
            //启动解析线程
            TcpDataProcesser dataProcess = new TcpDataProcesser();
            Thread m_thread = new Thread(new ThreadStart(dataProcess.Processing));
            m_thread.Start();

            //启动持久化线程
            PersistentProcesser persistProcess = new PersistentProcesser();
            Thread m_thread3 = new Thread(new ThreadStart(persistProcess.Processing));
            m_thread3.Start();

            //设置最后成功处理时间到memcached,以便检测监控程序能判断是否正常运行
            MemcachedClientSatat.getInstance().Set("monitor_analyze_run_lasttime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            LogUtil.info("服务启动成功!");

            //循环检测狗
            while (1==1)
            {
                //循环狗检测程序,这个就要求必须将狗一直插入才能正常运行软件
                if (validdog == null || validdog.Equals("true"))
                {
                    LogUtil.info("开始检测加密狗");
                    string result = monitordog();
                    if (!string.IsNullOrEmpty(result))
                    {
                        LogUtil.info(result);

                        //kill thread
                        if (dataProcess!=null)
                            dataProcess.runmark = false;

                        if (m_thread!=null)
                            if (m_thread.IsAlive)
                                m_thread.Abort();

                        if (persistProcess != null)
                            persistProcess.runmark = false;

                        if (m_thread3 != null)
                            if (m_thread3.IsAlive)
                                m_thread3.Abort();

                        LogUtil.info("软件已经停止服务!");
                    }
                }
                Thread.Sleep(60*1000);//线程休息1分钟
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //SystemCode.HexNumberToDenary("FC27", false, 16, 's');
            //启动解析线程
            TcpDataProcesser dataProcess = new TcpDataProcesser();
            Thread           m_thread    = new Thread(new ThreadStart(dataProcess.Processing));

            m_thread.Start();

            //启动清除过期数据线程
            //FlushProcesser flushProcess = new FlushProcesser();
            //Thread m_thread2 = new Thread(new ThreadStart(flushProcess.Processing));
            //m_thread2.Start();

            //启动持久化线程
            PersistentProcesser persistProcess = new PersistentProcesser();
            Thread m_thread3 = new Thread(new ThreadStart(persistProcess.Processing));

            m_thread3.Start();



            //DataProcess.DataProcessingEmail();

            LogUtil.info("数据解析服务启动成功!");
            string strLine;

            do
            {
                strLine = Console.ReadLine();
            } while (strLine != null && strLine != "exit");

            LogUtil.info("正在退出数据解析服务...");
            LogUtil.info("持久化剩余缓存数据...");
            //持久化尚未持久化的缓存数据后退出
            persistProcess.peristentData();
            LogUtil.info("剩余数据持久化完成...");

            //kill thread
            if (m_thread.IsAlive)
            {
                m_thread.Abort();
            }
            if (m_thread3.IsAlive)
            {
                m_thread3.Abort();
            }
        }
Exemple #3
0
        int memcahcednum = 0;//缓存次数,完成两次缓存,进行一次持久化数据

        /// <summary>
        /// 每一批次的最后处理
        /// </summary>
        private void lastHandle()
        {
            if (DateTime.Now < lastCacheTime.AddMinutes(cache_interval))
            {
                return;
            }
            Console.WriteLine("开始缓存数据到Memcached");
            DateTime curdt   = DateTime.Now;
            DateTime totaldt = DateTime.Now;

            //将内存中得数据放入缓存
            CacheHandler.CacheData();
            //最后批处理采集器最大值
            try
            {
                DeviceDataCountService.GetInstance().CacheCollectorCount(collectorDataCounts);
                LogUtil.info("CacheCollectorCount 完成:" + collectorDataCounts.Count);
                //电站统计,必须保证所有采集器都在,即每次都统计完整的电站单元,所以不能清空。

                collectorDataCounts.Clear();
            }
            catch (Exception ddccache)
            {
                LogUtil.error("CacheCollectorCount异常:" + ddccache.Message);
            }
            //最后处理发电量统计
            try
            {
                CacheHandler.CacheCountData(deviceEnergyMap, collectorEnergyMap);
            }
            catch (Exception ddccache)
            {
                LogUtil.error("CacheCollectorCount异常:" + ddccache.Message);
            }
            LogUtil.writeline("缓存到memcache处理用时:" + (DateTime.Now.Subtract(curdt).TotalSeconds) + "秒,统计:待处理数量" + AnalyzeCount.curWaittotal + ",总共处理:" + AnalyzeCount.curtotal + ",成功:" + AnalyzeCount.curSuccessNum + ",失败:" + AnalyzeCount.curFailNum + ",最近数据发送时间:" + AnalyzeCount.lasttime.ToString("yyyy-MM-dd HH:mm:ss"));
            lastCacheTime = DateTime.Now;

            memcahcednum++;
            if (memcahcednum == 3)
            {
                //进行持久化
                PersistentProcesser.peristentData();
                memcahcednum = 0;
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            //SystemCode.HexNumberToDenary("FC27", false, 16, 's');
            //启动解析线程
            TcpDataProcesser dataProcess = new TcpDataProcesser();
            Thread m_thread = new Thread(new ThreadStart(dataProcess.Processing));
            m_thread.Start();

            //启动清除过期数据线程
            //FlushProcesser flushProcess = new FlushProcesser();
            //Thread m_thread2 = new Thread(new ThreadStart(flushProcess.Processing));
            //m_thread2.Start();

            //启动持久化线程
            PersistentProcesser persistProcess = new PersistentProcesser();
            Thread m_thread3 = new Thread(new ThreadStart(persistProcess.Processing));
            m_thread3.Start();

            //DataProcess.DataProcessingEmail();

            LogUtil.info("数据解析服务启动成功!");
            string strLine;
            do
            {
                strLine = Console.ReadLine();
            } while (strLine != null && strLine != "exit");

            LogUtil.info("正在退出数据解析服务...");
            LogUtil.info("持久化剩余缓存数据...");
            //持久化尚未持久化的缓存数据后退出
            persistProcess.peristentData();
            LogUtil.info("剩余数据持久化完成...");

            //kill thread
            if (m_thread.IsAlive)
                m_thread.Abort();
            if (m_thread3.IsAlive)
                m_thread3.Abort();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            //先设置当前工作目录为进程目录
            Console.WriteLine("原工作目录:" + Directory.GetCurrentDirectory());
            Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
            Console.WriteLine("现在工作目录:" + Directory.GetCurrentDirectory());

            //从后台维护数据表中设置错误码静态数据
            //ErrorcodeService.GetInstance().setErrorStaticData();

            string validdog = ConfigurationSettings.AppSettings["validdog"];//是否验证狗
            //启动解析线程
            TcpDataProcesser dataProcess = new TcpDataProcesser();
            Thread           m_thread    = new Thread(new ThreadStart(dataProcess.Processing));

            m_thread.Start();


            //启动持久化线程
            PersistentProcesser persistProcess = new PersistentProcesser();
            Thread m_thread3 = new Thread(new ThreadStart(persistProcess.Processing));

            m_thread3.Start();

            //设置最后成功处理时间到memcached,以便检测监控程序能判断是否正常运行
            MemcachedClientSatat.getInstance().Set("monitor_analyze_run_lasttime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            LogUtil.info("服务启动成功!");

            //循环检测狗
            while (1 == 1)
            {
                //循环狗检测程序,这个就要求必须将狗一直插入才能正常运行软件
                if (validdog == null || validdog.Equals("true"))
                {
                    LogUtil.info("开始检测加密狗");
                    string result = monitordog();
                    if (!string.IsNullOrEmpty(result))
                    {
                        LogUtil.info(result);

                        //kill thread
                        if (dataProcess != null)
                        {
                            dataProcess.runmark = false;
                        }

                        if (m_thread != null)
                        {
                            if (m_thread.IsAlive)
                            {
                                m_thread.Abort();
                            }
                        }

                        if (persistProcess != null)
                        {
                            persistProcess.runmark = false;
                        }

                        if (m_thread3 != null)
                        {
                            if (m_thread3.IsAlive)
                            {
                                m_thread3.Abort();
                            }
                        }

                        LogUtil.info("软件已经停止服务!");
                    }
                }
                Thread.Sleep(60 * 1000);//线程休息1分钟
            }
        }