public async Task <TEntity> FindAsync( CancellationToken cancellationToken, params object[] keyValues) { if (!this.UseForAnonymousUser) { SecurityManager.ThrowIfUserContextNull(); OperationAccess operationAccessAsync = await this.CreateOperationAccessAsync(); if (!this.OperationAccess.CanView) { throw new OperationAccessException(this.ViewKey); } } TEntity entity1 = await this.FindEntityAsync(cancellationToken, keyValues); TEntity entity2 = entity1; entity1 = default(TEntity); if ((object)entity2 is IActivityLoggable) { IActivityLoggable entityLog = (IActivityLoggable)(object)entity2; if (entityLog.ActionsToLog == ActionLog.All || (entityLog.ActionsToLog & ActionLog.Read) == ActionLog.Read) { OMF.Common.ActivityLog.ActivityLog actLog = ActivityLogManager.CreateActivityLog(entityLog); actLog.Action = 1; ActivityLogManager.Save(actLog); actLog = (OMF.Common.ActivityLog.ActivityLog)null; } entityLog = (IActivityLoggable)null; } return(entity2); }
public static void SaveActivityLogForLogOffAction(UserContext userContext) { ActivityLog.ActivityLog activityLog1 = ActivityLogManager.CreateActivityLog(); activityLog1.ForceLog = true; activityLog1.EntityName = "خروج"; activityLog1.EntityID = userContext.Token; activityLog1.Action = 7; activityLog1.UserID = userContext.UserId; activityLog1.UserName = userContext.UserName; activityLog1.ClientIP = userContext.ClientIP; activityLog1.VisibleForEndUser = true; ActivityLog.ActivityLog activityLog2 = activityLog1; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userContext.UserName, UserToken = userContext.Token, RecordDateTime = DateTime.Now, Action = ActionType.Logout.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog2.LogData = activityLogData; ActivityLogManager.Save(activityLog1); }
public static void SaveActivityLogForChangePassAction(int userId, string userName) { ActivityLog.ActivityLog activityLog1 = ActivityLogManager.CreateActivityLog(); activityLog1.ForceLog = true; activityLog1.UserName = userName; activityLog1.EntityName = "تغییر رمز عبور"; activityLog1.VisibleForEndUser = true; activityLog1.EntityID = userId.ToString(); activityLog1.Action = 9; ActivityLog.ActivityLog activityLog2 = activityLog1; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog1.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.ChangePassword.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog2.LogData = activityLogData; ActivityLogManager.Save(activityLog1); }
public static void SaveActivityLogForLoginFailedAction(string userName, string reason) { ActivityLog.ActivityLog activityLog1 = ActivityLogManager.CreateActivityLog(); activityLog1.ForceLog = true; activityLog1.UserName = userName; activityLog1.EntityName = string.Format("ورود ناموفق-{0}", (object)reason); activityLog1.VisibleForEndUser = true; activityLog1.EntityID = " "; activityLog1.Action = 8; ActivityLog.ActivityLog activityLog2 = activityLog1; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog1.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.LoginFailed.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog2.LogData = activityLogData; ActivityLogManager.Save(activityLog1); }
public static void SaveActivityLogForLoginAction(string userName) { ActivityLog.ActivityLog activityLog1 = ActivityLogManager.CreateActivityLog(); activityLog1.ForceLog = true; activityLog1.UserName = userName; activityLog1.EntityName = "ورود"; activityLog1.VisibleForEndUser = true; activityLog1.EntityID = SecurityManager.CurrentUserToken; activityLog1.Action = 6; ActivityLog.ActivityLog activityLog2 = activityLog1; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog1.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.Login.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog2.LogData = activityLogData; ActivityLogManager.Save(activityLog1); }
public TEntity Find(params object[] keyValues) { if (!this.UseForAnonymousUser) { SecurityManager.ThrowIfUserContextNull(); if (!this.OperationAccess.CanView) { throw new OperationAccessException(this.ViewKey); } } TEntity entity1 = this.FindEntity(keyValues); if ((object)entity1 is IActivityLoggable) { IActivityLoggable entity2 = (IActivityLoggable)(object)entity1; if (entity2.ActionsToLog == ActionLog.All || (entity2.ActionsToLog & ActionLog.Read) == ActionLog.Read) { OMF.Common.ActivityLog.ActivityLog activityLog = ActivityLogManager.CreateActivityLog(entity2); activityLog.Action = 1; ActivityLogManager.Save(activityLog); } } return(entity1); }
public override int SaveChanges() { try { int num = 0; this.SyncObjectsStatePreCommit(); if (this.ChangeTracker.HasChanges()) { List <object> objectList = new List <object>(); foreach (DbEntityEntry entry in this.ChangeTracker.Entries()) { if (entry.State != System.Data.Entity.EntityState.Detached && entry.State != System.Data.Entity.EntityState.Unchanged) { if (ConfigurationController.CustomIdentityEnabled && entry.State == System.Data.Entity.EntityState.Added && entry.Entity is IEntity && entry.Entity is ICustomIdentity) { (entry.Entity as IEntity).SetID((object)this.Database.SqlQuery <int>(string.Format("select {0}.NEXTVAL from dual", (object)(entry.Entity as ICustomIdentity).IdentityGeneratorSequenceName)).FirstOrDefault <int>()); } if (entry.Entity is IActivityLoggable) { IActivityLoggable entity = (IActivityLoggable)entry.Entity; if (entity.ActionsToLog == ActionLog.All) { objectList.Add(entry.Entity); } else if (entry.State == System.Data.Entity.EntityState.Added && (entity.ActionsToLog & ActionLog.Insert) == ActionLog.Insert) { objectList.Add(entry.Entity); } else if (entry.State == System.Data.Entity.EntityState.Modified && (entity.ActionsToLog & ActionLog.Update) == ActionLog.Update) { objectList.Add(entry.Entity); } else if (entry.State == System.Data.Entity.EntityState.Deleted && (entity.ActionsToLog & ActionLog.Delete) == ActionLog.Delete) { objectList.Add(entry.Entity); } } if (entry.Entity is ILoggableEntityID) { if (entry.State == System.Data.Entity.EntityState.Modified) { ILoggableEntityID loggableEntityId = entry.GetDatabaseValues().ToObject() as ILoggableEntityID; if (loggableEntityId != null) { ILoggableEntityID entity = (ILoggableEntityID)entry.Entity; entity.LogData = new EntityIDLogData(); entity.LogData.InsertUserID = loggableEntityId.LogData.InsertUserID; entity.LogData.InsertDateTime = loggableEntityId.LogData.InsertDateTime; entity.LogData.UpdateUserID = new int?(SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId); entity.LogData.UpdateDateTime = new DateTime?(DateTime.Now); } } else if (entry.State == System.Data.Entity.EntityState.Added) { ILoggableEntityID entity = (ILoggableEntityID)entry.Entity; entity.LogData = new EntityIDLogData(); entity.LogData.InsertUserID = new int?(SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId); entity.LogData.InsertDateTime = new DateTime?(DateTime.Now); entity.LogData.UpdateUserID = new int?(); entity.LogData.UpdateDateTime = new DateTime?(); } } else if (entry.Entity is ILoggableEntityName) { if (entry.State == System.Data.Entity.EntityState.Modified) { ILoggableEntityName loggableEntityName = entry.GetDatabaseValues().ToObject() as ILoggableEntityName; if (loggableEntityName != null) { ILoggableEntityName entity = (ILoggableEntityName)entry.Entity; entity.LogData = new EntityNameLogData(); entity.LogData.InsertUserName = loggableEntityName.LogData.InsertUserName; entity.LogData.InsertDateTime = loggableEntityName.LogData.InsertDateTime; entity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.UpdateDateTime = new DateTime?(DateTime.Now); } } else if (entry.State == System.Data.Entity.EntityState.Added) { ILoggableEntityName entity = (ILoggableEntityName)entry.Entity; entity.LogData = new EntityNameLogData(); entity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.InsertDateTime = DateTime.Now; entity.LogData.UpdateUserName = (string)null; entity.LogData.UpdateDateTime = new DateTime?(); } } else if (entry.Entity is ILoggableEntityNameAndID) { if (entry.State == System.Data.Entity.EntityState.Modified) { ILoggableEntityNameAndID loggableEntityNameAndId = entry.GetDatabaseValues().ToObject() as ILoggableEntityNameAndID; if (loggableEntityNameAndId != null) { ILoggableEntityNameAndID entity = (ILoggableEntityNameAndID)entry.Entity; entity.LogData = new EntityNameAndIDLogData(); entity.LogData.InsertUserId = loggableEntityNameAndId.LogData.InsertUserId; entity.LogData.InsertUserName = loggableEntityNameAndId.LogData.InsertUserName; entity.LogData.InsertDateTime = loggableEntityNameAndId.LogData.InsertDateTime; entity.LogData.UpdateUserId = new int?(SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId); entity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.UpdateDateTime = new DateTime?(DateTime.Now); } } else if (entry.State == System.Data.Entity.EntityState.Added) { ILoggableEntityNameAndID entity = (ILoggableEntityNameAndID)entry.Entity; entity.LogData = new EntityNameAndIDLogData(); entity.LogData.InsertUserId = SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId; entity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.InsertDateTime = DateTime.Now; entity.LogData.UpdateUserId = new int?(); entity.LogData.UpdateUserName = (string)null; entity.LogData.UpdateDateTime = new DateTime?(); } } else if (entry.Entity is ILoggableMCIEntity) { if (entry.State == System.Data.Entity.EntityState.Modified) { ILoggableMCIEntity loggableMciEntity = entry.GetDatabaseValues().ToObject() as ILoggableMCIEntity; if (loggableMciEntity != null) { ILoggableMCIEntity entity = (ILoggableMCIEntity)entry.Entity; entity.LogData = new MCIEntityLogData(); entity.LogData.InsertUserName = loggableMciEntity.LogData.InsertUserName; entity.LogData.InsertDate = loggableMciEntity.LogData.InsertDate; entity.LogData.InsertTime = loggableMciEntity.LogData.InsertTime; entity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.UpdateDate = DateTime.Now.ToPersianDateTime().ToDateString(); entity.LogData.UpdateTime = DateTime.Now.ToPersianDateTime().ToTimeString(); } } else if (entry.State == System.Data.Entity.EntityState.Added) { ILoggableMCIEntity entity = (ILoggableMCIEntity)entry.Entity; entity.LogData = new MCIEntityLogData(); entity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.InsertDate = DateTime.Now.ToPersianDateTime().ToDateString(); entity.LogData.InsertTime = DateTime.Now.ToPersianDateTime().ToTimeString(); entity.LogData.UpdateUserName = (string)null; entity.LogData.UpdateDate = (string)null; entity.LogData.UpdateTime = (string)null; } } else if (entry.Entity is ILoggableMCIEntity2) { if (entry.State == System.Data.Entity.EntityState.Modified) { ILoggableMCIEntity2 loggableMciEntity2 = entry.GetDatabaseValues().ToObject() as ILoggableMCIEntity2; if (loggableMciEntity2 != null) { ILoggableMCIEntity2 entity = (ILoggableMCIEntity2)entry.Entity; entity.LogData = new MCIEntityLogData2(); entity.LogData.InsertUserName = loggableMciEntity2.LogData.InsertUserName; entity.LogData.InsertDate = loggableMciEntity2.LogData.InsertDate; entity.LogData.InsertTime = loggableMciEntity2.LogData.InsertTime; entity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.UpdateDate = DateTime.Now.ToPersianDateTime().ToDateString(); entity.LogData.UpdateTime = DateTime.Now.ToPersianDateTime().ToTimeString(); } } else if (entry.State == System.Data.Entity.EntityState.Added) { ILoggableMCIEntity2 entity = (ILoggableMCIEntity2)entry.Entity; entity.LogData = new MCIEntityLogData2(); entity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.InsertDate = DateTime.Now.ToPersianDateTime().ToDateString(); entity.LogData.InsertTime = DateTime.Now.ToPersianDateTime().ToTimeString(); entity.LogData.UpdateUserName = (string)null; entity.LogData.UpdateDate = (string)null; entity.LogData.UpdateTime = (string)null; } } else if (entry.Entity is ILoggableMCIEntityWithIP) { if (entry.State == System.Data.Entity.EntityState.Modified) { ILoggableMCIEntityWithIP loggableMciEntityWithIp = entry.GetDatabaseValues().ToObject() as ILoggableMCIEntityWithIP; if (loggableMciEntityWithIp != null) { ILoggableMCIEntityWithIP entity = (ILoggableMCIEntityWithIP)entry.Entity; entity.LogData = new MCIEntityWithIPLogData(); entity.LogData.InsertUserName = loggableMciEntityWithIp.LogData.InsertUserName; entity.LogData.InsertDate = loggableMciEntityWithIp.LogData.InsertDate; entity.LogData.InsertTime = loggableMciEntityWithIp.LogData.InsertTime; entity.LogData.InsertUserIP = loggableMciEntityWithIp.LogData.InsertUserIP; entity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.UpdateDate = DateTime.Now.ToPersianDateTime().ToDateString(); entity.LogData.UpdateTime = DateTime.Now.ToPersianDateTime().ToTimeString(); entity.LogData.UpdateUserIP = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.ClientIP; } } else if (entry.State == System.Data.Entity.EntityState.Added) { ILoggableMCIEntityWithIP entity = (ILoggableMCIEntityWithIP)entry.Entity; entity.LogData = new MCIEntityWithIPLogData(); entity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; entity.LogData.InsertDate = DateTime.Now.ToPersianDateTime().ToDateString(); entity.LogData.InsertTime = DateTime.Now.ToPersianDateTime().ToTimeString(); entity.LogData.InsertUserIP = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.ClientIP; entity.LogData.UpdateUserName = (string)null; entity.LogData.UpdateDate = (string)null; entity.LogData.UpdateTime = (string)null; entity.LogData.UpdateUserIP = (string)null; } } if (entry.Entity is ICacheable) { CacheManager.Remove(entry.Entity.GetType().FullName); } if (entry.Entity is IConcurrencySupportable && (entry.State == System.Data.Entity.EntityState.Modified || entry.State == System.Data.Entity.EntityState.Added)) { entry.Property("RowVersion").CurrentValue = (object)Guid.NewGuid().ToString().Replace("-", ""); } } } num = base.SaveChanges(); List <OMF.Common.ActivityLog.ActivityLog> activityLogList = new List <OMF.Common.ActivityLog.ActivityLog>(); foreach (object obj in objectList) { OMF.Common.ActivityLog.ActivityLog activityLog = ActivityLogManager.CreateActivityLog(obj as IActivityLoggable); activityLogList.Add(activityLog); } this.SyncObjectsStatePostCommit(); ActivityLogManager.Save((IEnumerable <OMF.Common.ActivityLog.ActivityLog>)activityLogList); } return(num); } catch (DbEntityValidationException ex) { throw new DataAccessException(string.Join(Constants.NewLine, ex.EntityValidationErrors.SelectMany <DbEntityValidationResult, string>((Func <DbEntityValidationResult, IEnumerable <string> >)(failure => failure.ValidationErrors.Select <DbValidationError, string>((Func <DbValidationError, string>)(error => string.Format("{0}: {1}", (object)error.PropertyName, (object)error.ErrorMessage)))))), (Exception)ex); } }