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()); } }
/// <summary> /// 設定組態異動成功執行的結果, 後續產生異動紀錄。若組態異動失敗,不需呼叫此方法。 /// if create, then pass empty string/null to oldValue /// </summary> /// <param name="oldValue">序列化之舊資料。若為新增資料, 傳空值或空字串。</param> /// <param name="newValue">序列化之新資料</param> /// <param name="userId"></param> /// <param name="oid"></param> /// <param name="ssid"></param> /// <param name="state">特殊狀態(方便查詢)</param> public void SetChangedResult(string oldValue, string newValue, string userId, string userName, string oid, string ssid = null, TRoadStateDefinitions state = TRoadStateDefinitions.Undefined, string sercurityServerName = null) { var result = new ChangedResult(); result.OldValue = oldValue; result.NewValue = newValue; result.UserId = userId; result.UserName = userName; result.OrgUnitOid = oid; result.SecurityServerId = ssid; result.SecurityServerName = sercurityServerName; result.IsNewValue = string.IsNullOrWhiteSpace(oldValue); result.State = state; this.Result = result; }
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); }