Exemple #1
0
        protected bool AllocateTKSNFromServer()
        {
            CommandMsgV2 cm = new CommandMsgV2();

            cm.TK_CommandType = Constants.TK_CommandType.ALLOCATE_TKSN;

            cm.SetValue(Constants.MSG_PARANAME_TKSN_NUM, 10000);

            try
            {
                CommandMsgV2 resp = m_CommClient.SendCommand(cm, 120) as CommandMsgV2;
                if (resp == null)
                {
                    return(false);
                }

                if (resp.GetValue(Constants.MSG_PARANAME_RESULT).ToString() != "OK")
                {
                    return(false);
                }

                lock (m_LockAllocation)
                {
                    m_TKSN_Begin = Convert.ToUInt64(resp.GetValue(Constants.MSG_PARANAME_TKSN_START));
                    m_TKSN_End   = Convert.ToUInt64(resp.GetValue(Constants.MSG_PARANAME_TKSN_END));
                }

                return(true);
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
                return(false);
            }
        }
Exemple #2
0
        private void _processAlarm(ArrayList alarms)
        {
            lock (alarms.SyncRoot)
            {
                if (alarms.Count == 0)
                {
                    return;
                }

                for (int i = 0; i < alarms.Count; ++i)
                {
                    TKAlarm      alarm = (TKAlarm)alarms[i];
                    CommandMsgV2 msg   = alarm.ConvertToMsg();

                    m_Communicator.enqueueDelayedMessages(msg);

                    Thread.Sleep(0);

                    if (Interlocked.Read(ref m_Run) == 0)
                    {
                        break;
                    }
                }
            }
        }
        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);
        }
        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);
        }
        /// <summary>
        /// 向待发送队列中插入一条告警, 如果前一报文是告警,则增加到其AlarmList当中,否则新建一个CommandMsg
        /// 如此实现告警发生、恢复事件与告警改变事件的串行化
        /// </summary>
        /// <param name="alarm"></param>
        public void FillAlarm(TKAlarm alarm)
        {
            if (AlarmFilter != "")
            {
                if (AlarmFilter.IndexOf(alarm.BusinessType) == -1)
                {
                    return;
                }
            }

            lock (m_Messages)
            {
                CommandMsgV2 alarm_msg = null;
                if (m_Messages.Count == 0 || m_Messages[m_Messages.Count - 1].TK_CommandType != Constants.TK_CommandType.ALARM_REPORT)
                {
                    alarm_msg = new CommandMsgV2();
                    alarm_msg.TK_CommandType = Constants.TK_CommandType.ALARM_REPORT;
                    alarm_msg.SetValue("ClientID", ClientID);
                    alarm_msg.SetValue("AlarmList", new ArrayList());

                    m_Messages.Add(alarm_msg);
                }
                else
                {
                    alarm_msg = m_Messages[m_Messages.Count - 1];
                }

                ArrayList t = alarm_msg.GetValue("AlarmList") as ArrayList;
                t.Add(new TKAlarm(alarm));
            }
        }
        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);
        }
Exemple #7
0
        //获取告警字符串
        public CommandMsgV2 ConvertToMsg()
        {
            try
            {
                SyncRoot.AcquireReaderLock(-1);

                CommandMsgV2 msg = new CommandMsgV2();
                msg.TK_CommandType = Constants.TK_CommandType.ALARM_REPORT;
                msg.SeqID          = CommandProcessor.AllocateID();

                msg.SetValue("集中告警流水号", TKSn.ToString());
                msg.SetValue("厂商告警流水号", ManuSn);
                msg.SetValue("告警城市", City);
                msg.SetValue("设备厂商", Manufacturer);
                msg.SetValue("业务类型", BusinessType);
                msg.SetValue("网元名称", NeName);
                msg.SetValue("网元类型", NeType);
                msg.SetValue("对象名称", ObjName);
                msg.SetValue("对象类型", ObjType);
                msg.SetValue("告警名称", AlarmName);
                msg.SetValue("重定义告警名称", Redefinition);
                //msg.SetValue("告警种类", Category);
                msg.SetValue("告警级别", Severity);
                msg.SetValue("告警发生时间", OccurTime);
                msg.SetValue("告警确认时间LV1", AckTimeLV1);
                msg.SetValue("再次确认时间LV1", AckAgainTimeLV1);
                msg.SetValue("告警确认时间LV2", AckTimeLV2);
                msg.SetValue("再次确认时间LV2", AckAgainTimeLV2);
                msg.SetValue("告警恢复时间", ClearTime);
                msg.SetValue("告警定位信息", Location);
                msg.SetValue("操作员信息LV11", OperatorLV11);
                msg.SetValue("操作员信息LV12", OperatorLV12);
                msg.SetValue("操作员信息LV21", OperatorLV21);
                msg.SetValue("操作员信息LV22", OperatorLV22);
                msg.SetValue("工程上报信息", ProjectInfo);
                msg.SetValue("派单人LV1", OrderOperatorLV1);
                msg.SetValue("派单号LV1", OrderIDLV1);
                msg.SetValue("派单时间LV1", OrderTimeLV1);
                msg.SetValue("派单人LV2", OrderOperatorLV2);
                msg.SetValue("派单号LV2", OrderIDLV2);
                msg.SetValue("派单时间LV2", OrderTimeLV2);
                msg.SetValue("OMCName", OMCName);
                msg.SetValue("Reserved2", Reserved2);
                msg.SetValue("Reserved3", Reserved3);
                msg.SetValue("接收时间", ReceiveTime);
                msg.SetValue("工程超时", ProjectTimeOut);

                return(msg);
            }
            finally
            {
                SyncRoot.ReleaseReaderLock();
            }
        }
