• C# 队列相关 MessageHandlerQueue


            /// <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#经典面试题及答案【20090210更新】
    难道SQL的子查询就是鸡肋吗?
    转:WCF基础知识问与答
    针对分析单点登录(流程图与数据安全)提出的问题及解决方案
    老生常谈:装饰者模式
    我对IDisposable接口的理解
    log4net日志组件经验分享
    老生常谈:工厂模式兄弟姐妹
    探讨高访问量网站优化方案(从图片角度)
  • 原文地址:https://www.cnblogs.com/mathyk/p/9454928.html
Copyright © 2020-2023  润新知