コード例 #1
0
        public ServiceKOIPM(string[] args)
        {
            InitializeComponent();


            try
            {
                CommClass.OStype = Convert.ToInt32(args[0].ToString());
            }
            catch
            {
                CommClass.OStype = 0;
            }
            CommClass.OStype = 1;


            CommClass.SetPubPath();
            Commonality.ConsoleManage.objectTime();

            CommClass.CreateConfig();

            //CommClass.CreateServListTable();
            //CommClass.CreateServList();

            //CommClass.ReadXML(CommClass.ServListPath, ref CommClass.DtServList);

            DataTable dt = new DataTable();

            CommClass.ReadXML(CommClass.ConfigFilePath, ref dt);

            if (dt.Rows.Count != 0)
            {
                #region 读取KMS配置相关信息
                //读取数据库连接
                CommClass.DBCONN = dt.Rows[0]["DBCONN"].ToString();
                //本地服务器ID
                CommClass.ID = dt.Rows[0]["ID"].ToString();
                //本地服务IP地址
                CommClass.IP = dt.Rows[0]["IP"].ToString();
                //是否启用自动启动
                CommClass.ISAUTOSTART = dt.Rows[0]["ISAUTOSTART"].ToString();

                //本地服务端口号

                try
                {
                    CommClass.PORT = Convert.ToInt32(dt.Rows[0]["PORT"].ToString());
                }
                catch
                {
                    CommClass.PORT = 0;
                }


                //上级服务ID
                CommClass.UPID = dt.Rows[0]["UPID"].ToString();

                //上级服务IP地址
                CommClass.UPIP = dt.Rows[0]["UPIP"].ToString();

                //上级服务端口号
                try
                {
                    CommClass.UPPORT = Convert.ToInt32(dt.Rows[0]["UPPORT"].ToString());
                }
                catch
                {
                    CommClass.UPPORT = 0;
                }

                //数据库连接字符串
                CommClass.DBCONN = dt.Rows[0]["DBCONN"].ToString();

                //是否连接上级服务{0:不连接;1:连接}
                CommClass.ISCONUP = dt.Rows[0]["ISCONUP"].ToString();

                #endregion

                if (CommClass.ISCONUP == "0")
                {
                    CommonFunction.GetServerList();
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectUpServ.HeartSocketobjectTime), null);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectUpServ.Start), null);//连接上级服务器
                }

                AsynTCPSocket listener = new AsynTCPSocket(CommClass.OStype.ToString());
                listener.listenerAddress         = CommClass.IP;
                listener.listenerPort            = CommClass.PORT;
                listener.ReceiveEvent           += new AsynchronousSocketListenerReceiveEvent(tcpServer_ReceiveEvent.ReceiveEvent);
                listener.ExceptionHandlingEvent += new AsynchronousServerExceptionHandlingEvent(tcpServer_ExceptionHandlingEvent.ReceiveEvent);
                listener.Start();
                while (!listener.IsBound)
                {
                    Thread.Sleep(500);
                }

                if (listener.IsBound)
                {
                    Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor:SOCKET=" + CommClass.IP + ":" + CommClass.PORT.ToString() + "  TCP服務啟動成功", "");
                }
                else
                {
                    Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor:SOCKET=" + CommClass.IP + ":" + CommClass.PORT.ToString() + "   TCP服務啟動失敗", "");
                }

                MonitorInterface.AlarmEvent += new ServMonitorAlarmHandlingEvent(ServMonitor_AlarmHandlingEvent.AlarmEvent);
                MonitorInterface.OptEvent   += new ServMonitorOptHandlingEvent(ServMonitor_OptHandlingEvent.OptEvent);
                MonitorInterface MonInterface = new MonitorInterface();
                MonInterface.Start(CommClass.OStype.ToString(), CommClass.ISAUTOSTART);
            }
        }
