Пример #1
0
        private void Init()
        {
            Local = new LocalStarClient();

            // 读取本地appsetting
            if (Server.IsNullOrEmpty())
            {
                var json = new JsonConfigProvider {
                    FileName = "appsettings.json"
                };
                json.LoadAll();

                Server = json["StarServer"];
            }

            if (Server.IsNullOrEmpty())
            {
                try
                {
                    var inf    = Local.GetInfo();
                    var server = inf?.Server;
                    if (!server.IsNullOrEmpty())
                    {
                        Server = server;
                        XTrace.WriteLine("星尘探测:{0}", server);
                    }
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);
                }
            }

            // 如果探测不到本地应用,则使用配置
            var set = Setting.Current;

            if (Server.IsNullOrEmpty())
            {
                Server = set.Server;
            }
            if (AppId.IsNullOrEmpty())
            {
                AppId = set.AppKey;
            }
            if (Secret.IsNullOrEmpty())
            {
                Secret = set.Secret;
            }

            if (AppId.IsNullOrEmpty())
            {
                AppId = AssemblyX.Entry.Name;
            }

            XTrace.WriteLine("星尘分布式服务 Server={0} AppId={1}", Server, AppId);
        }
Пример #2
0
        private void Init()
        {
            Local = new LocalStarClient();

            // 读取本地appsetting
            if (Server.IsNullOrEmpty() && File.Exists("appsettings.Development.json".GetFullPath()))
            {
                using var json = new JsonConfigProvider { FileName = "appsettings.Development.json" };
                json.LoadAll();

                Server = json["StarServer"];
            }
            if (Server.IsNullOrEmpty() && File.Exists("appsettings.json".GetFullPath()))
            {
                using var json = new JsonConfigProvider { FileName = "appsettings.json" };
                json.LoadAll();

                Server = json["StarServer"];
            }

            if (!Server.IsNullOrEmpty() && Local.Server.IsNullOrEmpty())
            {
                Local.Server = Server;
            }

            try
            {
                var inf    = Local.GetInfo();
                var server = inf?.Server;
                if (!server.IsNullOrEmpty())
                {
                    if (Server.IsNullOrEmpty())
                    {
                        Server = server;
                    }
                    XTrace.WriteLine("星尘探测:{0}", server);
                }
            }
            catch (Exception ex)
            {
                XTrace.Log.Error("星尘探测失败!{0}", ex.Message);
            }

            // 如果探测不到本地应用,则使用配置
            var set = StarSetting.Current;

            if (Server.IsNullOrEmpty())
            {
                Server = set.Server;
            }
            if (AppId.IsNullOrEmpty())
            {
                AppId = set.AppKey;
            }
            if (Secret.IsNullOrEmpty())
            {
                Secret = set.Secret;
            }

            try
            {
                var executing = AssemblyX.Create(Assembly.GetExecutingAssembly());
                var asm       = AssemblyX.Entry ?? executing;
                if (asm != null)
                {
                    if (AppId.IsNullOrEmpty())
                    {
                        AppId = asm.Name;
                    }
                    if (AppName.IsNullOrEmpty())
                    {
                        AppName = asm.Title;
                    }
                }

                ClientId = $"{NetHelper.MyIP()}@{Process.GetCurrentProcess().Id}";
            }
            catch { }

            XTrace.WriteLine("星尘分布式服务 Server={0} AppId={1}", Server, AppId);

            var ioc = ObjectContainer.Current;

            ioc.AddSingleton(this);
            ioc.AddSingleton(p => Tracer);
            ioc.AddSingleton(p => Config);
            ioc.AddSingleton(p => Service);
        }