CommandMsgV2 _CommitTabluarInfo(ICommunicationMessage message)
        {
            CommandMsgV2 resp = new CommandMsgV2();

            resp.SeqID          = CommandProcessor.AllocateID();
            resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
            resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);
            resp.SetValue("ClientID", message.GetValue("ClientID"));
            resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");

            try
            {
                string pkcolumn = message.GetValue(Constants.MSG_PARANAME_TABLEPKCOL).ToString();
                string tn       = message.GetValue(Constants.MSG_PARANAME_TABLENAME).ToString();

                string catalog = message.GetValue(Constants.MSG_PARANAME_TABLECATALOG).ToString().ToUpper();

                DataTable dt = message.GetValue(Constants.MSG_PARANAME_CHARTRESULT) as DataTable;
                _CommitTable(catalog, dt, tn, pkcolumn);
            }
            catch (Exception ex)
            {
                resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                resp.SetValue(Constants.MSG_PARANAME_REASON, ex.Message);
            }

            return(resp);
        }
        private ICommunicationMessage _ExecuteNonQuery(ICommunicationMessage message)
        {
            CommandMsgV2 resp = new CommandMsgV2();

            resp.SeqID          = CommandProcessor.AllocateID();
            resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
            resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);
            resp.SetValue("ClientID", message.GetValue("ClientID"));
            resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");

            try
            {
                string cmd     = message.GetValue(Constants.MSG_PARANAME_RAWSQL).ToString();
                string catalog = message.GetValue(Constants.MSG_PARANAME_TABLECATALOG).ToString().ToUpper();
                string connstr = "";
                if (catalog == "SYS_DB")
                {
                    connstr = AlarmManager.instance().ConnString;
                }
                else if (catalog == "USER_DB")
                {
                    connstr = UserManager.instance().ConnString;
                }

                SqlHelper.ExecuteNonQuery(connstr, CommandType.Text, cmd);
            }
            catch (Exception ex)
            {
                resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                resp.SetValue(Constants.MSG_PARANAME_REASON, ex.Message);
            }

            return(resp);
        }
        private CommandMsgV2 UserLogout(ICommunicationMessage message)
        {
            CommandMsgV2 responseMsg = new CommandMsgV2();

            try
            {
                if (message.Contains("ClientID"))
                {
                    if (message.Contains("用户名"))
                    {
                        string sUserName = message.GetValue("用户名").ToString().Trim();
                        string sql       = "update Operator set lastlogouttime = '" + DateTime.Now.ToString().Trim() + "' where login_name = '" + sUserName + "'";
                        SqlHelper.ExecuteNonQuery(m_ConnStr, CommandType.Text, sql);

                        // 注销内部客户端的数据
                        CommandMsgV2 logout = new CommandMsgV2();
                        logout.TK_CommandType = Constants.TK_CommandType.UNREGISTERCLIENT;
                        logout.SeqID          = CommandProcessor.AllocateID();
                        logout.SetValue("ClientID", message.GetValue("ClientID"));
                        CommandProcessor.instance().DispatchCommand(logout);

                        responseMsg.SeqID          = CommandProcessor.AllocateID();
                        responseMsg.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                        responseMsg.SetValue("ClientID", message.GetValue("ClientID"));
                        responseMsg.SetValue("RESPONSE_TO", message.SeqID);
                        responseMsg.SetValue("RESULT", "OK");
                    }
                    else
                    {
                        responseMsg.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                        responseMsg.SeqID          = CommandProcessor.AllocateID();
                        responseMsg.SetValue("ClientID", message.GetValue("ClientID"));
                        responseMsg.SetValue("RESPONSE_TO", message.SeqID);
                        responseMsg.SetValue("RESULT", "NOK");
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                try
                {
                    responseMsg.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                    responseMsg.SeqID          = CommandProcessor.AllocateID();
                    responseMsg.SetValue("ClientID", message.GetValue("ClientID"));
                    responseMsg.SetValue("RESPONSE_TO", message.SeqID);
                    responseMsg.SetValue("RESULT", "NOK");
                }
                catch { }
            }
            finally
            {
            }
            return(responseMsg);
        }
        CommandMsgV2 _GetTabluarInfo(ICommunicationMessage message)
        {
            CommandMsgV2 resp = new CommandMsgV2();

            resp.SeqID          = CommandProcessor.AllocateID();
            resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
            resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);
            resp.SetValue("ClientID", message.GetValue("ClientID"));
            resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
            resp.SetValue(Constants.MSG_PARANAME_CHARTRESULT, null);

            try
            {
                string filter = message.GetValue(Constants.MSG_PARANAME_TABLEFILTER).ToString();
                //string pkcolumn = message.GetValue(Constants.MSG_PARANAME_TABLEPKCOL).ToString();
                string tn = message.GetValue(Constants.MSG_PARANAME_TABLENAME).ToString();

                string catalog = message.GetValue(Constants.MSG_PARANAME_TABLECATALOG).ToString().ToUpper();
                string connstr = "";
                if (catalog == "SYS_DB")
                {
                    connstr = AlarmManager.instance().ConnString;
                }
                else if (catalog == "USER_DB")
                {
                    connstr = UserManager.instance().ConnString;
                }

                string cmd = "select * from " + tn;
                if (filter.Trim() != "")
                {
                    cmd += " where " + filter;
                }

                DataSet ds = new DataSet();
                SqlHelper.FillDataset(connstr, CommandType.Text, cmd, ds, new string[] { tn });
                ds.AcceptChanges();
                resp.SetValue(Constants.MSG_PARANAME_CHARTRESULT, ds.Tables[tn]);
            }
            catch (Exception ex)
            {
                resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                resp.SetValue(Constants.MSG_PARANAME_REASON, ex.Message);
            }

            return(resp);
        }
        private ICommunicationMessage _GetTabluarVariantInfo(ICommunicationMessage message)
        {
            CommandMsgV2 resp = new CommandMsgV2();

            resp.SeqID          = CommandProcessor.AllocateID();
            resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
            resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);
            resp.SetValue("ClientID", message.GetValue("ClientID"));
            resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
            resp.SetValue(Constants.MSG_PARANAME_CHARTRESULT, null);

            try
            {
                string cmd     = message.GetValue(Constants.MSG_PARANAME_RAWSQL).ToString();
                string catalog = message.GetValue(Constants.MSG_PARANAME_TABLECATALOG).ToString().ToUpper();
                string connstr = "";
                if (catalog == "SYS_DB")
                {
                    connstr = AlarmManager.instance().ConnString;
                }
                else if (catalog == "USER_DB")
                {
                    connstr = UserManager.instance().ConnString;
                }

                DataSet ds = new DataSet();
                SqlHelper.FillDataset(connstr, CommandType.Text, cmd, ds, new string[] { "result" });
                ds.AcceptChanges();
                resp.SetValue(Constants.MSG_PARANAME_CHARTRESULT, ds.Tables["result"]);
            }
            catch (Exception ex)
            {
                resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                resp.SetValue(Constants.MSG_PARANAME_REASON, ex.Message);
            }

            return(resp);
        }
