/// <summary>
        /// 接收日志消息
        /// </summary>
        /// <param name="sender">事件源</param>
        /// <param name="e">消息参数</param>
        private static void m_messageReceiver_Received(object sender, MessageEventArgs e)
        {
            try
            {
                //写入日志服务
                var clmTemp = e.Message as CustomLogMessage;
                if (null != clmTemp)
                {
                    if (m_enableFileLog)
                    {
                        if (clmTemp.WriteLogType == WriteLogType.AllLog ||
                            clmTemp.WriteLogType == WriteLogType.FileDataBaseLog ||
                            clmTemp.WriteLogType == WriteLogType.FileLog)
                        {
                            SysLogHelper.LogMessage("Q:" + clmTemp.LogSource, clmTemp.LogMessage, clmTemp.LogLevel, WriteLogType.FileLog, clmTemp.LogAddition);
                        }
                    }

                    if (m_enableDataBaseLog)
                    {
                        if (clmTemp.WriteLogType == WriteLogType.AllLog ||
                            clmTemp.WriteLogType == WriteLogType.FileDataBaseLog ||
                            clmTemp.WriteLogType == WriteLogType.DataBaseLog)
                        {
                            SysLogHelper.LogMessage("Q:" + clmTemp.LogSource, clmTemp.LogMessage, clmTemp.LogLevel, WriteLogType.DataBaseLog, clmTemp.LogAddition);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SysLogHelper.LogMessage("LogMQConsumerHelper.messageReceiver_Received", ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     功能:静态构造函数,创建默认的缓存实例
        /// </summary>
        static CacheHelper()
        {
            try
            {
                //获取缓存策略类别
                string strCacheStrategyType = ConfigurationManager.AppSettings["CacheStrategyType"];
                if (!string.IsNullOrWhiteSpace(strCacheStrategyType))
                {
                    //获取缓存过期时间
                    string strCacheExpiration = ConfigurationManager.AppSettings["CacheExpiration"];
                    double value;
                    if (!string.IsNullOrWhiteSpace(strCacheExpiration))
                    {
                        double.TryParse(strCacheExpiration, out value);
                        s_cacheExpiration = TimeSpan.FromMinutes(value);
                    }

                    //创建缓存策略类实例
                    var redisConfigInfo = JsonConfigInfo.LoadFromFile("cache.json");
                    s_cacheStrategy = ComponentLoader.Load <ICacheStrategy>(redisConfigInfo);
                }
            }
            catch (Exception ex)
            {
                string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
                SysLogHelper.LogMessage("CacheHelper.Static", strMessage, LogLevel.Error);
            }
        }
        /// <summary>
        /// 功能:创建对象实例
        /// </summary>
        /// <typeparam name="T">实例的接口类型</typeparam>
        /// <param name="strClassFullName">实例的类全名称(命名空间.类型名,程序集)</param>
        /// <param name="ignoreCase">类全名是否区分大小写</param>
        /// <returns>对象实例</returns>
        public static T CreateTypeInstance <T>(string strClassFullName, bool ignoreCase = false)
        {
            if (!string.IsNullOrWhiteSpace(strClassFullName))
            {
                object objTemp = null;

                try
                {
                    //加载类型
                    Type typTemp = Type.GetType(strClassFullName, true, ignoreCase);

                    //根据类型创建实例
                    objTemp = Activator.CreateInstance(typTemp, true);
                    //objTemp = typTemp.Assembly.CreateInstance(strClassFullName, ignoreCase);
                    return((T)objTemp);
                }
                catch (Exception ex)
                {
                    string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
                    SysLogHelper.LogMessage("ObjectFactoryHelper.CreateTypeInstance", strMessage, LogLevel.Error);
                    return(default(T));
                }
            }
            else
            {
                return(default(T));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     功能:批量获取缓存
        /// </summary>
        /// <typeparam name="T">结果类型</typeparam>
        /// <param name="keys">缓存键数组</param>
        /// <returns>缓存对像集合</returns>
        public static List <T> Get <T>(IEnumerable <string> keys)
        {
            var lstReturn = new List <T>();

            if (null != s_cacheStrategy)
            {
                List <string> lstKeys = new List <string>();
                if (null != keys)
                {
                    keys.Any(key =>
                    {
                        string strKey = GlobalHelper.GetLowerString(key);
                        lstKeys.Add(strKey);
                        return(false);
                    });
                }

                try
                {
                    lstReturn = s_cacheStrategy.Get <T>(lstKeys);
                }
                catch (Exception ex)
                {
                    SysLogHelper.LogMessage("CacheHelper.Get", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                }
            }

            return(lstReturn);
        }
        /// <summary>
        /// 功能:创建对象实例
        /// </summary>
        /// <typeparam name="T">实例的接口类型</typeparam>
        /// <param name="strAssemblyName">类型所在程序集名称</param>
        /// <param name="strClassNameSpace">类型所在命名空间</param>
        /// <param name="strClassName">类型名称</param>
        /// <param name="ignoreCase">类名是否区分大小写</param>
        /// <returns>对象实例</returns>
        public static T CreateTypeInstance <T>(string strAssemblyName, string strClassNameSpace, string strClassName, bool ignoreCase = false)
        {
            if (string.IsNullOrWhiteSpace(strAssemblyName) || string.IsNullOrWhiteSpace(strClassNameSpace) || string.IsNullOrWhiteSpace(strClassName))
            {
                return(default(T));
            }
            else
            {
                object objTemp = null;

                try
                {
                    //命名空间.类型名
                    string fullName = strClassNameSpace + "." + strClassName;

                    //加载程序集,创建程序集里面的 命名空间.类型名 实例
                    objTemp = Assembly.Load(strAssemblyName).CreateInstance(fullName, ignoreCase);

                    //类型转换并返回
                    return((T)objTemp);
                }
                catch (Exception ex)
                {
                    string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
                    SysLogHelper.LogMessage("ObjectFactoryHelper.CreateTypeInstance", strMessage, LogLevel.Error);
                    return(default(T));
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            try
            {
                XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config"));
                //运行服务
                HostFactory.Run(cf =>
                {
                    cf.SetServiceName("Lx.Service.LogHost");
                    cf.SetDisplayName("Lx.Service.LogHost");
                    cf.SetDescription("日志服务");
                    cf.Service <TopshelfWrapper>(sv =>
                    {
                        sv.ConstructUsing(b => new TopshelfWrapper());
                        sv.WhenStarted(o => o.Start());
                        sv.WhenStopped(o => o.Stop());
                    });

                    cf.RunAsLocalSystem();
                    cf.StartAutomatically();
                    cf.EnablePauseAndContinue();
                });
            }
            catch (Exception ex)
            {
                string strMessage = $"服务启动失败,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
                SysLogHelper.LogMessage("LogHost.Main", strMessage);
            }

            Console.ReadLine();
        }
        /// <summary>
        /// 功能:测试日志
        /// </summary>
        public static FeedBackResponse <string> TestLog()
        {
            FeedBackResponse <string> fbrReturn = new FeedBackResponse <string>();

            SysLogHelper.LogMessage("LogServiceHelper.TestLog", "Test log data!", LogLevel.Information);
            SysLogHelper.LogServiceMessage("LogServiceHelper.TestLog", "Test log data!", LogLevel.Information);
            fbrReturn.ResultData = "ok";

            return(fbrReturn);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            try
            {
                XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config"));
                //获取配置的服务名称列表
                List <string> lstConfigServices = ServiceHelper.GetConfigServices();
                //启动服务
                if (null != lstConfigServices && lstConfigServices.Count > 0)
                {
                    //获取Windows服务信息
                    JsonConfigInfo winServiceInfo = ConfigHelper.LoadFromFile("WinServiceInfo.json");

                    //获取待启动的Windows服务的名称
                    string strServiceInfo = lstConfigServices[0];
                    int    intPosition    = strServiceInfo.LastIndexOf(".");
                    string strServiceName = strServiceInfo.Substring(intPosition + 1);

                    //获取服务配置
                    JObject joServiceInfo = winServiceInfo.GetValue <JObject>(strServiceName);

                    //运行服务
                    HostFactory.Run(cf =>
                    {
                        cf.SetServiceName(joServiceInfo["ServiceName"].Value <string>());
                        cf.SetDisplayName(joServiceInfo["DisplayName"].Value <string>());
                        cf.SetDescription(joServiceInfo["Description"].Value <string>());

                        cf.Service <TopshelfWrapper>(sv =>
                        {
                            sv.ConstructUsing(b => new TopshelfWrapper());
                            sv.WhenStarted(o => o.Start());
                            sv.WhenStopped(o => o.Stop());
                        });

                        cf.RunAsLocalSystem();
                        cf.StartAutomatically();
                        cf.EnablePauseAndContinue();
                    });
                }
                else
                {
                    Console.WriteLine("没有配置服务,无服务可启动!");
                }
            }
            catch (Exception ex)
            {
                string strMessage = $"服务启动失败,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
                SysLogHelper.LogMessage("Lx.Service.WinServiceHost.Main", strMessage);
            }

            Console.ReadLine();
        }
 static ObjectFactoryHelper()
 {
     try
     {
         m_dictObject             = new Dictionary <int, object>();
         m_queryImplementAssembly = Assembly.Load(m_queryImplementAssemblyName);
     }
     catch (Exception ex)
     {
         string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
         SysLogHelper.LogMessage("ObjectFactoryHelper.Static", strMessage, LogLevel.Error);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        ///     功能:获取计数器的当前值
        /// </summary>
        /// <param name="key">计数器名称</param>
        /// <returns>当前值</returns>
        public static async Task <double?> GetDoubleCounterAsync(string key)
        {
            string strKey = GlobalHelper.GetLowerString(key);

            try
            {
                return(await s_cacheStrategy.GetDoubleCounterAsync(strKey));
            }
            catch (Exception ex)
            {
                SysLogHelper.LogMessage("CacheHelper.GetDoubleCounterAsync", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                return(null);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     功能:初始化计数器
        /// </summary>
        /// <param name="key">计数器名称</param>
        /// <param name="value">初始值</param>
        /// <returns>是否设置成功</returns>
        public static async Task <bool> InitCounterAsync(string key, double value)
        {
            string strKey = GlobalHelper.GetLowerString(key);

            try
            {
                return(await s_cacheStrategy.InitCounterAsync(strKey, value));
            }
            catch (Exception ex)
            {
                SysLogHelper.LogMessage("CacheHelper.InitCounterAsync_double", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                return(false);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     功能:初始化计数器
        /// </summary>
        /// <param name="key">计数器名称</param>
        /// <param name="value">初始值</param>
        /// <returns>是否设置成功</returns>
        public static bool InitCounter(string key, long value)
        {
            string strKey = GlobalHelper.GetLowerString(key);

            try
            {
                return(s_cacheStrategy.InitCounter(strKey, value));
            }
            catch (Exception ex)
            {
                SysLogHelper.LogMessage("CacheHelper.InitCounter", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                return(false);
            }
        }
 static LogServiceHelper()
 {
     try
     {
         JsonConfigInfo lsConfigInfo = ConfigHelper.LoadFromFile("LogService.json");
         m_enableFileLog     = lsConfigInfo.GetValue <bool>("EnableFileLog");
         m_enableDataBaseLog = lsConfigInfo.GetValue <bool>("EnableDataBaseLog");
     }
     catch (Exception ex)
     {
         string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
         SysLogHelper.LogMessage("LogServiceHelper.static", strMessage);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        ///     功能:获取计数器的当前值
        /// </summary>
        /// <param name="key">计数器名称</param>
        /// <returns>当前值</returns>
        public static long?GetCounter(string key)
        {
            string strKey = GlobalHelper.GetLowerString(key);

            try
            {
                return(s_cacheStrategy.GetCounter(strKey));
            }
            catch (Exception ex)
            {
                SysLogHelper.LogMessage("CacheHelper.GetCounter", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                return(null);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     功能:设置永久缓存项(服务器上key存在就替换,不存在就添加)
        /// </summary>
        /// <param name="key">缓存键值</param>
        /// <param name="value">缓存值</param>
        /// <returns>是否设置成功</returns>
        public static bool Set(string key, object value)
        {
            bool   blnSuccess = false;
            string strKey     = GlobalHelper.GetLowerString(key);

            try
            {
                blnSuccess = s_cacheStrategy.Set(strKey, value, s_cacheExpiration);
            }
            catch (Exception ex)
            {
                SysLogHelper.LogMessage("CacheHelper.Set", ex.Message, LogLevel.Error, WriteLogType.FileLog);
            }
            return(blnSuccess);
        }
 /// <summary>
 /// 功能:初始化
 /// </summary>
 public static void Initalize()
 {
     try
     {
         m_messageReceiver           = MessageQueueHelper.GetMessageQueueFromPool().GetMessageReceiver(QueueName.LxLogQueue.ToString(), "");
         m_messageReceiver.Received += m_messageReceiver_Received;
         m_messageReceiver.Start();
         Console.WriteLine("日志消息队列消费者已启动!");
     }
     catch (Exception ex)
     {
         string strErrorMessage = SysLogHelper.GetErrorLogInfo(ex, true);
         SysLogHelper.LogMessage("LogMQConsumerHelper.Static", strErrorMessage);
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 功能:初始化
 /// </summary>
 public static void Initalize()
 {
     try
     {
         m_messageReceiver           = MessageQueueHelper.GetMessageQueueFromPool().GetMessageReceiver(QueueName.AutoPayQueue.ToString(), "");
         m_messageReceiver.Received += m_messageReceiver_Received;
         m_messageReceiver.Start();
         Console.WriteLine("订单服务已启动!");
     }
     catch (Exception ex)
     {
         string strMessage = $"初始化,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
         SysLogHelper.LogMessage("Lx.Service.Initalize", strMessage);
     }
 }
        /// <summary>
        /// 功能:写日志到数据库
        /// </summary>
        /// <param name="logLevel">日志级别(不同的级别的日志会存入对应的日志文件)</param>
        /// <param name="logSource">日志的来源</param>
        /// <param name="logValue">需记录的日志值</param>
        /// <param name="logAddition">日志附加信息</param>
        public static FeedBackResponse <string> WriteDataBaseLog(LogLevel logLevel, string logSource, string logValue, string logAddition)
        {
            FeedBackResponse <string> fbrReturn = new FeedBackResponse <string>();

            if (m_enableDataBaseLog)
            {
                SysLogHelper.LogMessage(logSource, logValue, logLevel, WriteLogType.DataBaseLog, logAddition);
            }
            else
            {
                fbrReturn.Message = "记录数据日志开关关闭.";
            }

            return(fbrReturn);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 功能:停止服务
 /// </summary>
 public void Stop()
 {
     try
     {
         //关闭服务
         OrderMQConsumerHelper.Release();
         //调用垃圾回收
         GC.Collect();
         GC.WaitForPendingFinalizers();
     }
     catch (Exception ex)
     {
         string strMessage = $"服务停止失败,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
         SysLogHelper.LogMessage("Lx.Service.Order", strMessage);
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// 接收代付订单
        /// </summary>
        /// <param name="sender">事件源</param>
        /// <param name="e">消息参数</param>
        private static void m_messageReceiver_Received(object sender, MessageEventArgs e)
        {
            var orderModel = e.Message as OrderMqMessage;

            try
            {
                if (null != orderModel)
                {
                    PayOrderService.AddPayOrder(orderModel);
                }
            }
            catch (Exception ex)
            {
                string strMessage = $"接收代付订单失败,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
                SysLogHelper.LogMessage("Lx.Service.m_messageReceiver_Received", strMessage);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 功能:启动服务
        /// </summary>
        public void Start()
        {
            try
            {
                //获取配置的服务名称列表
                List <string> lstConfigServices = ServiceHelper.GetConfigServices();

                //启动服务主机
                lstConfigServices.ForEach(cs =>
                {
                    //获取待启动的Windows服务的名称
                    int intPosition       = cs.LastIndexOf(".");
                    string strServiceName = cs.Substring(intPosition + 1);
                    //日志服务
                    if (cs.IndexOf("LogService", StringComparison.InvariantCultureIgnoreCase) > 0)
                    {
                        m_logServiceHost = new ServiceHost <LogService>();
                        m_logServiceHost.EnableMetadataExchange = true;
                        m_logServiceHost.Open();
                        Console.WriteLine("日志服务已经启动,如果要退出,请输入exit,不要直接关闭");
                    }

                    //用户服务
                    if (cs.IndexOf("UserService", StringComparison.InvariantCultureIgnoreCase) > 0)
                    {
                        m_userServiceHost = new ServiceHost <UserService>();
                        m_userServiceHost.EnableMetadataExchange = true;
                        m_userServiceHost.Open();
                        Console.WriteLine("用户服务已经启动,如果要退出,请输入exit,不要直接关闭");
                    }
                    //订单服务
                    if (cs.IndexOf("OrderService", StringComparison.InvariantCultureIgnoreCase) > 0)
                    {
                        m_OrderServiceHost = new ServiceHost <OrderService>();
                        m_OrderServiceHost.EnableMetadataExchange = true;
                        m_OrderServiceHost.Open();
                        Console.WriteLine("订单服务已经启动,如果要退出,请输入exit,不要直接关闭");
                    }
                });
            }
            catch (Exception ex)
            {
                string strMessage = $"服务启动失败,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
                SysLogHelper.LogMessage("Lx.Service.WinServiceHost.Start", strMessage);
            }
        }
        /// <summary>
        /// 功能:创建对象实例
        /// </summary>
        /// <typeparam name="T">实例的接口类型</typeparam>
        /// <param name="strClassName">实例的类名称</param>
        /// <param name="strClassNameSpace">实例的类所在的空间名称</param>
        /// <param name="blnCreateNew">是否每次创建新对象</param>
        /// <returns>对象实例</returns>
        public static T CreateInstance <T>(string strClassName, string strClassNameSpace, bool blnCreateNew = false)
        {
            if (!string.IsNullOrWhiteSpace(strClassName))
            {
                object objTemp         = null;
                string strInstanceName = "";
                if (string.IsNullOrWhiteSpace(strClassNameSpace))
                {
                    strInstanceName = m_queryImplementAssemblyName + "." + strClassName;
                }
                else
                {
                    strInstanceName = m_queryImplementAssemblyName + "." + strClassNameSpace + "." + strClassName;
                }

                try
                {
                    if (blnCreateNew)
                    {
                        objTemp = m_queryImplementAssembly.CreateInstance(strInstanceName);
                    }
                    else
                    {
                        int intKey = strInstanceName.GetHashCode();
                        if (!m_dictObject.TryGetValue(intKey, out objTemp))
                        {
                            objTemp = m_queryImplementAssembly.CreateInstance(strInstanceName);
                            m_dictObject[intKey] = objTemp;
                        }
                    }
                }
                catch (Exception ex)
                {
                    string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
                    SysLogHelper.LogMessage("ObjectFactoryHelper.CreateInstance", strMessage, LogLevel.Error);
                    return(default(T));
                }

                return((T)objTemp);
            }
            else
            {
                return(default(T));
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        ///     功能:移除所有缓存项
        /// </summary>
        /// <returns>是否成功</returns>
        public static bool RemoveAll()
        {
            bool blnSuccess = false;

            if (null != s_cacheStrategy)
            {
                try
                {
                    blnSuccess = s_cacheStrategy.RemoveAll();
                }
                catch (Exception ex)
                {
                    SysLogHelper.LogMessage("CacheHelper.RemoveAll", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                }
            }

            return(blnSuccess);
        }
Ejemplo n.º 24
0
        /// <summary>
        ///     功能:获取缓存项的值
        /// </summary>
        /// <typeparam name="T">缓存项的类型</typeparam>
        /// <param name="key">缓存项的键值</param>
        /// <returns>获取到的缓存项</returns>
        public static T Get <T>(string key)
        {
            object obj = default(T);

            if (null != s_cacheStrategy)
            {
                string strKey = GlobalHelper.GetLowerString(key);
                try
                {
                    obj = s_cacheStrategy.Get <T>(strKey);
                }
                catch (Exception ex)
                {
                    SysLogHelper.LogMessage("CacheHelper.Get", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                }
            }

            return((T)obj);
        }
        static DBDataSourceHelper()
        {
            try
            {
                //获取数据源类型
                string strDBType = ConfigurationManager.AppSettings["DBType"];
                if (string.IsNullOrWhiteSpace(strDBType))
                {
                    strDBType = "MySql";
                }

                s_dbDataSource = ObjectFactoryHelper.CreateInstance <IDBDataSource>(strDBType + "DBDataSource", "DBDataSource", true);
            }
            catch (Exception ex)
            {
                string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
                SysLogHelper.LogMessage("DataSourceHelper.Static", strMessage, LogLevel.Error);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     功能:设置缓存项(服务器上key存在就替换,不存在就添加)
        /// </summary>
        /// <param name="key">缓存键值</param>
        /// <param name="value">缓存值</param>
        /// <param name="numOfMinutes">缓存过期时间(单位:分)</param>
        /// <returns>是否设置成功</returns>
        public static async Task <bool> SetAsync(string key, object value, double numOfMinutes)
        {
            bool blnSuccess = false;

            if (null != s_cacheStrategy)
            {
                string strKey = GlobalHelper.GetLowerString(key);
                try
                {
                    blnSuccess = await s_cacheStrategy.SetAsync(strKey, value, TimeSpan.FromMinutes(numOfMinutes));
                }
                catch (Exception ex)
                {
                    SysLogHelper.LogMessage("CacheHelper.SetAsync", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                }
            }

            return(blnSuccess);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 功能:停止服务
        /// </summary>
        public void Stop()
        {
            try
            {
                //关闭服务
                if (null != m_logServiceHost)
                {
                    if (m_logServiceHost.State != CommunicationState.Closed)
                    {
                        m_logServiceHost.Close();
                    }

                    m_logServiceHost = null;
                }

                if (null != m_userServiceHost)
                {
                    if (m_userServiceHost.State != CommunicationState.Closed)
                    {
                        m_userServiceHost.Close();
                    }

                    m_userServiceHost = null;
                }

                if (null != m_OrderServiceHost)
                {
                    if (m_OrderServiceHost.State != CommunicationState.Closed)
                    {
                        m_OrderServiceHost.Close();
                    }
                    m_OrderServiceHost = null;
                }
                //调用垃圾回收
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception ex)
            {
                string strMessage = $"服务启动失败,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
                SysLogHelper.LogMessage("Lx.Service.WinServiceHost.Stop", strMessage);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        ///     功能:设置永久缓存项(服务器上key存在就替换,不存在就添加)
        /// </summary>
        /// <param name="key">缓存键值</param>
        /// <param name="value">缓存值</param>
        /// <returns>是否设置成功</returns>
        public static async Task <bool> AddAsync(string key, object value)
        {
            bool blnSuccess = false;

            if (null != s_cacheStrategy)
            {
                string strKey = GlobalHelper.GetLowerString(key);

                try
                {
                    blnSuccess = await s_cacheStrategy.AddAsync(strKey, value, s_cacheExpiration);
                }
                catch (Exception ex)
                {
                    SysLogHelper.LogMessage("CacheHelper.AddAsync", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                }
            }

            return(blnSuccess);
        }
Ejemplo n.º 29
0
        /// <summary>
        ///     功能:移除缓存项(服务器上Key存在就移除)
        /// </summary>
        /// <param name="key">缓存项的键值</param>
        /// <returns>是否移除成功</returns>
        public static bool Remove(string key)
        {
            bool blnSuccess = false;

            if (null != s_cacheStrategy)
            {
                string strKey = GlobalHelper.GetLowerString(key);
                try
                {
                    var o = s_cacheStrategy.Get <object>(strKey);
                    blnSuccess = (o == null ? true : s_cacheStrategy.Remove(strKey));
                }
                catch (Exception ex)
                {
                    SysLogHelper.LogMessage("CacheHelper.Remove", ex.Message, LogLevel.Error, WriteLogType.FileLog);
                }
            }

            return(blnSuccess);
        }
Ejemplo n.º 30
0
        /// <summary>
        ///     功能:加载组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configInfo"></param>
        /// <returns></returns>
        public static T Load <T>(JsonConfigInfo configInfo)
        {
            var componentTypeName = configInfo.GetString("_type");

            if (componentTypeName == null)
            {
                var message = $"无法加载组件:{typeof(T).FullName}配置文件中缺少 _type 属性";
                SysLogHelper.LogMessage("CacheHelper.Load", message, LogLevel.Error, WriteLogType.FileLog);
                throw new ArgumentOutOfRangeException(message);
            }
            var classNameArray = componentTypeName.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);

            if (classNameArray.Length == 1)
            {
                var message = $"无法加载组件:{typeof(T).FullName}配置文件中缺少 _type 属性,缺少命名空间:{componentTypeName}";
                SysLogHelper.LogMessage("CacheHelper.Load", message, LogLevel.Error, WriteLogType.FileLog);
                throw new ArgumentOutOfRangeException(message);
            }
            var @namespace = string.Join(".", classNameArray.Take(classNameArray.Length - 1));
            var className  = classNameArray.Last();
            var target     = ObjectFactoryHelper.CreateInstance <T>(className, @namespace, true);

            if (target == null)
            {
                var componentType = Type.GetType(componentTypeName);
                target = (T)Activator.CreateInstance(componentType);
            }
            JsonConvert.PopulateObject(configInfo.Itemes.ToString(), target);
            var component = target as IComponent;

            if (component != null)
            {
                component.Init();
            }
            return(target);
        }