public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next)
        {
            if (request is IGlobalConfigChange)
            {
                var changeRequest = (IGlobalConfigChange)request;

                // Context property injection
                var configContext = (GlobalConfigChangeContext)_serviceProvider.GetService(typeof(GlobalConfigChangeContext));
                changeRequest.ConfigContext = configContext;

                var response = await next();

                bool hasChanged = changeRequest.ConfigContext.Result != null;
                if (hasChanged)
                {
                    ChangeIntent  intent  = changeRequest.ConfigContext.Intent;
                    ChangedResult changed = changeRequest.ConfigContext.Result;

                    if (intent != null && changed != null && !IsBySsSystem(changed.UserId))
                    {
                        var dbContext = (IApplicationDbContext)_serviceProvider.GetService(typeof(IApplicationDbContext));

                        GlobalConfigChangeLog log = BuildLog(intent, changed);
                        dbContext.GlobalConfigChangeLogs.Add(log);
                        await dbContext.SaveChangesAsync(cancellationToken);
                    }
                }

                return(response);
            }
            else
            {
                return(await next());
            }
        }
예제 #2
0
        /// <summary>
        /// 設定組態異動描述
        /// </summary>
        /// <param name="type"></param>
        /// <param name="description"></param>
        /// <param name="refId"></param>
        public void SetChangeIntent(ConfigCategory type, string description, string refId)
        {
            var intent = new ChangeIntent
            {
                ConfigCategory    = type,
                ChangeDescription = description,
                ReferenceId       = refId
            };

            this.Intent = intent;
        }
        private GlobalConfigChangeLog BuildLog(ChangeIntent intent, ChangedResult result)
        {
            var log = new GlobalConfigChangeLog();

            log.ReferenceId      = intent.ReferenceId;
            log.ConfigCategory   = intent.ConfigCategory;
            log.Description      = intent.ChangeDescription;
            log.UserId           = result.UserId;
            log.UserName         = result.UserName;
            log.GcaOid           = result.OrgUnitOid;
            log.SecurityServerId = result.SecurityServerId;
            log.LogTime          = DateTime.Now;
            log.StateChange      = result.State;

            return(log);
        }