Beispiel #1
0
        protected override void OnStop()
        {
            try
            {
                IBoolCanContinue = false;
                while (IBoolIsBusing)
                {
                    Thread.Sleep(100);
                }
                if (ITcpListener != null)
                {
                    ITcpListener.Stop(); ITcpListener = null;
                }
                CloseAllClientThread();

                FileLog.WriteInfo("Service Stopped At :", DateTime.Now.ToString("G"));
                if (ThreadCheckThreadIsAlive != null)
                {
                    ThreadCheckThreadIsAlive.Abort();
                    ThreadCheckThreadIsAlive = null;
                }

                if (IThreadLogOperation != null)
                {
                    try
                    {
                        IThreadLogOperation.Abort();
                        IThreadLogOperation = null;
                    }
                    catch (System.Exception e)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                FileLog.WriteError("Service Stopped   Error At :", ex.ToString());
            }
        }
Beispiel #2
0
        private void StartTcpSSLServer(int AIntPort)
        {
            string LStrInstallReturn = string.Empty;

            try
            {
                FileLog.WriteInfo("StartTcpSSLServer() Begion", "");

                X509Store LX509Store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

                #region 使用安全证书方式 2015-07-06 修改
                List <string> lstDirs = Directory.GetDirectories(IStrBaseDirectory.Trim('\\')).ToList();
                FileLog.WriteInfo("StartTcpSSLServer()", "lstDirs.count = " + lstDirs.Count);
                string strDir = string.Empty;
                if (lstDirs.Contains(System.IO.Path.Combine(IStrBaseDirectory, @"WinServices")))
                {
                    //UMP.PF.Certificate.pfx //UMP.SSL.Certificate.pfx
                    strDir = System.IO.Path.Combine(IStrBaseDirectory, @"WinServices\UMP.SSL.Certificate.pfx");
                }
                else
                {
                    strDir = System.IO.Path.Combine(IStrBaseDirectory, @"UMP.SSL.Certificate.pfx");
                }

                FileLog.WriteInfo("StartTcpSSLServer()", "IX509CertificateServerPath = " + strDir);
                IX509CertificateServer = new X509Certificate2(strDir, "VoiceCyber,123");

                #endregion

                FileLog.WriteInfo("StartTcpSSLServer() ", " ITcpListener.Start();");
                ITcpListener = new TcpListener(IPAddress.Any, AIntPort);
                ITcpListener.Start();
                FileLog.WriteInfo("StartTcpSSLServer() ", "Finished, SSL Tcp Listener Point : " + AIntPort.ToString() + " Waiting For A Socket Link From Client");
            }
            catch (Exception ex)
            {
                FileLog.WriteInfo("StartTcpSSLServer()Error", ex.ToString());
            }
        }
Beispiel #3
0
        ///// <summary>
        ///// 将日志写入 Windows 事情
        ///// </summary>
        ///// <param name="AStrWriteBody">日志内容</param>
        ///// <param name="AEntryType">日志类型</param>
        //private void WriteEntryLog(string AStrWriteBody, EventLogEntryType AEntryType)
        //{
        //    try
        //    {
        //        UMPServiceLog.WriteEntry(AStrWriteBody, AEntryType);
        //    }
        //    catch { }
        //}

        #endregion


        #region MyRegion
        private void StartService06()
        {
            FileLog.WriteInfo("StartService06()", "Started");
            IStrBaseDirectory = GetCurrentBaseDirectory();
            FileLog.WriteInfo("StartService06()", "IStrBaseDirectory=" + IStrBaseDirectory);

            if (string.IsNullOrEmpty(IStrBaseDirectory))
            {
                return;
            }

            IIntThisServicePort = GetUMPPFBasicHttpPort();
            while (IIntThisServicePort == 0)
            {
                Thread.Sleep(5000);
                IIntThisServicePort = GetUMPPFBasicHttpPort();
            }

            //Service06端口号是UMP端口-6
            IIntThisServicePort -= 6;
            FileLog.WriteInfo("StartService06()", "IIntThisServicePort:" + IIntThisServicePort);

            while (IIntDBType == 0 || string.IsNullOrEmpty(IStrDBConnectProfile))
            {
                GetDatabaseConnectionProfile();
                System.Threading.Thread.Sleep(5000);
            }

            if (!CreateCheckThreadIsAlive())
            {
                return;
            }

            StartTcpSSLServer(IIntThisServicePort);
            FileLog.WriteInfo("StartService06()", "StartTcpSSLServer");

            WaitForSocketClientConnect();
        }
Beispiel #4
0
        /// <summary>
        /// 检测进程是否真正活着的主体程序
        /// </summary>
        private void CheckThreadIsAliveAction()
        {
            bool   LBoolReturn = true, LBoolRemoved = false;
            int    LIntThreadCount = 0, LIntConnectedCount = 0;
            string LStrRetrun = string.Empty;

            try
            {
                while (IBoolCanContinue)
                {
                    RemoveIsNotAliveThread(ref LBoolReturn, ref LBoolRemoved, ref LIntThreadCount, ref LIntConnectedCount, ref LStrRetrun);
                    if (!LBoolReturn)
                    {
                        FileLog.WriteInfo("CheckThreadIsAliveAction()", "Failed\n RemoveIsNotAliveThread()");
                    }

                    Thread.Sleep(3000);
                }
            }
            catch (Exception ex)
            {
                FileLog.WriteInfo("CheckThreadIsAliveAction()", "Failed\n" + ex.ToString());
            }
        }
Beispiel #5
0
        /// <summary>
        /// 获取数据路类型及数据库连接串
        /// </summary>
        /// <returns>string.Empty成功,Error01未进行数据库配置,否则失败</returns>
        ///
        #region 获取数据库连接信息
        private void GetDatabaseConnectionProfile()
        {
            string LStrXmlFileName      = string.Empty;
            string LStrVerificationCode = string.Empty;

            string LStrAttributesData = string.Empty;
            //0:数据库服务器;1:端口;2:数据库名或服务名;3:登录用户;4:登录密码;5:其他参数
            List <string> LListStrDBProfile = new List <string>();

            try
            {
                IIntDBType           = 0;
                IStrDBConnectProfile = string.Empty;
                LStrVerificationCode = CreateVerificationCode(EncryptionAndDecryption.UMPKeyAndIVType.M104);

                LStrXmlFileName = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                //LStrXmlFileName =System.AppDomain.CurrentDomain.BaseDirectory;//测试用
                LStrXmlFileName = System.IO.Path.Combine(LStrXmlFileName, @"UMP.Server\Args01.UMP.xml");

                XmlDocument LXmlDocArgs01 = new XmlDocument();
                LXmlDocArgs01.Load(LStrXmlFileName);
                XmlNodeList LXmlNodeListDatabase = LXmlDocArgs01.SelectSingleNode("DatabaseParameters").ChildNodes;

                #region 读取数据库连接参数
                foreach (XmlNode LXmlNodeSingleDatabase in LXmlNodeListDatabase)
                {
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P03"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    if (LStrAttributesData != "1")
                    {
                        continue;
                    }

                    //数据库类型
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P02"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    IIntDBType         = int.Parse(LStrAttributesData);

                    //数据库服务器名或IP地址
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P04"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    LListStrDBProfile.Add(LStrAttributesData);

                    //数据库服务端口
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P05"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    LListStrDBProfile.Add(LStrAttributesData);

                    //数据库名或Service Name
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P06"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    LListStrDBProfile.Add(LStrAttributesData);

                    //登录用户
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P07"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    LListStrDBProfile.Add(LStrAttributesData);

                    //登录密码
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P08"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    LListStrDBProfile.Add(LStrAttributesData);

                    //其他参数
                    LStrAttributesData = LXmlNodeSingleDatabase.Attributes["P09"].Value;
                    LStrAttributesData = EncryptionAndDecryption.EncryptDecryptString(LStrAttributesData, LStrVerificationCode, EncryptionAndDecryption.UMPKeyAndIVType.M104);
                    LListStrDBProfile.Add(LStrAttributesData);

                    break;
                }
                #endregion

                #region 创建数据库连接字符串
                string LStrDBConnectProfile = string.Empty;

                if (IIntDBType == 2)
                {
                    IStrDBConnectProfile = string.Format("Data Source={0},{1};Initial Catalog={2};User Id={3};Password={4}", LListStrDBProfile[0], LListStrDBProfile[1], LListStrDBProfile[2], LListStrDBProfile[3], LListStrDBProfile[4]);
                    LStrDBConnectProfile = string.Format("Data Source={0},{1};Initial Catalog={2};User Id={3};Password={4}", LListStrDBProfile[0], LListStrDBProfile[1], LListStrDBProfile[2], LListStrDBProfile[3], "******");
                    LStrDBConnectProfile = "DataBase Type : MS SQL Server\n" + LStrDBConnectProfile;
                }
                if (IIntDBType == 3)
                {
                    IStrDBConnectProfile = string.Format("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0}) (PORT={1})))(CONNECT_DATA=(SERVICE_NAME= {2})));User Id={3}; Password={4}", LListStrDBProfile[0], LListStrDBProfile[1], LListStrDBProfile[2], LListStrDBProfile[3], LListStrDBProfile[4]);
                    LStrDBConnectProfile = string.Format("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0}) (PORT={1})))(CONNECT_DATA=(SERVICE_NAME= {2})));User Id={3}; Password={4}", LListStrDBProfile[0], LListStrDBProfile[1], LListStrDBProfile[2], LListStrDBProfile[3], "******");
                    LStrDBConnectProfile = "DataBase Type : Oracle\n" + LStrDBConnectProfile;
                }
                #endregion

                FileLog.WriteInfo("GetDatabaseConnectionProfile() ", "LStrDBConnectProfile=" + LStrDBConnectProfile);
            }
            catch (Exception ex)
            {
                IIntDBType           = 0;
                IStrDBConnectProfile = string.Empty;
                FileLog.WriteError("GetDatabaseConnectionProfile()", "Error :" + ex.ToString());
            }
        }
Beispiel #6
0
 /// <summary>
 /// 写日记 实例方法
 /// </summary>
 /// <param name="logLevel"></param>
 /// <param name="msg"></param>
 public void Log(LogLevel logLevel, string msg)
 {
     FileLog.WriteLog(logLevel, string.Empty, msg);
 }