/// <summary>
        /// Validates this instance.
        /// </summary>
        /// <exception cref="System.ArgumentException">
        /// InstanceName must be set
        /// or
        /// AppId must be set
        /// or
        /// AppId must be set
        /// or
        /// TenantId must be set
        /// or
        /// SubscriptionId must be set
        /// or
        /// SharedAccessPolicy must be set
        /// </exception>
        /// <exception cref="ArgumentException">InstanceName must be set and AppId must be set and AppId must be set and
        /// TenantId must be set and SubscriptionId must be set and SharedAccessPolicy must be set
        /// and ReceiverEntity OR SenderEntity must be set.</exception>
        /// <inheritdoc />
        public override void Validate()
        {
            if (InstanceName.IsNullOrEmpty())
            {
                throw new ArgumentException("InstanceName must be set");
            }

            if (AppId.IsNullOrEmpty())
            {
                throw new ArgumentException("AppId must be set");
            }

            if (AppSecret.IsNullOrEmpty())
            {
                throw new ArgumentException("AppSecret must be set");
            }

            if (TenantId.IsNullOrEmpty())
            {
                throw new ArgumentException("TenantId must be set");
            }

            if (SubscriptionId.IsNullOrEmpty())
            {
                throw new ArgumentException("SubscriptionId must be set");
            }

            if (SharedAccessPolicyName.IsNullOrEmpty())
            {
                throw new ArgumentException("SharedAccessPolicy must be set");
            }

            base.Validate();
        }
Esempio n. 2
0
        /// <summary>
        /// 默认构造函数
        /// </summary>
        /// <param name="userName"></param>
        public HeaderBarModel(string?userName)
        {
            var user = UserHelper.RetrieveUserByUserName(userName);

            if (user != null)
            {
                Icon        = user.Icon.Contains("://", StringComparison.OrdinalIgnoreCase) ? user.Icon : string.Format("{0}{1}", DictHelper.RetrieveIconFolderPath(), user.Icon);
                DisplayName = user.DisplayName;
                UserName    = user.UserName;
                AppId       = user.App;
                Css         = user.Css;
                ActiveCss   = string.IsNullOrEmpty(Css) ? Theme : Css;

                // 当前用户未设置应用程序时 使用当前配置 appId
                if (AppId.IsNullOrEmpty())
                {
                    AppId = BootstrapAppContext.AppId;
                }

                // 通过 AppCode 获取用户默认应用的标题
                Title  = DictHelper.RetrieveWebTitle(AppId);
                Footer = DictHelper.RetrieveWebFooter(AppId);

                // feat: https://gitee.com/LongbowEnterprise/dashboard/issues?id=I12VKZ
                // 后台系统网站图标跟随个人中心设置的默认应用站点的展示
                WebSiteIcon = DictHelper.RetrieveWebIcon(AppId);
                WebSiteLogo = DictHelper.RetrieveWebLogo(AppId);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 預設構造函数
        /// </summary>
        /// <param name="userName"></param>
        public HeaderBarModel(string?userName)
        {
            var user = UserHelper.RetrieveUserByUserName(userName);

            if (user != null)
            {
                Icon        = user.Icon.Contains("://", StringComparison.OrdinalIgnoreCase) ? user.Icon : string.Format("{0}{1}", DictHelper.RetrieveIconFolderPath(), user.Icon);
                DisplayName = user.DisplayName;
                UserName    = user.UserName;
                AppId       = user.App;
                Css         = user.Css;
                ActiveCss   = string.IsNullOrEmpty(Css) ? Theme : Css;

                // 當前用户未設置應用程式時 使用當前配置 appId
                if (AppId.IsNullOrEmpty())
                {
                    AppId = BootstrapAppContext.AppId;
                }

                // 通過 AppCode 獲取用户預設應用的標題
                Title  = DictHelper.RetrieveWebTitle(AppId);
                Footer = DictHelper.RetrieveWebFooter(AppId);

                // feat: https://gitee.com/LongbowEnterprise/dashboard/issues?id=I12VKZ
                // 後台系統網站圖標跟隨個人中心設置的預設應用站点的展示
                WebSiteIcon = DictHelper.RetrieveWebIcon(AppId);
                WebSiteLogo = DictHelper.RetrieveWebLogo(AppId);
            }
            EnableBlazor = DictHelper.RetrieveEnableBlazor();
        }
Esempio n. 4
0
        private void Valid()
        {
            if (Server.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Server));
            }
            if (AppId.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(AppId));
            }

            if (_client == null)
            {
                if (!AppId.IsNullOrEmpty())
                {
                    _tokenFilter = new TokenHttpFilter
                    {
                        UserName = AppId,
                        Password = Secret,
                    }
                }
                ;

                _client = new ApiHttpClient(Server)
                {
                    Filter = _tokenFilter
                };
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>指定服务端地址来实例化追踪器</summary>
        /// <param name="server"></param>
        public StarTracer(String server) : this()
        {
            var http = new ApiHttpClient(server)
            {
                Tracer = this
            };

            Client = http;

            var set = Setting.Current;

            if (!AppId.IsNullOrEmpty() && !set.Secret.IsNullOrEmpty())
            {
                http.Filter = new TokenHttpFilter {
                    UserName = AppId, Password = set.Secret
                }
            }
            ;
        }
Esempio n. 7
0
        private Boolean Valid()
        {
            //if (Server.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Server));
            //if (AppId.IsNullOrEmpty()) throw new ArgumentNullException(nameof(AppId));

            if (Server.IsNullOrEmpty() || AppId.IsNullOrEmpty())
            {
                return(false);
            }

            if (_client == null)
            {
                if (!AppId.IsNullOrEmpty())
                {
                    _tokenFilter = new TokenHttpFilter
                    {
                        UserName = AppId,
                        Password = Secret,
                    }
                }
                ;

                _client = new ApiHttpClient(Server)
                {
                    Filter = _tokenFilter
                };

                var set = StarSetting.Current;
                if (set.Debug)
                {
                    _client.Log = XTrace.Log;
                }
            }

            return(true);
        }
Esempio n. 8
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);
        }