Esempio n. 1
0
        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);
        }
        /// <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());
            }
        }
Esempio n. 3
0
        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
            {
            }
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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());
            }
        }