Exemple #8
0
 protected void AdapterAlarmReport(TKAlarm alarm)
 {
     try
     {
         CommandMsgV2 msg = alarm.ConvertToMsg();
         m_CommClient.PostCommand(msg);
     }
     catch (Exception ex)
     {
         SendLog(ex.ToString());
     }
 }
        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);
        }
Exemple #10
0
        protected void AdapterStateReport(AdapterStatus state, object extrainfo)
        {
            CommandMsgV2 cm = new CommandMsgV2();

            cm.TK_CommandType = Constants.TK_CommandType.ADAPTER_STATE_REPORT;

            cm.SetValue(Constants.MSG_PARANAME_ADAPTER_STATE, state);
            cm.SetValue(Constants.MSG_PARANAME_ADAPTER_EXTRAINFO, extrainfo);

            try
            {
                m_CommClient.PostCommand(cm);
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
            }
        }
        public override ICommunicationMessage clone()
        {
            CommandMsgV2 cm = new CommandMsgV2();

            cm.m_EncodeMode = EncodeMode;
            cm.m_SeqID      = SeqID;
            cm.m_Type       = TK_CommandType;

            lock (m_SyncRoot)
            {
                foreach (C5.KeyValuePair <string, object> de in m_Content)
                {
                    cm.SetValue(de.Key, de.Value);
                }
            }

            return(cm);
        }
        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);
        }
        public void handleCommand(ICommunicationMessage message)
        {
            CommandMsgV2 responseMsg = null;

            switch (message.TK_CommandType)
            {
            case Constants.TK_CommandType.LOGIN:
                responseMsg = UserLogin(message);
                break;

            case Constants.TK_CommandType.LOGOUT:
                responseMsg = UserLogout(message);
                break;

            default:
                break;
            }

            CommandProcessor.instance().DispatchCommand(responseMsg);
        }
Exemple #14
0
        protected bool AdapterLogin()
        {
            CommandMsgV2 cm = new CommandMsgV2();

            cm.TK_CommandType = Constants.TK_CommandType.ADAPTER_LOGIN;

            cm.SetValue(Constants.MSG_PARANAME_ADAPTER_NAME, Name);
            cm.SetValue(Constants.MSG_PARANAME_ADAPTER_ADDRESS, m_CommClient.LocalIP.ToString());
            cm.SetValue(Constants.MSG_PARANAME_ADAPTER_CONTROLLER_PORT, ControllerPort);

            try
            {
                CommandMsgV2 resp = m_CommClient.SendCommand(cm) as CommandMsgV2;
                if (resp == null)
                {
                    return(false);
                }

                if (resp.Contains(Constants.MSG_PARANAME_RESULT))
                {
                    switch (resp.GetValue(Constants.MSG_PARANAME_RESULT).ToString())
                    {
                    case "OK":
                        return(true);

                    default:
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
                return(false);
            }
        }
        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 #16
0
        protected bool AdapterLogout()
        {
            CommandMsgV2 cm = new CommandMsgV2();

            cm.TK_CommandType = Constants.TK_CommandType.ADAPTER_LOGOUT;

            try
            {
                CommandMsgV2 resp = m_CommClient.SendCommand(cm) as CommandMsgV2;
                if (resp == null)
                {
                    return(false);
                }

                if (resp.Contains(Constants.MSG_PARANAME_RESULT))
                {
                    switch (resp.GetValue(Constants.MSG_PARANAME_RESULT).ToString())
                    {
                    case "OK":
                        return(true);

                    default:
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                SendLog(ex.ToString());
                return(false);
            }
        }
        /// <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());
            }
        }
        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);
            }
        }
        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());
            }
        }
 public void AddMessage(CommandMsgV2 msg)
 {
     lock (m_Messages)
         m_Messages.Add(msg);
 }