Exemplo n.º 1
0
        static SynServerService()
        {
            try
            {
                LogProxy.InfoFormat(CURRENTAPPID, AppId);

                ApplicationName = SynServerConfig.ApplicationName;

                if (SynServerConfig.Port > 0)
                {
                    Port = SynServerConfig.Port;
                }

                if (SynServerConfig.ClearInterval > 0)
                {
                    ClearInterval = SynServerConfig.ClearInterval * 1000;
                }

                if (SynServerConfig.TimeLimit > 0)
                {
                    TimeLimit = SynServerConfig.TimeLimit;
                }
            }
            catch (Exception ex)
            {
                LogProxy.Fatal(ex, true);
            }
        }
Exemplo n.º 2
0
        static CacheService()
        {
            try
            {
                if (CacheCommConfig.ClearInterval > 0)
                {
                    CacheClearInterval = CacheCommConfig.ClearInterval * 1000;
                }

                if (CacheCommConfig.MinStayTime > 0)
                {
                    MinStayTime = CacheCommConfig.MinStayTime;
                }

                if (CacheCommConfig.WriteLockTimeout > 0)
                {
                    WriteLockTimeout = CacheCommConfig.WriteLockTimeout;
                }

                if (CacheCommConfig.FixLoggingInterval > 0)
                {
                    FixLoggingInterval = CacheCommConfig.FixLoggingInterval;
                }

                Thread t = new Thread(CacheClearThreadMethod);
                t.Start();
            }
            catch (Exception ex)
            {
                LogProxy.Fatal(ex, true);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 本方法用于自定义对象的 Id,如果不自定义,系统默认Id为Guid
        /// format 说明
        /// <para>{0} :当前时间</para>
        /// <para>{1} :唯一时间戳(近似当天总毫秒数,内部保证不重复),十六进制表示,总长7位,不足左补零</para>
        /// <para>{2} :同上,以十进制表示,总长8位,不足左补零</para>
        /// <para>{0}和{1}或者{0}和{2}结合可确保当前机器生成唯一 Id,不确保不同机器生成相同 Id,{1}和{2}不必同时引用</para>
        /// <para>{3} :app.config中配置的AppId(在分布式环境下,每个应用程序应该确保配置完全独立的AppId),与上述配合可生成全局唯一 Id</para>
        /// <para>{4}以后可以通过 GetOneId&lt;T&gt;(params string[] args) 传入值 </para>
        /// format示例:us-{0:yyMMdd}{1}-{3} 或 d{3}{0:yyMMdd}{1}
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="format"></param>
        public static void RegisterIdFormat <T>(string format)
        {
            if (string.IsNullOrEmpty(format))
            {
                LogProxy.Fatal(string.Format(IDFORMATSTRINGISNULL, typeof(T).FullName), true);
            }

            lock (LockIdFormatObj)
            {
                IdFormat[typeof(T).FullName] = format;
            }
        }
Exemplo n.º 4
0
 static StorageService()
 {
     try
     {
         XElement root = XElement.Load(ConfigDirectory);
         IEnumerable <XElement> storageContexts = root.Elements("StorageContext");
         LoadStorageContexts(storageContexts);
     }
     catch (Exception ex)
     {
         LogProxy.Fatal(ex, true);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 基本数据类型(decimal)特性,指示该属性在创建对应数据字段时的设置
        /// </summary>
        /// <param name="precision">精度(1-38之间)</param>
        /// <param name="decimalDigits">小数位数(0-38之间)且必须小于或等于精度</param>
        public DecimalDataTypeAttribute(int precision, int decimalDigits)
        {
            if (precision < 1 || precision > 38)
            {
                LogProxy.Fatal(PRECISIONERROR, true);
            }
            if (decimalDigits < 0 || decimalDigits > precision)
            {
                LogProxy.Fatal(DECIMALDIGITSERROR, true);
            }

            this.precision     = precision;
            this.decimaldigits = decimalDigits;
        }
Exemplo n.º 6
0
        static MappingService()
        {
            StorageService.Init();

            try
            {
                XElement root = XElement.Load(ConfigDirectory);

                _isAutoCreateTable = string.Equals(root.Attribute("autocreatetable") == null ? "false" : root.Attribute("autocreatetable").Value, "true", StringComparison.OrdinalIgnoreCase);

                IEnumerable <XElement> assemblies = root.Elements("Assembly");
                LoadAssemblies(assemblies);
            }
            catch (Exception ex)
            {
                LogProxy.Fatal(ex, true);
            }
        }
Exemplo n.º 7
0
        private static void ServicesInit()
        {
            int fails = 0;

            while (true)
            {
                int lastFails = fails;
                fails = 0;

                bool isInitialized = true;
                foreach (var v in Services.Values)
                {
                    if (v.IsInitialized)
                    {
                        continue;
                    }

                    LogProxy.Info(string.Format(SERVICEBEGININIT, v.ToString()));

                    ((ServiceBase)v).IsInitialized = v.Init();

                    if (v.IsInitialized)
                    {
                        LogProxy.Info(string.Format(SERVICEENDINIT, v.ToString()));
                    }
                    else
                    {
                        LogProxy.Info(string.Format(SERVICEINITFAIL, v.ToString()));
                        fails++;
                        isInitialized = false;
                    }
                }

                if (isInitialized)
                {
                    return;
                }

                if (lastFails <= fails)
                {
                    LogProxy.Fatal(SERVICESINITERROR, true);
                }
            }
        }
Exemplo n.º 8
0
        private static void ServicesLoad()
        {
            XElement root = XElement.Load(ConfigDirectory);
            IEnumerable <XElement> services = root.Elements("Service");

            string dllDir = Tools.GetAssemblyPath();

            Assembly driverAssembly, typeAssembly;
            Type     typeType, driverType;
            IService obj;

            foreach (var service in services)
            {
                string[] type   = service.Attribute("type").Value.Split(',');
                string[] driver = service.Attribute("driver").Value.Split(',');

                driverAssembly = Assembly.LoadFrom(string.Format("{0}{1}.dll", dllDir, driver[1].Trim(), ".dll"));
                typeAssembly   = Assembly.LoadFrom(string.Format("{0}{1}.dll", dllDir, type[1].Trim(), ".dll"));

                typeType   = typeAssembly.GetType(type[0].Trim());
                driverType = driverAssembly.GetType(driver[0].Trim());

                if (typeType == null || driverType == null)
                {
                    LogProxy.Fatal(string.Format(SERVICELOADFAIL, driver[0].Trim()), true);
                }

                obj = Activator.CreateInstance(driverType) as IService;

                if (obj == null)
                {
                    LogProxy.Fatal(string.Format(SERVICELOADFAIL, driver[0].Trim()), true);
                }

                LogProxy.Info(string.Format(SERVICELOADED, driver[0].Trim()));

                AddService(typeType, obj);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 预处理,启动内部服务,构筑运行环境,仅调用一次
        /// </summary>
        public static void Init()
        {
            if (InitStatus != InitStatus.None)
            {
                return;
            }

            lock (LockObj)
            {
                if (InitStatus != InitStatus.None)
                {
                    return;
                }

                InitStatus = InitStatus.Initing;
            }

            LogProxy.Info(SERVICESBEGININIT);

            try
            {
                ServicesLoad();

                ServicesInit();

                ServicesRun();
            }
            catch (Exception ex)
            {
                InitStatus = InitStatus.Fail;
                LogProxy.Fatal(ex, true);
            }

            InitStatus = InitStatus.Complete;

            LogProxy.Info(SERVICESENDINIT);
        }
Exemplo n.º 10
0
        private static void ServicesRun()
        {
            foreach (var v in Services.Values)
            {
                if (!v.IsInitialized)
                {
                    LogProxy.Fatal(string.Format(SERVICERUNFAILNOINIT, v.ToString()), true);
                    continue;
                }

                LogProxy.Info(string.Format(SERVICEBEGINRUN, v.ToString()));

                ((ServiceBase)v).IsRunned = v.Run();

                if (v.IsRunned)
                {
                    LogProxy.Info(string.Format(SERVICEENDRUN, v.ToString()));
                }
                else
                {
                    LogProxy.Fatal(string.Format(SERVICERUNFAIL, v.ToString()), true);
                }
            }
        }
Exemplo n.º 11
0
        static LockServerService()
        {
            try
            {
                ApplicationName = LockServerConfig.ApplicationName;

                if (LockServerConfig.Port > 0)
                {
                    Port = LockServerConfig.Port;
                }

                if (LockServerConfig.Expire > 0)
                {
                    LOCKEREXPIREINTERVAL = LockServerConfig.Expire;
                }

                if (LockServerConfig.TryInterval > 0)
                {
                    TRYINTERVAL = LockServerConfig.TryInterval * 1000;
                }

                if (LockServerConfig.Trys > 0)
                {
                    TRYCOUNT = LockServerConfig.Trys;
                }

                if (LockServerConfig.ClearInterval > 0)
                {
                    LOCKECLEARINTERVAL = LockServerConfig.ClearInterval * 1000;
                }
            }
            catch (Exception ex)
            {
                LogProxy.Fatal(ex, true);
            }
        }