Exemple #6
0
        private void _dealing(object state)
        {
            m_ClearEvent.Reset();

            try
            {
                while (Interlocked.Read(ref m_Run) == 1)
                {
                    m_SignalNewMessage.WaitOne();
                    if (Interlocked.Read(ref m_Run) == 0)
                    {
                        return;
                    }

                    // 每次得到信号都将队列中的报文处理完
                    while (Interlocked.Read(ref m_Run) == 1)
                    {
                        ICommunicationMessage msg = null;

                        lock (m_DelayedMsgs)
                        {
                            if (m_DelayedMsgs.Count == 0)
                            {
                                break;
                            }
                            msg = m_DelayedMsgs.Dequeue();
                        }

                        switch (msg.TK_CommandType)
                        {
                        case Constants.TK_CommandType.ALARM_REPORT:
                            _processAlarm(msg.GetValue("AlarmList") as ArrayList);
                            break;

                        default:
                            m_Communicator.enqueueDelayedMessages(msg);
                            break;
                        }

                        Thread.Sleep(10);
                    }
                }
            }
            finally
            {
                m_ClearEvent.Set();
            }
        }
        void _VerifyTerminalsStatus(ICommunicationMessage message)
        {
            C5.HashDictionary <long, AdapterInfo> ads = new C5.HashDictionary <long, AdapterInfo>();
            AlarmManager.instance().GetAdaptersInfo(ads);

            foreach (C5.KeyValuePair <long, AdapterInfo> info in ads)
            {
                try
                {
                    System.Net.IPEndPoint end = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(info.Value.Address), info.Value.ControllerPort);
                    if (end.Port == 0)
                    {
                        continue;
                    }
                    else
                    {
                        ICommClient comm = CommManager.instance().CreateCommClient <CommandMsgV2, TKMessageV2Extractor, TKMessageV2Encoder>("控制器",
                                                                                                                                            end.Address.ToString(), end.Port, 30, false, false);

                        if (!comm.Start())
                        {
                            // remove adapter
                            AlarmManager.instance().RemoveAdapterInfo(info.Key);
                        }
                        else
                        {
                            comm.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    DefLib.Util.Logger.Instance().SendLog(ex.ToString());
                }
            }

            CommandMsgV2 msg = new CommandMsgV2();

            msg.TK_CommandType = Constants.TK_CommandType.MON_GETTERMINALSINFO;
            msg.SeqID          = message.SeqID;
            msg.SetValue("ClientID", message.GetValue("ClientID"));

            CommandProcessor.instance().DispatchCommand(msg);
        }
        /// <summary>
        /// 命令处理程序
        /// </summary>
        /// <param name="message"></param>
        public void handleCommand(ICommunicationMessage message)
        {
            if (message.Contains(Constants.MSG_PARANAME_ADAPTER_NAME))
            {
                if (message.GetValue(Constants.MSG_PARANAME_ADAPTER_NAME).ToString().Trim() != Name)
                {
                    return;
                }
            }
            else
            {
                throw new Exception("Incoming package's name mismatched.");
            }

            CommandMsgV2 resp = new CommandMsgV2();

            resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
            resp.SeqID          = CommandProcessor.AllocateID();
            resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);
            try
            {
                if (message.Contains("ClientID"))
                {
                    resp.SetValue("ClientID", message.GetValue("ClientID"));
                }
                else
                {
                    throw new Exception("No ClientID in incoming package.");
                }
                //对应几个命令:启动、停止、退出、
                switch (message.TK_CommandType)
                {
                case Constants.TK_CommandType.ADAPTER_START:
                    if (Start())
                    {
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                    }
                    else
                    {
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    }

                    break;

                case Constants.TK_CommandType.ADAPTER_STOP:
                    if (Stop())
                    {
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                    }
                    else
                    {
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    }

                    break;

                case Constants.TK_CommandType.ADAPTER_SHUTDOWN:
                    Shutdown();
                    break;

                case Constants.TK_CommandType.ADAPTER_GETRUNTIMEINFO:
                {
                    Process p = Process.GetCurrentProcess();
                    resp.SetValue("PROCESSID", p.Id.ToString());
                    resp.SetValue("THREADCOUNT", p.Threads.Count.ToString());
                    resp.SetValue("PHYMEMORY", p.WorkingSet64.ToString());
                    resp.SetValue("STATUS", GetStatus().ToString());
                    resp.SetValue("STARTTIME", p.StartTime.ToString());
                    resp.SetValue("CPUTIME", ((long)p.TotalProcessorTime.TotalMinutes).ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.ADAPTER_GETOMCLIST:    //重点
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in GetOMCList())
                    {
                        sb.Append(s);
                        sb.Append(",");
                    }

                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    resp.SetValue("OMCLIST", sb.ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.ADAPTER_GETCURLOG:
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in GetCurrentLog())
                    {
                        sb.Append(s);
                        sb.Append(Environment.NewLine);
                    }

                    resp.SetValue("CURLOG", sb.ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.ADAPTER_GETLOGFILES:
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in GetLogFiles())
                    {
                        sb.Append(s);
                        sb.Append(",");
                    }

                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    resp.SetValue("LOGFILES", sb.ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                default:
                    break;
                }

                CommandProcessor.instance().DispatchCommand(resp);
            }
            catch (Exception ex)
            {
                Logger.Instance().SendLog("AdapterController", ex.ToString());
            }
        }
        public void handleCommand(ICommunicationMessage message)
        {
            long clientid = 0, immediateid = 0;

            try
            {
                clientid = Convert.ToInt64(message.GetValue("ClientID").ToString());
                lock (m_ClientCommunicators)
                {
                    if (!m_ClientCommunicators.ContainsKey(clientid))
                    {
                        return; // 非来自自身管理的client的响应包, 不处理
                    }
                }
            }
            catch
            {
                return; // 没有clientid的报文不处理
            }

            try
            {
                // 非自身发包的响应以及向客户端的主动发包都发送到客户端
                if (message.Contains(Constants.MSG_PARANAME_IMMEDIATE_ID))
                {
                    immediateid = Convert.ToInt64(message.GetValue(Constants.MSG_PARANAME_IMMEDIATE_ID).ToString());
                }

                if (clientid == Constants.BOARDCAST_CLIENT_ID)
                {
                    lock (m_ClientCommunicators)
                    {
                        foreach (Communicator disp in m_ClientCommunicators.Values)
                        {
                            disp.enqueueMessage(message.clone());
                        }
                    }
                }
                else
                {
                    ICommunicator dispatcher = null;
                    lock (m_ClientCommunicators)
                    {
                        if (!m_ClientCommunicators.ContainsKey(clientid))
                        {
                            return;
                        }

                        dispatcher = m_ClientCommunicators[clientid];
                    }

                    dispatcher.enqueueMessage(message);
                }
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
            }
            finally
            {
            }
        }
        CommandMsgV2 _StartAdapter(ICommunicationMessage message)
        {
            try
            {
                CommandMsgV2 resp = new CommandMsgV2();
                resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                resp.SeqID          = CommandProcessor.AllocateID();
                resp.SetValue("ClientID", message.GetValue("ClientID"));
                resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);


                long adapterid = Convert.ToInt64(message.GetValue(Constants.MSG_PARANAME_ADAPTER_ID));

                C5.HashDictionary <long, AdapterInfo> ads = new C5.HashDictionary <long, AdapterInfo>();
                AlarmManager.instance().GetAdaptersInfo(ads);
                if (!ads.Contains(adapterid))
                {
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    resp.SetValue(Constants.MSG_PARANAME_REASON, "采集器不存在.");
                    return(resp);
                }

                try
                {
                    CommandMsgV2 cmd = new CommandMsgV2();
                    cmd.SeqID          = CommandProcessor.AllocateID();
                    cmd.TK_CommandType = Constants.TK_CommandType.ADAPTER_START;
                    cmd.SetValue("ClientID", adapterid);
                    cmd.SetValue(Constants.MSG_PARANAME_ADAPTER_NAME, ads[adapterid].Name);

                    System.Net.IPEndPoint end = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ads[adapterid].Address), ads[adapterid].ControllerPort);
                    if (end.Port == 0)
                    {
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                        resp.SetValue(Constants.MSG_PARANAME_REASON, "不可远程控制的采集器");
                    }
                    else
                    {
                        ICommClient comm = CommManager.instance().CreateCommClient <CommandMsgV2, TKMessageV2Extractor, TKMessageV2Encoder>("控制器",
                                                                                                                                            end.Address.ToString(), end.Port, 30, false, false);

                        comm.Start();
                        ICommunicationMessage r2 = comm.SendCommand(cmd);
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, r2.GetValue(Constants.MSG_PARANAME_RESULT));
                        comm.Close();
                    }
                }
                catch (Exception ex)
                {
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    resp.SetValue(Constants.MSG_PARANAME_REASON, ex.Message);
                }

                return(resp);
            }
            catch (Exception ex)
            {
                Logger.Instance().SendLog(ex.ToString());
                return(null);
            }
        }
        public void ConvertFromMsg(ICommunicationMessage msg)
        {
            foreach (string key in msg.GetKeys())
            {
                object val = msg.GetValue(key);
                switch (key)
                {
                case "COMMAND":
                    if (val.ToString() != Constants.MSG_TYPE_ALARM_REPORT && val.ToString() != Constants.MSG_TYPE_ALARM_ORDER_CHANGE)
                    {
                        return;
                    }
                    break;

                case "接收时间":
                    ReceiveTime = val.ToString();
                    break;

                case "集中告警流水号":
                    TKSn = val.ToString();
                    break;

                case "厂商告警流水号":
                    ManuSn = val.ToString();
                    break;

                case "告警城市":
                    City = val.ToString();
                    break;

                case "设备厂商":
                    Manufacturer = val.ToString();
                    break;

                case "业务类型":
                    BusinessType = val.ToString();
                    break;

                case "OMCName":
                    OMCName = val.ToString();
                    break;

                case "网元名称":
                    NeName = val.ToString();
                    break;

                case "网元类型":
                    NeType = val.ToString();
                    break;

                case "对象名称":
                    ObjName = val.ToString();
                    break;

                case "对象类型":
                    ObjType = val.ToString();
                    break;

                case "告警名称":
                    AlarmName = val.ToString();
                    break;

                case "重定义告警名称":
                    Redefinition = val.ToString();
                    break;

                //						case "告警种类":
                //							Category = val.ToString();
                //							break;
                case "告警级别":
                    Severity = val.ToString();
                    break;

                case "告警发生时间":
                    OccurTime = val.ToString();
                    break;

                case "告警确认时间LV1":
                    AckTimeLV1 = val.ToString();
                    break;

                case "再次确认时间LV1":
                    AckAgainTimeLV1 = val.ToString();
                    break;

                case "告警确认时间LV2":
                    AckTimeLV2 = val.ToString();
                    break;

                case "再次确认时间LV2":
                    AckAgainTimeLV2 = val.ToString();
                    break;

                case "告警恢复时间":
                    ClearTime = val.ToString();
                    break;

                case "告警定位信息":
                    Location = val.ToString();
                    break;

                case "操作员信息LV11":
                    OperatorLV11 = val.ToString();
                    break;

                case "操作员信息LV12":
                    OperatorLV12 = val.ToString();
                    break;

                case "操作员信息LV21":
                    OperatorLV21 = val.ToString();
                    break;

                case "操作员信息LV22":
                    OperatorLV22 = val.ToString();
                    break;

                case "工程上报信息":
                    ProjectInfo = val.ToString();
                    break;

                //add
                case "工程超时":
                    ProjectBool = val.ToString();
                    break;

                case "派单人LV1":
                    OrderOperatorLV1 = val.ToString();
                    break;

                case "派单号LV1":
                    OrderIDLV1 = val.ToString();
                    break;

                case "派单时间LV1":
                    OrderTimeLV1 = val.ToString();
                    break;

                case "派单人LV2":
                    OrderOperatorLV2 = val.ToString();
                    break;

                case "派单号LV2":
                    OrderIDLV2 = val.ToString();
                    break;

                case "派单时间LV2":
                    OrderTimeLV2 = val.ToString();
                    break;

                default:
                    break;
                }
            }
        }
