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 async Task SaveActivityLogForLoginFailedActionAsync( string userName, string reason) { ActivityLog.ActivityLog activityLog = ActivityLogManager.CreateActivityLog(); activityLog.ForceLog = true; activityLog.UserName = userName; activityLog.EntityName = string.Format("ورود ناموفق-{0}", (object)reason); activityLog.VisibleForEndUser = true; activityLog.EntityID = " "; activityLog.Action = 8; ActivityLog.ActivityLog activityLog1 = activityLog; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.LoginFailed.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog1.LogData = activityLogData; await ActivityLogManager.SaveAsync(activityLog); }
public static async Task SaveActivityLogForChangePassActionAsync( int userId, string userName) { ActivityLog.ActivityLog activityLog = ActivityLogManager.CreateActivityLog(); activityLog.ForceLog = true; activityLog.EntityName = "تغییر رمز عبور"; activityLog.UserName = userName; activityLog.VisibleForEndUser = true; activityLog.EntityID = userId.ToString(); activityLog.Action = 9; ActivityLog.ActivityLog activityLog1 = activityLog; ActivityLogData activityLogData = new ActivityLogData(); activityLogData.Data = SerializationHelper.SerializeCustom((object)new { UserName = userName, UserToken = activityLog.EntityID, RecordDateTime = DateTime.Now, Action = ActionType.ChangePassword.ToString() }); activityLogData.ObjectState = ObjectState.Added; activityLog1.LogData = activityLogData; await ActivityLogManager.SaveAsync(activityLog); }
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 async Task updateDataAsync(DB_Connection con) { activityLogManager = new ActivityLogManager(); DeviceManager = new DeviceManager(); UserManager = new UserManager(); con.Open(); DataTable dt_personInRoom = await con.QuerryAsync("SELECT ID, UserID, DeviceID_Login, Time_Login FROM v_personsInRoom;"); DataTable dt_user = await con.QuerryAsync("SELECT * FROM tbl_User;"); DataTable dt_devices = await con.QuerryAsync("SELECT * FROM tbl_Devices;"); DataTable dt_activityLog = await con.QuerryAsync("SELECT * FROM tbl_ActivityLog WHERE DeviceID_Logout IS NOT NULL;"); con.Close(); personsInRoomCount = dt_personInRoom.Rows.Count; isEnabled = personsInRoomCount > 0; // All user foreach (DataRow item in dt_user.Rows) { UserManager.AddUser(new User( Int32.Parse(item[0].ToString()), item[1].ToString(), item[2].ToString(), item[3].ToString(), item.Field <DateTime>(4) )); } // User in Room foreach (DataRow item in dt_personInRoom.Rows) { UserManager.GetUser(Int32.Parse(item[1].ToString())).IsLoggedIn = true; } // Devices foreach (DataRow item in dt_devices.Rows) { DeviceManager.AddDevice(new Device( Int32.Parse(item[0].ToString()), item[1].ToString() )); } }
// GET: Dashboard public ActionResult Index() { SendLetterManager sendLetterManager = new SendLetterManager(); ReceiveLetterManager ReceiveLetterManager = new ReceiveLetterManager(); UserManager userManager = new UserManager(); ActivityLogManager activityLogManager = new ActivityLogManager(); DashboardViewModel dashboardViewModel = new DashboardViewModel(); dashboardViewModel.PageId = "Dashboard"; dashboardViewModel.CountOfReceiveLetter = ReceiveLetterManager.Count; dashboardViewModel.CountOfSendLetter = sendLetterManager.Count; dashboardViewModel.CountOfUser = userManager.Count; //dashboardViewModel.activityLog = new List<ActivityLog>(); //dashboardViewModel.activityLog = activityLogManager.Read(x=>x.TimeStamp >= System.Data.Entity.DbFunctions.AddDays(new DateTime(),-1),null,0,false); return(View(dashboardViewModel)); }
protected override void OnClosing(CancelEventArgs e) { if (ManageViewModel.M2qttManager != null) { ManageViewModel.M2qttManager.Disconnect(); } if (ManageViewModel.IsSharingSession == true) { string messageBoxText = "If you close the application while in sharing mode, all shared messengers will be discarded, do you want to save them?"; MessageBoxResult result = MessageBox.Show(messageBoxText, "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { DatabaseContextUtility.SaveMessengers(PageManager.Instance.MessengerCache); } } ActivityLogManager.SendActivityLog(); ActivityLogManager.SaveActivityLog(); Application.Current.Shutdown(); System.Diagnostics.Process.GetCurrentProcess().Kill(); }
public void PerformActionOnMessenger(int id) { Messenger messenger = ApplicationContext.Instance.GetMessengerFromApplicationContextById(id); ActivityLogManager.Log(messenger); if (messenger.Children != null && messenger.Children.Any()) { MoveDownALevel(messenger); } else { if (SentenceModeManager.SentenceMode) { SentenceModeManager.AddWord(messenger.Name); } else { synthesizer.SpeakAsync(messenger.Name); } } }
protected void SetUserData() { try { this.detailMessage = ExceptionManager.GetExceptionMessageWithDebugInfo(this.exception); this.machineName = ActivityLogManager.ClientIpCatcher(); this.domainName = !this.Exception.Data.Contains((object)"SourceName") ? Environment.UserDomainName : this.Exception.Data[(object)"SourceName"].ToString(); this.machineIP = ActivityLogManager.ClientIpCatcher(); this.osVersion = Environment.OSVersion.ToString(); this.osLogonName = Environment.UserName; if (SecurityManager.CurrentUserContext != null) { this.userID = (object)SecurityManager.CurrentUserContext.UserId; this.userName = SecurityManager.CurrentUserContext.UserName; } else { this.userID = (object)-1; this.userName = "******"; } int?applicationId = ConfigurationController.ApplicationID; int num; if (!applicationId.HasValue) { num = -1; } else { applicationId = ConfigurationController.ApplicationID; num = applicationId.Value; } this.appId = num; this.date = DateTime.Now; this.code = Environment.MachineName + this.date.ToString("-yyyyMMddHHmmssffff"); } catch (Exception ex) { throw new ExpManagementException(ex); } }
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 MainWindow() { InitializeComponent(); ((INotifyCollectionChanged)SentenceListView.Items).CollectionChanged += SentenceListView_CollectionChanged; ActivityLogManager.LoadUnsentLog(); }
//public string IdentityGeneratorSequenceName //{ // get // { // return "tbl_user_info_seq"; // } //} public UserContext ConvertToUserContext() { UserContext userContext = new UserContext(); userContext.UserId = this.ID; userContext.Gender = this.Gender; userContext.UserName = this.UserName; userContext.FirstName = this.FirstName; userContext.Tel = this.Tel; userContext.Email = this.Email; userContext.LastName = this.LastName; userContext.NationalCode = this.NationalCode; userContext.Password = this.Password; userContext.MobileNo = this.MobileNo; userContext.ApplicationID = this.ApplicationId; userContext.AuthenticationType = this.AuthenticationType; userContext.OrganizationId = this.OrganizationId; userContext.NeedOTP = this.NeedOTP; userContext.OTPCode = this.OTPCode; userContext.OTPTryNo = this.OTPTryNo; userContext.LastOTPDate = this.LastOTPDate; userContext.Tag1 = this.Tag1; userContext.Tag2 = this.Tag2; userContext.Tag3 = this.Tag3; userContext.Tag4 = this.Tag4; userContext.Tag5 = this.Tag5; userContext.Tag6 = this.Tag6; userContext.Tag7 = this.Tag7; userContext.Tag8 = this.Tag8; userContext.Tag9 = this.Tag9; userContext.Tag10 = this.Tag10; userContext.TagInt1 = this.TagInt1; userContext.TagInt2 = this.TagInt2; userContext.TagInt3 = this.TagInt3; userContext.TagInt4 = this.TagInt4; userContext.TagInt5 = this.TagInt5; userContext.LastLoginDateTime = DateTime.Now; userContext.Roles = SecurityManager.GetUserRoles(this.ID); userContext.ClientIP = ActivityLogManager.ClientIpCatcher == null ? "" : ActivityLogManager.ClientIpCatcher(); return(userContext); }
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); } }
public override async Task <int> SaveChangesAsync(CancellationToken cancellationToken) { int num; try { int changes = 0; this.SyncObjectsStatePreCommit(); if (this.ChangeTracker.HasChanges()) { List <object> logList = new List <object>(); List <IWorkflowStarterEntity> list = new List <IWorkflowStarterEntity>(); foreach (DbEntityEntry entry in this.ChangeTracker.Entries()) { DbEntityEntry dbEntry = entry; if (dbEntry.State != System.Data.Entity.EntityState.Detached && dbEntry.State != System.Data.Entity.EntityState.Unchanged) { if (ConfigurationController.CustomIdentityEnabled && dbEntry.State == System.Data.Entity.EntityState.Added && dbEntry.Entity is IEntity && dbEntry.Entity is ICustomIdentity) { IEntity entity = dbEntry.Entity as IEntity; string sequenceName = (dbEntry.Entity as ICustomIdentity).IdentityGeneratorSequenceName; int identity = this.Database.SqlQuery <int>(string.Format("select {0}.NEXTVAL from dual", (object)sequenceName)).FirstOrDefault <int>(); entity.SetID((object)identity); entity = (IEntity)null; sequenceName = (string)null; } if (dbEntry.Entity is IActivityLoggable) { IActivityLoggable entityForLog = (IActivityLoggable)dbEntry.Entity; if (entityForLog.ActionsToLog == ActionLog.All) { logList.Add(dbEntry.Entity); } else if (dbEntry.State == System.Data.Entity.EntityState.Added && (entityForLog.ActionsToLog & ActionLog.Insert) == ActionLog.Insert) { logList.Add(dbEntry.Entity); } else if (dbEntry.State == System.Data.Entity.EntityState.Modified && (entityForLog.ActionsToLog & ActionLog.Update) == ActionLog.Update) { logList.Add(dbEntry.Entity); } else if (dbEntry.State == System.Data.Entity.EntityState.Deleted && (entityForLog.ActionsToLog & ActionLog.Delete) == ActionLog.Delete) { logList.Add(dbEntry.Entity); } entityForLog = (IActivityLoggable)null; } if (dbEntry.Entity is ILoggableEntityID) { if (dbEntry.State == System.Data.Entity.EntityState.Modified) { DbPropertyValues dbValues = await dbEntry.GetDatabaseValuesAsync(cancellationToken); ILoggableEntityID dbEntity = dbValues.ToObject() as ILoggableEntityID; if (dbEntity != null) { ILoggableEntityID loggableEntity = (ILoggableEntityID)dbEntry.Entity; loggableEntity.LogData = new EntityIDLogData(); loggableEntity.LogData.InsertUserID = dbEntity.LogData.InsertUserID; loggableEntity.LogData.InsertDateTime = dbEntity.LogData.InsertDateTime; loggableEntity.LogData.UpdateUserID = new int?(SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId); loggableEntity.LogData.UpdateDateTime = new DateTime?(DateTime.Now); loggableEntity = (ILoggableEntityID)null; } dbValues = (DbPropertyValues)null; dbEntity = (ILoggableEntityID)null; } else if (dbEntry.State == System.Data.Entity.EntityState.Added) { ILoggableEntityID loggableEntity = (ILoggableEntityID)dbEntry.Entity; loggableEntity.LogData = new EntityIDLogData(); loggableEntity.LogData.InsertUserID = new int?(SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId); loggableEntity.LogData.InsertDateTime = new DateTime?(DateTime.Now); loggableEntity.LogData.UpdateUserID = new int?(); loggableEntity.LogData.UpdateDateTime = new DateTime?(); loggableEntity = (ILoggableEntityID)null; } } else if (dbEntry.Entity is ILoggableEntityName) { if (dbEntry.State == System.Data.Entity.EntityState.Modified) { DbPropertyValues dbValues = await dbEntry.GetDatabaseValuesAsync(); ILoggableEntityName dbEntity = dbValues.ToObject() as ILoggableEntityName; if (dbEntity != null) { ILoggableEntityName loggableEntity = (ILoggableEntityName)dbEntry.Entity; loggableEntity.LogData = new EntityNameLogData(); loggableEntity.LogData.InsertUserName = dbEntity.LogData.InsertUserName; loggableEntity.LogData.InsertDateTime = dbEntity.LogData.InsertDateTime; loggableEntity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.UpdateDateTime = new DateTime?(DateTime.Now); loggableEntity = (ILoggableEntityName)null; } dbValues = (DbPropertyValues)null; dbEntity = (ILoggableEntityName)null; } else if (dbEntry.State == System.Data.Entity.EntityState.Added) { ILoggableEntityName loggableEntity = (ILoggableEntityName)dbEntry.Entity; loggableEntity.LogData = new EntityNameLogData(); loggableEntity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.InsertDateTime = DateTime.Now; loggableEntity.LogData.UpdateUserName = (string)null; loggableEntity.LogData.UpdateDateTime = new DateTime?(); loggableEntity = (ILoggableEntityName)null; } } else if (dbEntry.Entity is ILoggableEntityNameAndID) { if (dbEntry.State == System.Data.Entity.EntityState.Modified) { DbPropertyValues dbValues = await dbEntry.GetDatabaseValuesAsync(); ILoggableEntityNameAndID dbEntity = dbValues.ToObject() as ILoggableEntityNameAndID; if (dbEntity != null) { ILoggableEntityNameAndID loggableEntity = (ILoggableEntityNameAndID)dbEntry.Entity; loggableEntity.LogData = new EntityNameAndIDLogData(); loggableEntity.LogData.InsertUserId = dbEntity.LogData.InsertUserId; loggableEntity.LogData.InsertUserName = dbEntity.LogData.InsertUserName; loggableEntity.LogData.InsertDateTime = dbEntity.LogData.InsertDateTime; loggableEntity.LogData.UpdateUserId = new int?(SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId); loggableEntity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.UpdateDateTime = new DateTime?(DateTime.Now); loggableEntity = (ILoggableEntityNameAndID)null; } dbValues = (DbPropertyValues)null; dbEntity = (ILoggableEntityNameAndID)null; } else if (dbEntry.State == System.Data.Entity.EntityState.Added) { ILoggableEntityNameAndID loggableEntity = (ILoggableEntityNameAndID)dbEntry.Entity; loggableEntity.LogData = new EntityNameAndIDLogData(); loggableEntity.LogData.InsertUserId = SecurityManager.CurrentUserContext == null ? -1 : SecurityManager.CurrentUserContext.UserId; loggableEntity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.InsertDateTime = DateTime.Now; loggableEntity.LogData.UpdateUserId = new int?(); loggableEntity.LogData.UpdateUserName = (string)null; loggableEntity.LogData.UpdateDateTime = new DateTime?(); loggableEntity = (ILoggableEntityNameAndID)null; } } else if (dbEntry.Entity is ILoggableMCIEntity) { if (dbEntry.State == System.Data.Entity.EntityState.Modified) { DbPropertyValues dbValues = await dbEntry.GetDatabaseValuesAsync(); ILoggableMCIEntity dbEntity = dbValues.ToObject() as ILoggableMCIEntity; if (dbEntity != null) { ILoggableMCIEntity loggableEntity = (ILoggableMCIEntity)dbEntry.Entity; loggableEntity.LogData = new MCIEntityLogData(); loggableEntity.LogData.InsertUserName = dbEntity.LogData.InsertUserName; loggableEntity.LogData.InsertDate = dbEntity.LogData.InsertDate; loggableEntity.LogData.InsertTime = dbEntity.LogData.InsertTime; loggableEntity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.UpdateDate = DateTime.Now.ToPersianDateTime().ToDateString(); loggableEntity.LogData.UpdateTime = DateTime.Now.ToPersianDateTime().ToTimeString(); loggableEntity = (ILoggableMCIEntity)null; } dbValues = (DbPropertyValues)null; dbEntity = (ILoggableMCIEntity)null; } else if (dbEntry.State == System.Data.Entity.EntityState.Added) { ILoggableMCIEntity loggableEntity = (ILoggableMCIEntity)dbEntry.Entity; loggableEntity.LogData = new MCIEntityLogData(); loggableEntity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.InsertDate = DateTime.Now.ToPersianDateTime().ToDateString(); loggableEntity.LogData.InsertTime = DateTime.Now.ToPersianDateTime().ToTimeString(); loggableEntity.LogData.UpdateUserName = (string)null; loggableEntity.LogData.UpdateDate = (string)null; loggableEntity.LogData.UpdateTime = (string)null; loggableEntity = (ILoggableMCIEntity)null; } } else if (dbEntry.Entity is ILoggableMCIEntity2) { if (dbEntry.State == System.Data.Entity.EntityState.Modified) { DbPropertyValues dbValues = await dbEntry.GetDatabaseValuesAsync(); ILoggableMCIEntity2 dbEntity = dbValues.ToObject() as ILoggableMCIEntity2; if (dbEntity != null) { ILoggableMCIEntity2 loggableEntity = (ILoggableMCIEntity2)dbEntry.Entity; loggableEntity.LogData = new MCIEntityLogData2(); loggableEntity.LogData.InsertUserName = dbEntity.LogData.InsertUserName; loggableEntity.LogData.InsertDate = dbEntity.LogData.InsertDate; loggableEntity.LogData.InsertTime = dbEntity.LogData.InsertTime; loggableEntity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.UpdateDate = DateTime.Now.ToPersianDateTime().ToDateString(); loggableEntity.LogData.UpdateTime = DateTime.Now.ToPersianDateTime().ToTimeString(); loggableEntity = (ILoggableMCIEntity2)null; } dbValues = (DbPropertyValues)null; dbEntity = (ILoggableMCIEntity2)null; } else if (dbEntry.State == System.Data.Entity.EntityState.Added) { ILoggableMCIEntity2 loggableEntity = (ILoggableMCIEntity2)dbEntry.Entity; loggableEntity.LogData = new MCIEntityLogData2(); loggableEntity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.InsertDate = DateTime.Now.ToPersianDateTime().ToDateString(); loggableEntity.LogData.InsertTime = DateTime.Now.ToPersianDateTime().ToTimeString(); loggableEntity.LogData.UpdateUserName = (string)null; loggableEntity.LogData.UpdateDate = (string)null; loggableEntity.LogData.UpdateTime = (string)null; loggableEntity = (ILoggableMCIEntity2)null; } } else if (dbEntry.Entity is ILoggableMCIEntityWithIP) { if (dbEntry.State == System.Data.Entity.EntityState.Modified) { DbPropertyValues dbValues = await dbEntry.GetDatabaseValuesAsync(); ILoggableMCIEntityWithIP dbEntity = dbValues.ToObject() as ILoggableMCIEntityWithIP; if (dbEntity != null) { ILoggableMCIEntityWithIP loggableEntity = (ILoggableMCIEntityWithIP)dbEntry.Entity; loggableEntity.LogData = new MCIEntityWithIPLogData(); loggableEntity.LogData.InsertUserName = dbEntity.LogData.InsertUserName; loggableEntity.LogData.InsertDate = dbEntity.LogData.InsertDate; loggableEntity.LogData.InsertTime = dbEntity.LogData.InsertTime; loggableEntity.LogData.InsertUserIP = dbEntity.LogData.InsertUserIP; loggableEntity.LogData.UpdateUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.UpdateDate = DateTime.Now.ToPersianDateTime().ToDateString(); loggableEntity.LogData.UpdateTime = DateTime.Now.ToPersianDateTime().ToTimeString(); loggableEntity.LogData.UpdateUserIP = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.ClientIP; loggableEntity = (ILoggableMCIEntityWithIP)null; } dbValues = (DbPropertyValues)null; dbEntity = (ILoggableMCIEntityWithIP)null; } else if (dbEntry.State == System.Data.Entity.EntityState.Added) { ILoggableMCIEntityWithIP loggableEntity = (ILoggableMCIEntityWithIP)dbEntry.Entity; loggableEntity.LogData = new MCIEntityWithIPLogData(); loggableEntity.LogData.InsertUserName = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.UserName; loggableEntity.LogData.InsertDate = DateTime.Now.ToPersianDateTime().ToDateString(); loggableEntity.LogData.InsertTime = DateTime.Now.ToPersianDateTime().ToTimeString(); loggableEntity.LogData.InsertUserIP = SecurityManager.CurrentUserContext == null ? "-1" : SecurityManager.CurrentUserContext.ClientIP; loggableEntity.LogData.UpdateUserName = (string)null; loggableEntity.LogData.UpdateDate = (string)null; loggableEntity.LogData.UpdateTime = (string)null; loggableEntity.LogData.UpdateUserIP = (string)null; loggableEntity = (ILoggableMCIEntityWithIP)null; } } if (dbEntry.Entity is ICacheable) { CacheManager.Remove(dbEntry.Entity.GetType().FullName); } if (dbEntry.Entity is IConcurrencySupportable && (dbEntry.State == System.Data.Entity.EntityState.Modified || dbEntry.State == System.Data.Entity.EntityState.Added)) { dbEntry.Property("RowVersion").CurrentValue = (object)Guid.NewGuid().ToString().Replace("-", ""); } dbEntry = (DbEntityEntry)null; } } changes = await base.SaveChangesAsync(cancellationToken); List <OMF.Common.ActivityLog.ActivityLog> activityLogList = new List <OMF.Common.ActivityLog.ActivityLog>(); foreach (object obj in logList) { object entity = obj; OMF.Common.ActivityLog.ActivityLog activityLog = ActivityLogManager.CreateActivityLog(entity as IActivityLoggable); activityLogList.Add(activityLog); activityLog = (OMF.Common.ActivityLog.ActivityLog)null; entity = (object)null; } this.SyncObjectsStatePostCommit(); await ActivityLogManager.SaveAsync((IEnumerable <OMF.Common.ActivityLog.ActivityLog>) activityLogList); logList = (List <object>)null; list = (List <IWorkflowStarterEntity>)null; activityLogList = (List <OMF.Common.ActivityLog.ActivityLog>)null; } num = changes; } catch (DbEntityValidationException ex) { string jointFailures = 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)))))); throw new DataAccessException(jointFailures, (Exception)ex); } return(num); }