コード例 #2
0
        /// <summary>
        /// 消息处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static void process(StateObject request)
        {
//            <?xml version="1.0" encoding="utf-8"?>
//<ROOT>
//    <ITEM>
//<ID></ID>
//<DEVID>1</ DEVID >
//<DEVNAME></ DEVNAME >
//<DEVTYPE></ DEVTYPE >
//<IP></ IP >
//<PORT></ PORT >
//<UPDEVID></ UPDEVID >
//<DESCR></ DESCR >
//    </ITEM>
//</ROOT>

            //哈希表存放包体内容
            Hashtable _hashtable_Package = new Hashtable();
            string    DevID     = ""; //设备编号
            string    DevName   = ""; //设备名称
            int       DevTypeID = 0;  //设备类型编号
            string    IP        = ""; //IP地址
            string    PORT      = ""; //端口号
            string    UPDEVID   = ""; //上级设备编号
            string    DESCR     = ""; //说明
            int       intID     = 0;  //设备信息索引编号

            try
            {
                if (request != null)
                {
                    #region 包体解析
                    short cmd1 = 0; //主命令字
                    short cmd2 = 0; //子命令字
                    cmd1 = OMSCmd.DevInfoModify;
                    cmd2 = ErrCommon.Success;
                    byte[]    ByteResult = null;
                    DataTable dt         = new DataTable();
                    Commonality.CommClass.ReadXML(request.receiveFileTemporarily, ref dt);

                    if (dt.Rows.Count <= 0)
                    {
                        cmd2 = -101;//解包失败
                        //哈希表存放包体内容
                        Hashtable _hashtable_Package_Temp = new Hashtable();
                        _hashtable_Package_Temp.Add("1", request);//...連結位置
                        _hashtable_Package_Temp.Add("2", cmd1);
                        _hashtable_Package_Temp.Add("3", cmd2);
                        ByteResult = null;
                        _hashtable_Package_Temp.Add("4", ByteResult);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(CommonFunction.SendDatas), _hashtable_Package_Temp);
                        Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious,
                                                        "KOIPMonitor>>DevInfoModify>>process>>", "消息体内容有误");
                        return;
                    }

                    try
                    {
                        intID = Convert.ToInt32(dt.Rows[0]["ID"].ToString());
                    }
                    catch
                    {
                        intID = 0;
                    }

                    DevID   = dt.Rows[0]["DEVID"].ToString();
                    DevName = dt.Rows[0]["DEVNAME"].ToString();
                    try
                    {
                        DevTypeID = Convert.ToInt32(dt.Rows[0]["DEVTYPE"].ToString());
                    }
                    catch
                    {
                        DevTypeID = 0;
                    }
                    IP      = dt.Rows[0]["IP"].ToString();
                    PORT    = dt.Rows[0]["PORT"].ToString();
                    UPDEVID = dt.Rows[0]["UPDEVID"].ToString();
                    DESCR   = dt.Rows[0]["DESCR"].ToString();


                    int Ret = -1;

                    DevInfo_Modify(intID, DevID,
                                   DevName,
                                   DevTypeID,
                                   IP,
                                   PORT,
                                   UPDEVID,
                                   DESCR, ref Ret);
                    switch (Ret)
                    {
                    case -1:
                        cmd2 = -8018;
                        break;

                    case 0:
                        cmd2       = ErrCommon.Success;
                        ByteResult = BitConverter.GetBytes(intID);
                        CommonFunction.GetServerList();
                        break;
                    }


                    #endregion

                    Hashtable _hashtable_PackageArry = new Hashtable();
                    _hashtable_PackageArry.Add("1", request);//...連結位置
                    _hashtable_PackageArry.Add("2", cmd1);
                    _hashtable_PackageArry.Add("3", cmd2);
                    _hashtable_PackageArry.Add("4", ByteResult);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(CommonFunction.SendDatas), _hashtable_PackageArry);
                    //CommonFunction.NoticeServerList();
                }
                else
                {
                    Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor>>DevInfoModify>>process>>", "StateObject request==null");
                }
            }
            catch (Exception ex)
            {
                Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "KOIPMonitor>>DevInfoModify>>process>>", ex.Message);
            }
            finally
            {
                //删除文件
                //if (!string.IsNullOrEmpty(request.receiveFileTemporarily))
                //    ThreadPool.QueueUserWorkItem(new WaitCallback(DiskIO.Del), request.receiveFileTemporarily);

                //GC.Collect();
            }
        }