Exemple #12
0
        public void ConvertFromMsg(ICommunicationMessage msg)
        {
            try
            {
                if (msg.TK_CommandType != Constants.TK_CommandType.ALARM_REPORT &&
                    msg.TK_CommandType != Constants.TK_CommandType.ADAPTER_ALARM_REPORT &&
                    msg.TK_CommandType != Constants.TK_CommandType.ALARM_ORDER_CHANGE)
                {
                    throw new Exception("无效告警报文.");
                }

                SyncRoot.AcquireWriterLock(-1);

                if (!msg.Contains("集中告警流水号"))
                {
                    throw new Exception("告警报文没有流水号.");
                }

                foreach (string key in msg.GetKeys())
                {
                    switch (key)
                    {
                    case "集中告警流水号":
                        TKSn = Convert.ToUInt64(msg.GetValue(key).ToString());
                        break;

                    case "厂商告警流水号":
                        ManuSn = msg.GetValue(key).ToString();
                        break;

                    case "告警城市":
                        City = msg.GetValue(key).ToString();
                        break;

                    case "设备厂商":
                        Manufacturer = msg.GetValue(key).ToString();
                        break;

                    case "业务类型":
                        BusinessType = msg.GetValue(key).ToString();
                        break;

                    case "网元名称":
                        NeName = msg.GetValue(key).ToString();
                        break;

                    case "网元类型":
                        NeType = msg.GetValue(key).ToString();
                        break;

                    case "对象名称":
                        ObjName = msg.GetValue(key).ToString();
                        break;

                    case "对象类型":
                        ObjType = msg.GetValue(key).ToString();
                        break;

                    case "告警名称":
                        AlarmName = msg.GetValue(key).ToString();
                        break;

                    case "重定义告警名称":
                        Redefinition = msg.GetValue(key).ToString();
                        break;

                    //case "告警种类":
                    //    Category = msg.GetValue(key).ToString();
                    //    break;
                    case "告警级别":
                        Severity = msg.GetValue(key).ToString();
                        break;

                    case "告警发生时间":
                        OccurTime = msg.GetValue(key).ToString();
                        break;

                    case "告警确认时间LV1":
                        AckTimeLV1 = msg.GetValue(key).ToString();
                        break;

                    case "再次确认时间LV1":
                        AckAgainTimeLV1 = msg.GetValue(key).ToString();
                        break;

                    case "告警确认时间LV2":
                        AckTimeLV2 = msg.GetValue(key).ToString();
                        break;

                    case "再次确认时间LV2":
                        AckAgainTimeLV2 = msg.GetValue(key).ToString();
                        break;

                    case "告警恢复时间":
                        ClearTime = msg.GetValue(key).ToString();
                        break;

                    case "告警定位信息":
                        Location = msg.GetValue(key).ToString();
                        break;

                    case "操作员信息LV11":
                        OperatorLV11 = msg.GetValue(key).ToString();
                        break;

                    case "操作员信息LV12":
                        OperatorLV12 = msg.GetValue(key).ToString();
                        break;

                    case "操作员信息LV21":
                        OperatorLV21 = msg.GetValue(key).ToString();
                        break;

                    case "操作员信息LV22":
                        OperatorLV22 = msg.GetValue(key).ToString();
                        break;

                    case "工程上报信息":
                        ProjectInfo = msg.GetValue(key).ToString();
                        break;

                    case "工程超时":
                        ProjectTimeOut = msg.GetValue(key).ToString();
                        break;

                    case "派单人LV1":
                        OrderOperatorLV1 = msg.GetValue(key).ToString();
                        break;

                    case "派单号LV1":
                        OrderIDLV1 = msg.GetValue(key).ToString();
                        break;

                    case "派单时间LV1":
                        OrderTimeLV1 = msg.GetValue(key).ToString();
                        break;

                    case "派单人LV2":
                        OrderOperatorLV2 = msg.GetValue(key).ToString();
                        break;

                    case "派单号LV2":
                        OrderIDLV2 = msg.GetValue(key).ToString();
                        break;

                    case "派单时间LV2":
                        OrderTimeLV2 = msg.GetValue(key).ToString();
                        break;

                    case "OMCName":
                        OMCName = msg.GetValue(key).ToString();
                        break;

                    case "Reserved2":
                        Reserved2 = msg.GetValue(key).ToString();
                        break;

                    case "Reserved3":
                        Reserved3 = msg.GetValue(key).ToString();
                        break;

                    case "接收时间":
                        ReceiveTime = msg.GetValue(key).ToString();
                        break;

                    default:
                        break;
                    }
                }
            }
            finally
            {
                SyncRoot.ReleaseWriterLock();
            }
        }
        private CommandMsgV2 UserLogin(ICommunicationMessage message)
        {
            CommandMsgV2 responseMsg = new CommandMsgV2();

            try
            {
                if (message.Contains("ClientID"))
                {
                    if (message.Contains("用户名") && message.Contains("密码"))
                    {
                        string sUserName = message.GetValue("用户名").ToString().Trim();
                        string sPassword = message.GetValue("密码").ToString().Trim();

                        string  sQuery = "select manage,company from Operator where valid=1 and login_name = '" + sUserName + "' and password = '******'";
                        DataSet ds;
                        ds = SqlHelper.ExecuteDataset(m_ConnStr, CommandType.Text, sQuery);

                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            //用户名、密码正确
                            object[] objs     = ds.Tables[0].Rows[0].ItemArray;
                            string   sRight   = objs[0].ToString();
                            string   sCompany = ds.Tables[0].Rows[0]["company"].ToString();

                            //查询用户可管理的业务类型
                            sQuery = "select businesstype from Operator_BusinessType where login_name = '" + sUserName + "'";
                            ds.Tables.Clear();

                            ds = SqlHelper.ExecuteDataset(m_ConnStr, CommandType.Text, sQuery);

                            string sFilter = "";
                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                object[] temps = dr.ItemArray;
                                sFilter += temps[0].ToString().Trim() + ",";
                            }

                            #region 先发命令给CM,通知客户端登陆成功
                            CommandMsgV2 MsgLogOK = new CommandMsgV2();
                            MsgLogOK.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                            MsgLogOK.SeqID          = CommandProcessor.AllocateID();
                            MsgLogOK.SetValue("ClientID", message.GetValue("ClientID"));
                            MsgLogOK.SetValue("RESPONSE_TO", message.SeqID);
                            MsgLogOK.SetValue("RESULT", "OK");
                            MsgLogOK.SetValue("BUSINESSTYPE", sFilter.Trim());
                            MsgLogOK.SetValue("RIGHT", sRight.Trim());
                            MsgLogOK.SetValue("COMPANY", sCompany.Trim());

                            CommandProcessor.instance().DispatchCommand(MsgLogOK);

                            #endregion


                            //发命令给AM,注册客户端
                            responseMsg.SeqID          = message.SeqID;
                            responseMsg.TK_CommandType = Constants.TK_CommandType.REGISTERCLIENT;
                            responseMsg.SetValue("ClientID", message.GetValue("ClientID"));
                            responseMsg.SetValue(Constants.MSG_PARANAME_AUTHORIZED, true);
                            responseMsg.SetValue("SERVERNAME", Constants.ALARM_SERVERNAME);
                            responseMsg.SetValue("Filter", sFilter.Trim());
                            responseMsg.SetValue("RIGHT", sRight.Trim());
                            responseMsg.SetValue("COMPANY", sCompany.Trim());

                            sQuery = "update Operator set lastlogintime = '" + DateTime.Now.ToString() + "' where login_name = '" + sUserName + "'";

                            SqlHelper.ExecuteNonQuery(m_ConnStr, CommandType.Text, sQuery);

                            Logger.Instance().SendLog("UM", "用户:" + sUserName + " 已登录到系统.");
                        }
                        else
                        {
                            //登录失败
                            responseMsg.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                            responseMsg.SetValue("ClientID", message.GetValue("ClientID"));
                            responseMsg.SetValue("RESPONSE_TO", message.SeqID);
                            responseMsg.SetValue("RESULT", "NOK");

                            Logger.Instance().SendLog("UM", "用户:" + sUserName + " 登录失败.");
                        }
                    }
                    else
                    {
                        //登录失败
                        responseMsg.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                        responseMsg.SetValue("ClientID", message.GetValue("ClientID"));
                        responseMsg.SetValue("RESPONSE_TO", message.SeqID);
                        responseMsg.SetValue("RESULT", "NOK");

                        Logger.Instance().SendLog("UM", "无效登录包");
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    //登录失败
                    responseMsg.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                    responseMsg.SetValue("ClientID", message.GetValue("ClientID"));
                    responseMsg.SetValue("RESPONSE_TO", message.SeqID);
                    responseMsg.SetValue("RESULT", "NOK");

                    Logger.Instance().SendLog("UM", "登录时出现异常:" + ex.ToString());
                }
                catch { }
            }
            finally
            {
            }
            return(responseMsg);
        }
        public void handleCommand(ICommunicationMessage message)
        {
            CommandMsgV2 resp = new CommandMsgV2();

            resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
            resp.SeqID          = CommandProcessor.AllocateID();
            resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);
            try
            {
                if (message.Contains("ClientID"))
                {
                    resp.SetValue("ClientID", message.GetValue("ClientID"));
                }
                else
                {
                    throw new Exception("No ClientID in incoming package.");
                }

                switch (message.TK_CommandType)
                {
                case Constants.TK_CommandType.SERVER_GETRUNTIMEINFO:
                {
                    Process p = Process.GetCurrentProcess();
                    resp.SetValue("PROCESSID", p.Id.ToString());
                    resp.SetValue("THREADCOUNT", p.Threads.Count.ToString());
                    resp.SetValue("MAX_THREADCOUNT", 30 + (AlarmManager.instance().MaxAdapters + AlarmManager.instance().MaxClients + AlarmManager.instance().MaxControllers) * 2);
                    resp.SetValue("PHYMEMORY", p.WorkingSet64.ToString());

                    /// SystemInfo使用了性能计数器,有可能构造不出来
                    ///
                    resp.SetValue("AVAIL_PHYMEMORY", 0);
                    resp.SetValue("MAX_PHYMEMORY", 0);
                    resp.SetValue("CPUUSAGE", 0);

                    try
                    {
                        resp.SetValue("AVAIL_PHYMEMORY", SystemInfo.Instance.MemoryAvailable);
                        resp.SetValue("MAX_PHYMEMORY", SystemInfo.Instance.PhysicalMemory);
                        resp.SetValue("CPUUSAGE", (int)SystemInfo.Instance.CpuLoad);
                    }
                    catch { }

                    resp.SetValue("STATUS", AlarmManager.instance().GetStatus().ToString());
                    resp.SetValue("STARTTIME", p.StartTime.ToString());
                    resp.SetValue("CPUTIME", ((long)p.TotalProcessorTime.TotalMinutes).ToString());
                    resp.SetValue("ALARMCLIENTS", AlarmManager.instance().GetAlarmClientsNum().ToString());
                    resp.SetValue("MAX_ALARMCLIENTS", AlarmManager.instance().MaxClients);
                    resp.SetValue("ADAPTERCLIENTS", AlarmManager.instance().GetAdapterClientsNum().ToString());
                    resp.SetValue("MAX_ADAPTERCLIENTS", AlarmManager.instance().MaxAdapters);
                    resp.SetValue("ACTIVEALARMNUM", AlarmManager.instance().GetActiveAlarmsNum().ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.SERVER_GETCURLOG:
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in GetCurrentLog())
                    {
                        sb.Append(s);
                    }

                    resp.SetValue("CURLOG", sb.ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.SERVER_GETLOGFILES:
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in GetLogFiles())
                    {
                        sb.Append(s);
                        sb.Append(",");
                    }

                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    resp.SetValue("LOGFILES", sb.ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.MON_GETTERMINALSINFO:
                {
                    C5.HashDictionary <long, AdapterInfo> ads = new C5.HashDictionary <long, AdapterInfo>();
                    AlarmManager.instance().GetAdaptersInfo(ads);

                    resp.SetValue(Constants.MSG_PARANAME_TERMINALS_INFO, ads);
                }
                break;

                default:
                    break;
                }

                CommandProcessor.instance().DispatchCommand(resp);
            }
            catch (Exception ex)
            {
                Main_LogReceived("", ex.ToString());
            }
        }