public RecordChangedEventArgs( MessagesBag messagesBag, IModelToTableMapper <T> mapper, IEnumerable <TableColumnInfo> userInterestedColumns, string server, string database, string sender, CultureInfo cultureInfo, bool includeOldValues = false) : base(server, database, sender, cultureInfo) { this.MessagesBag = messagesBag; this.EntiyProperiesInfo = ModelUtil.GetModelPropertiesInfo <T>(); this.UserInterestedColumns = userInterestedColumns; this.ChangeType = messagesBag.MessageType; this.Entity = this.MaterializeEntity(messagesBag.Messages.Where(m => !m.IsOldValue).ToList(), mapper); if (includeOldValues && this.ChangeType == ChangeType.Update) { this.EntityOldValues = this.MaterializeEntity(messagesBag.Messages.Where(m => m.IsOldValue).ToList(), mapper); } else { this.EntityOldValues = default(T); } }
protected virtual ITableDependency <TEntity> CreateSqlTableDependency(IModelToTableMapper <TEntity> modelToTableMapper) { var sqlTableDependencySettings = Settings; switch (lifetimeScope) { case LifetimeScope.ConnectionScope: return(new SqlTableDependencyWithReconnection <TEntity>(connectionString, TableName, schemaName: SchemaName, mapper: modelToTableMapper, updateOf: sqlTableDependencySettings.UpdateOf, filter: sqlTableDependencySettings.Filter, notifyOn: sqlTableDependencySettings.NotifyOn, executeUserPermissionCheck: sqlTableDependencySettings.ExecuteUserPermissionCheck, includeOldValues: sqlTableDependencySettings.IncludeOldValues)); case LifetimeScope.ApplicationScope: return(new SqlTableDependencyWitApplicationScope <TEntity>(connectionString, TableName, schemaName: SchemaName, mapper: modelToTableMapper, updateOf: sqlTableDependencySettings.UpdateOf, filter: sqlTableDependencySettings.Filter, notifyOn: sqlTableDependencySettings.NotifyOn, executeUserPermissionCheck: sqlTableDependencySettings.ExecuteUserPermissionCheck, includeOldValues: sqlTableDependencySettings.IncludeOldValues)); case LifetimeScope.UniqueScope: return(new SqlTableDependencyWithUniqueScope <TEntity>(connectionString, TableName, schemaName: SchemaName, mapper: modelToTableMapper, updateOf: sqlTableDependencySettings.UpdateOf, filter: sqlTableDependencySettings.Filter, notifyOn: sqlTableDependencySettings.NotifyOn, executeUserPermissionCheck: sqlTableDependencySettings.ExecuteUserPermissionCheck, includeOldValues: sqlTableDependencySettings.IncludeOldValues)); default: return(null); } }
protected TableDependency( string connectionString, string schemaName = null, string tableName = null, IModelToTableMapper <T> mapper = null, IUpdateOfModel <T> updateOf = null, ITableDependencyFilter filter = null, DmlTriggerType dmlTriggerType = DmlTriggerType.All, bool executeUserPermissionCheck = true) { if (mapper?.Count() == 0) { throw new UpdateOfException("mapper parameter is empty."); } if (updateOf?.Count() == 0) { throw new UpdateOfException("updateOf parameter is empty."); } this.CheckIfConnectionStringIsValid(connectionString); this.CheckIfParameterlessConstructorExistsForModel(); if (executeUserPermissionCheck) { this.CheckIfUserHasPermissions(connectionString); } _connectionString = connectionString; _tableName = this.GetTableName(tableName); _schemaName = this.GetSchemaName(schemaName); _server = this.GetServerName(connectionString); _database = this.GetDataBaseName(connectionString); this.CheckIfTableExists(connectionString); this.CheckRdbmsDependentImplementation(connectionString); var tableColumnList = this.GetTableColumnsList(connectionString); if (!tableColumnList.Any()) { throw new TableWithNoColumnsException(tableName); } _mapper = mapper ?? this.GetModelMapperFromColumnDataAnnotation(); this.CheckMapperValidity(tableColumnList); this.CheckUpdateOfCongruenceWithTriggerType(updateOf, dmlTriggerType); _updateOf = this.GetUpdateOfColumnNameList(updateOf, tableColumnList); _userInterestedColumns = this.GetUserInterestedColumns(tableColumnList); if (!_userInterestedColumns.Any()) { throw new NoMatchBetweenModelAndTableColumns(); } this.CheckIfUserInterestedColumnsCanBeManaged(_userInterestedColumns); _dataBaseObjectsNamingConvention = this.GetBaseObjectsNamingConvention(); _dmlTriggerType = dmlTriggerType; _filter = filter; }
public SqlTableDependencyFilter(Expression filter, IModelToTableMapper <T> modelMapperDictionary = null) { _filter = filter; _modelMapperDictionary = modelMapperDictionary != null && modelMapperDictionary.Count() > 0 ? modelMapperDictionary.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value) : this.CreateModelToTableMapperHelper()?.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value); }
public SqlTableDependencyFilter(Expression filter, IModelToTableMapper <T> modelMapperDictionary = null) { _filter = filter; _modelMapperDictionary = modelMapperDictionary != null && modelMapperDictionary.Count() > 0 ? modelMapperDictionary.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value) : ModelToTableMapperHelper <T> .GetModelMapperFromColumnDataAnnotation()?.GetMappings().ToDictionary(kvp => kvp.Key.Name, kvp => kvp.Value); }
public SqlRecordChangedEventArgs( MessagesBag messagesBag, IModelToTableMapper <T> mapper, IEnumerable <ColumnInfo> userInterestedColumns, string server, string database, string sender, CultureInfo cultureInfo) : base(messagesBag, mapper, userInterestedColumns, server, database, sender, cultureInfo) { }
protected override ITableDependency <Product> CreateSqlTableDependency(IModelToTableMapper <Product> modelToTableMapper) { var sqlTableDependency = base.CreateSqlTableDependency(modelToTableMapper); traceListener?.Dispose(); sqlTableDependency.TraceListener = traceListener = new NLogTraceListener(); sqlTableDependency.TraceLevel = TraceLevel.Verbose; return(sqlTableDependency); }
public RecordChangedEventArgs( MessagesBag messagesBag, IModelToTableMapper <T> mapper, IEnumerable <ColumnInfo> userInterestedColumns, string server, string database, string sender, CultureInfo cultureInfo) : base(server, database, sender, cultureInfo) { this.MessagesBag = messagesBag; this.EntiyProperiesInfo = ModelUtil.GetModelPropertiesInfo <T>(); this.UserInterestedColumns = userInterestedColumns; this.ChangeType = messagesBag.MessageType; this.Entity = this.MaterializeEntity(messagesBag.Messages, mapper); }
public SqlTableDependencyTest( string connectionString, string tableName = null, string schemaName = null, IModelToTableMapper <T> mapper = null, IUpdateOfModel <T> updateOf = null, ITableDependencyFilter filter = null, DmlTriggerType notifyOn = DmlTriggerType.All, bool executeUserPermissionCheck = true, bool includeOldValues = false, bool throwExceptionBeforeWaitForNotifications = false, bool throwExceptionInWaitForNotificationsPoint1 = false, bool throwExceptionInWaitForNotificationsPoint2 = false, bool throwExceptionInWaitForNotificationsPoint3 = false, bool throwExceptionCreateSqlServerDatabaseObjects = false) : base(connectionString, tableName, schemaName, mapper, updateOf, filter, notifyOn, executeUserPermissionCheck, includeOldValues) { _throwExceptionBeforeWaitForNotifications = throwExceptionBeforeWaitForNotifications; _throwExceptionInWaitForNotificationsPoint1 = throwExceptionInWaitForNotificationsPoint1; _throwExceptionInWaitForNotificationsPoint2 = throwExceptionInWaitForNotificationsPoint2; _throwExceptionInWaitForNotificationsPoint3 = throwExceptionInWaitForNotificationsPoint3; _throwExceptionCreateSqlServerDatabaseObjects = throwExceptionCreateSqlServerDatabaseObjects; }
protected virtual T MaterializeEntity(List <Message> messages, IModelToTableMapper <T> mapper) { var entity = new T(); foreach (var entityPropertyInfo in this.EntiyProperiesInfo) { var propertyMappedTo = mapper?.GetMapping(entityPropertyInfo); var columnName = propertyMappedTo ?? entityPropertyInfo.Name; var message = messages.FirstOrDefault(m => string.Equals(m.Recipient, columnName, StringComparison.CurrentCultureIgnoreCase)); if (message == default(Message)) { continue; } var columnInfo = this.GetColumnInfo(columnName); var value = this.GetValue(entityPropertyInfo, columnInfo, message.Body); this.SetValue(entity, entityPropertyInfo.Name, value); } return(entity); }
public SqlTableDependencyWithReconnection(string connectionString, string tableName = null, string schemaName = null, IModelToTableMapper <TEntity> mapper = null, IUpdateOfModel <TEntity> updateOf = null, ITableDependencyFilter filter = null, DmlTriggerType notifyOn = DmlTriggerType.All, bool executeUserPermissionCheck = true, bool includeOldValues = false) : base(connectionString, tableName, schemaName, mapper, updateOf, filter, notifyOn, executeUserPermissionCheck, includeOldValues) { }
public BaseDependency(string table_name, IModelToTableMapper <T> modelToTableMapper) { dependency = new SqlTableDependency <T>(connectionString, table_name, modelToTableMapper); }