private void FinalizeRequestAudit(ResourceExecutedContext context, TimeSpan duration) { var ms = (int)duration.TotalMilliseconds; var result = "none"; if (context.Result is ObjectResult objectResult) { result = JsonConvert.SerializeObject(objectResult.Value); } var epb = new EntityPatchBag <LogsAuditEntity> { Id = context.HttpContext.TraceIdentifier, Model = new LogsAuditEntity { Result = result, ResponseDuration = ms }, PropertiesToUpdate = new Dictionary <string, bool> { { "result", true }, { "responseDuration", true } } }; _logger.UpdateAuditLog(epb); }
public async Task TakeCareOf(EntityPatchBag <T> eub, T existing) { var updatablePrimitiveProperties = EntityTypeHelper.GetUpdatablePrimitveProperties <T>( EntityTypeHelper.GetPropertiesNames(eub.PropertiesToUpdate)); foreach (var upp in updatablePrimitiveProperties) { upp.SetValue(existing, upp.GetValue(eub.Model)); } var updateableEntityProperties = EntityTypeHelper.GetUpdateableEntityProperties <T>( EntityTypeHelper.GetPropertiesNames(eub.PropertiesToUpdate)); foreach (var uep in updateableEntityProperties) { var e = (IEntity)uep.GetValue(eub.Model); if (e == null || string.IsNullOrEmpty(e.Id)) { uep.SetValue(existing, null); } else { var propRepo = _dataLayer.Repository(uep.PropertyType); var e2 = await propRepo.GetOneEntity(e.Id); uep.SetValue(existing, e2); } } }
public void OnApiException(ExceptionContext context) { var method = context.HttpContext.Request.Method; if (method == "GET" || method == "OPTIONS") { return; } var epb = new EntityPatchBag <LogsAuditEntity> { Id = context.HttpContext.TraceIdentifier, Model = new LogsAuditEntity { Data = context.Exception.ToString() }, PropertiesToUpdate = new Dictionary <string, bool> { { "data", true } } }; // // if (context.Exception is KnownException knownExc) // { // dr.StatusCode = knownExc.Code != 0 ? knownExc.Code : 500; // } // else // { // Console.WriteLine("exception: " + context.Exception?.Message + " " + typeof(KnownException).Name); // dr.StatusCode = 500; // } _logger.UpdateAuditLog(epb); }
public static EntityPatchBag <T> GetEpbFor(T current, T existing) { var epb = new EntityPatchBag <T> { Id = existing.Id, Model = current, PropertiesToUpdate = new Dictionary <string, bool>() }; var updateablePrimitiveProperties = EntityTypeHelper.GetUpdatablePrimitveProperties <T>(); foreach (var upp in updateablePrimitiveProperties) { var crtValue = upp.GetValue(current); if (crtValue == null && upp.GetValue(existing) != null || crtValue != null && !crtValue.Equals(upp.GetValue(existing))) { epb.PropertiesToUpdate.Add(upp.Name, true); } } var updateableEntityProperties = EntityTypeHelper.GetUpdateableEntityProperties <T>(); foreach (var uep in updateableEntityProperties) { var crtValue = (IEntity)uep.GetValue(current); var existingValue = (IEntity)uep.GetValue(existing); if (string.IsNullOrEmpty(crtValue?.Id)) { crtValue = null; } if (crtValue == null && existingValue == null) { continue; } if (crtValue == null || existingValue == null || !string.IsNullOrEmpty(crtValue.Id) && crtValue.Id != existingValue.Id) { epb.PropertiesToUpdate.Add(uep.Name, true); } } return(epb); }
public virtual async Task <T> Patch(EntityPatchBag <T> eub) { var existing = await GetOne(eub.Id); if (!eub.HasAnything) { return(existing); } await new EntityUpdateHelper <T>(_dataLayer, _dbSet).TakeCareOf(eub, existing); existing.Updated = DateTime.Now; if (!SkipSaving) { await _dataLayer.SaveChangesAsync(); } return(existing); }
public void OnUiException(ExceptionContext context) { Console.WriteLine("OnUiException"); var epb = new EntityPatchBag <LogsUiEntity> { Id = context.HttpContext.TraceIdentifier, Model = new LogsUiEntity { OldVersion = "!!Exception occured!!!", NewVersion = context.Exception.ToString() }, PropertiesToUpdate = new Dictionary <string, bool> { { "OldVersion", true }, { "NewVersion", true } } }; _logger.UpdateUiLog(epb); }
public void UpdateStoredLog(EntityPatchBag <T> epbae) { _logQueue.Enqueue(epbae); _semaphore.Release(); }
public void UpdateAuditLog(EntityPatchBag <LogsAuditEntity> epbae) { _auditManager.UpdateStoredLog(epbae); }
public void UpdateUiLog(EntityPatchBag <LogsUiEntity> epbule) { _uiLogManager.UpdateStoredLog(epbule); }
public override Task <SettingEntity> Patch(EntityPatchBag <SettingEntity> eub) { InvalidateCache(); return(base.Patch(eub)); }