/// <summary> 订阅配置 </summary>
        /// <param name="modules">模块</param>
        /// <param name="env">环境模式</param>
        /// <returns></returns>
        public async Task Subscript(string[] modules, string env)
        {
            if (string.IsNullOrWhiteSpace(Code))
            {
                return;
            }
            Logger.LogInformation($"hub:{Context.ConnectionId} Subscript {env} - {string.Join(',', modules)}");
            foreach (var mode in modules)
            {
                await Groups.AddToGroupAsync(Context.ConnectionId, $"{Code}_{mode}_{env}");
            }

            if (ProjectId.IsNotNullOrEmpty())
            {
                using var scope = CurrentIocManager.BeginLifetimeScope();
                var contract = scope.Resolve <IConfigContract>();
                var dict     = new Dictionary <string, object>();
                foreach (var module in modules)
                {
                    var config = await contract.GetAsync(ProjectId, module, env);

                    dict.Add(module, config);
                }

                await Clients.Caller.SendAsync("UPDATE", dict);
            }
        }
Exemple #2
0
        /// <summary> 通知配置更新 </summary>
        /// <param name="module"></param>
        /// <param name="env"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        private void NotifyConfig(string module, string env, object config)
        {
            Task.Factory.StartNew <Task>(async() =>
            {
                using var scope = CurrentIocManager.BeginLifetimeScope();
                var hub         = scope.Resolve <IHubContext <ConfigHub> >();
                if (string.IsNullOrWhiteSpace(env))
                {
                    var contract = scope.Resolve <IConfigContract>();
                    //default
                    var existsEnvs = (await contract.GetEnvsAsync(Project.Id, module)).ToList();
                    foreach (ConfigEnv configEnv in Enum.GetValues(typeof(ConfigEnv)))
                    {
                        var item = configEnv.ToString().ToLower();
                        if (existsEnvs.Contains(item))
                        {
                            continue;
                        }

                        await hub.UpdateAsync(Project.Code, module, item, config);
                    }
                }
                else
                {
                    await hub.UpdateAsync(Project.Code, module, env, config);
                }
            });
        }
Exemple #3
0
        /// <summary> 根据编码获取项目 </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static ProjectDto GetProjectByToken(this HttpContext context)
        {
            var ticket = context.GetTicket();

            if (ticket?.ProjectId == null)
            {
                return(null);
            }
            using var scope = CurrentIocManager.BeginLifetimeScope();
            var contract = scope.Resolve <IProjectContract>();

            return(contract.DetailAsync(ticket.ProjectId).SyncRun());
        }
Exemple #4
0
        /// <summary> 根据编码获取项目 </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static ProjectDto GetProjectByCode(this HttpContext context)
        {
            var code = context.GetProjectCode();

            if (string.IsNullOrWhiteSpace(code))
            {
                return(null);
            }
            using var scope = CurrentIocManager.BeginLifetimeScope();
            var contract = scope.Resolve <IProjectContract>();

            return(contract.DetailByCodeAsync(code).SyncRun());
        }