码迷,mamicode.com
首页 > Windows程序 > 详细

C# 队列相关

时间:2018-08-10 15:54:22      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:exe   log   _id   gty   etl   err   col   相关   line   

        /// <summary>
        /// 消息队列
        /// </summary>
        public MessageHandlerQueue _msgHdl;
        public MessageHandlerQueue MsgHandle
        {
            get
            {
                if (_msgHdl == null)
                {
                    _msgHdl = new MessageHandlerQueue(ThreadFun);
                    _msgHdl.Start();
                    return _msgHdl;
                }
                else
                    return _msgHdl;
            }
            private set
            {
                _msgHdl = value;
            }
        }
        #region 消息队列函数
        private void ThreadFun(object msg)
        {
            try
            {
                var dev = msg as CfgObjectDevice;
                if (dev != null)
                {
                    if (devDao != null)
                    {
                        //devDao.SaveOrUpdate(dev);

                        int isOnline = dev.IsOnline ? 1 : 0;
                        var sqlStr = string.Format("UPDATE cfg_object_device SET is_online = {0} WHERE object_id = {1}", isOnline, dev.ObjectId);
                        devDao.ExecSQL(sqlStr);

                    }
                    return;
                }

                var mod = msg as CfgObjectModule;
                if (mod != null)
                {
                    if (moduleDao != null)
                    {
                        //moduleDao.SaveOrUpdate(mod);

                        int isOnline = mod.IsOnline ? 1 : 0;
                        var sqlStr = string.Format("UPDATE cfg_object_module SET is_online = {0} WHERE object_id = {1}", isOnline, mod.ObjectId);
                        moduleDao.ExecSQL(sqlStr);
                    }
                    return;
                }

                var sys = msg as CfgObjectSubsystem;
                if (sys != null)
                {
                    if (subsysDao != null)
                    {
                        //subsysDao.SaveOrUpdate(sys);

                        int link_status = 0;
                        if (sys.LinkStatus == "1")
                            link_status = 1;
                        else if (sys.LinkStatus == "0")
                            link_status = 0;

                        var sqlStr = string.Format("UPDATE cfg_object_subsystem SET link_status = {0} WHERE object_id = {1}", link_status, sys.ObjectId);
                        subsysDao.ExecSQL(sqlStr);

                    }
                    return;
                }

                var entity = msg as HisAlarm;
                if (entity != null)
                {
                    if (alarmDao != null)
                    {
                        alarmDao.SaveOrUpdate(entity);
                    }
                    return;
                }

                var cfgTypeAlarm = msg as CfgTypeAlarm;
                if (cfgTypeAlarm != null)
                {
                    if (cfgTypeAlarmDao != null)
                    {
                        cfgTypeAlarmDao.SaveOrUpdate(cfgTypeAlarm);
                    }
                    return;
                }


                LogHelper.GetLog("Server").ErrorFormat("{0} 类型没有处理", msg.GetType());
            }
            catch (Exception ex)
            {
                LogHelper.GetLog("Server").Error(ExceptionHelper.GetExceptionDesc(ex));
            }

        }

 

C# 队列相关

标签:exe   log   _id   gty   etl   err   col   相关   line   

原文地址:https://www.cnblogs.com/mathyk/p/9454928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!