private static void DelayValidateSchemaNameChanged(ModelElement element) { if (!element.IsDeleted) { Schema schema = (Schema)element; // Disable customization tracking during any name change to // avoid redundant processing. SchemaCustomization customization = SchemaCustomization.SetCustomization(schema, null); AbstractionModel abstractionModel; string schemaName; if (customization != null && null != (schemaName = customization.CustomizedSchemaName)) { schema.Name = schemaName; } else if (null != (abstractionModel = SchemaIsForAbstractionModel.GetAbstractionModel(schema))) { schema.Name = abstractionModel.Name; } if (customization != null) { // Don't regenerate the customization object for a schema name change, // just use the previous settings. SchemaCustomization.SetCustomization(schema, customization); } } }
/// <summary> /// Get the customizations for a given schema, and return the previous /// customization (if any). /// </summary> public static SchemaCustomization SetCustomization(Schema schema, SchemaCustomization customization) { object customizationsObject; Dictionary <Guid, SchemaCustomization> customizations; Type key = typeof(SchemaCustomization); Dictionary <object, object> bag = schema.Store.PropertyBag; SchemaCustomization prev = null; if (!bag.TryGetValue(key, out customizationsObject) || null == (customizations = customizationsObject as Dictionary <Guid, SchemaCustomization>)) { if (customization == null) { return(null); } bag[key] = customizations = new Dictionary <Guid, SchemaCustomization>(); } Guid schemaId = schema.Id; if (customization == null) { if (customizations.TryGetValue(schemaId, out prev)) { customizations.Remove(schemaId); } } else { customizations.TryGetValue(schemaId, out prev); customizations[schemaId] = customization; } return(prev); }
private static void TablePropertyChanged(object sender, ElementPropertyChangedEventArgs e) { // Transitions: // Name changed, CustomName set->update schema customization // CustomName changed: add or remove customization ModelElement element = e.ModelElement; Table table = null; Schema schema; SchemaCustomization customization; string updatedName = null; bool customNameChanged = false; if (!element.IsDeleted) { Guid propertyId = e.DomainProperty.Id; if (propertyId == Table.NameDomainPropertyId) { table = (Table)element; if (table.CustomName) { updatedName = table.Name; customNameChanged = true; } } else if (propertyId == Table.CustomNameDomainPropertyId) { table = (Table)element; if (table.CustomName) { updatedName = table.Name; } customNameChanged = true; } else if (propertyId == Table.ColumnOrderDomainPropertyId) { table = (Table)element; bool isCustom = (ColumnOrdering)e.NewValue == ColumnOrdering.Custom; if ((isCustom ^ ((ColumnOrdering)e.OldValue == ColumnOrdering.Custom)) && null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { // UNDONE: Consider batching this into an 'element events ended' customization.CustomizeColumnPositions(table, isCustom); } } if (customNameChanged && null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeTableName(table, updatedName); } } }
private static void DelayValidateSchemaNamesChanged(ModelElement element) { if (!element.IsDeleted) { Schema schema = (Schema)element; // Disable customization tracking during name generation, and // reset customizations on completion. SchemaCustomization customization = SchemaCustomization.SetCustomization(schema, null); NameGeneration.GenerateAllNames(schema, customization); SchemaCustomization.SetCustomization(schema, new SchemaCustomization(schema)); } }
private static void DelayValidateCustomizeColumnPositions(ModelElement element) { if (!element.IsDeleted) { Table table = (Table)element; Schema schema; SchemaCustomization customization; if (null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeColumnPositions(table, table.ColumnOrder == ColumnOrdering.Custom); } } }
/// <summary> /// Implements <see cref="IModelingEventSubscriber.ManageModelingEventHandlers"/> /// </summary> protected void ManageModelingEventHandlers(ModelingEventManager eventManager, EventSubscriberReasons reasons, EventHandlerAction action) { if (0 != (reasons & EventSubscriberReasons.DocumentLoaded)) { IPropertyProviderService propertyProvider = ((IFrameworkServices)Store).PropertyProviderService; propertyProvider.AddOrRemovePropertyProvider(typeof(FactType), AssimilationMapping.PopulateAssimilationMappingExtensionProperties, true, action); propertyProvider.AddOrRemovePropertyProvider(typeof(ObjectType), AssimilationMapping.PopulateObjectTypeAbsorptionExtensionProperties, false, action); propertyProvider.AddOrRemovePropertyProvider(typeof(ObjectType), ReferenceModeNaming.PopulateReferenceModeNamingExtensionProperties, false, action); propertyProvider.AddOrRemovePropertyProvider(typeof(ORMModel), ReferenceModeNaming.PopulateDefaultReferenceModeNamingExtensionPropertiesOnORMModel, false, action); propertyProvider.AddOrRemovePropertyProvider(typeof(RelationalNameGenerator), ReferenceModeNaming.PopulateDefaultReferenceModeNamingExtensionPropertiesOnColumnNameGenerator, false, action); if (0 != (reasons & EventSubscriberReasons.ModelStateEvents)) { SchemaCustomization.ManageModelingEventHandlers(eventManager, this.Store, action); } } }
private static void ColumnOrderChanged(object sender, RolePlayerOrderChangedEventArgs e) { ModelElement element = e.SourceElement; if (!element.IsDeleted) { Table table = (Table)element; Schema schema; SchemaCustomization customization; if (table.ColumnOrder == ColumnOrdering.Custom && null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { // UNDONE: Consider batching this into an 'element events ended' customization.CustomizeColumnPositions(table, true); } } }
private static void RebuildForAbstractionModelDelayed(ModelElement element) { if (!element.IsDeleted) { AbstractionModel model = (AbstractionModel)element; Schema schema = SchemaIsForAbstractionModel.GetSchema(model); if (schema != null) { // Clear any customizations to stop rules and events from modifying // the customizations during rebuild. SchemaCustomization initialCustomization = SchemaCustomization.SetCustomization(schema, null); schema.TableCollection.Clear(); schema.DomainCollection.Clear(); FullyGenerateConceptualDatabaseModel(schema, model, initialCustomization, null); SchemaCustomization.SetCustomization(schema, new SchemaCustomization(schema)); } } }
private static void ColumnPropertyChanged(object sender, ElementPropertyChangedEventArgs e) { // Transitions: // Name changed, CustomName set->update schema customization // CustomName changed: add or remove customization ModelElement element = e.ModelElement; if (!element.IsDeleted) { Column column = null; Table table; Schema schema; SchemaCustomization customization; string updatedName = null; bool customNameChanged = false; Guid propertyId = e.DomainProperty.Id; if (propertyId == Column.NameDomainPropertyId) { column = (Column)element; if (column.CustomName) { updatedName = column.Name; customNameChanged = true; } } else if (propertyId == Column.CustomNameDomainPropertyId) { column = (Column)element; if (column.CustomName) { updatedName = column.Name; } customNameChanged = true; } if (customNameChanged && null != (table = column.Table) && null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeColumnName(column, updatedName); } } }
/// <summary> /// ChangeRule: typeof(ORMSolutions.ORMArchitect.RelationalModels.ConceptualDatabase.Table) /// </summary> private static void TableChangedRule(ElementPropertyChangedEventArgs e) { Guid propertyId = e.DomainProperty.Id; Table table; Schema schema; SchemaCustomization customization; if (propertyId == Table.CustomNameDomainPropertyId) { table = (Table)e.ModelElement; if (null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeTableName(table, (bool)e.NewValue ? table.Name : null); ValidateSchemaNamesChanged(schema); } } else if (propertyId == Table.NameDomainPropertyId) { table = (Table)e.ModelElement; if (table.CustomName && null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeTableName(table, (string)e.NewValue); ValidateSchemaNamesChanged(schema); } } else if (propertyId == Table.ColumnOrderDomainPropertyId) { table = (Table)e.ModelElement; if (null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { if (((ColumnOrdering)e.NewValue == ColumnOrdering.Custom) ^ ((ColumnOrdering)e.OldValue == ColumnOrdering.Custom)) { FrameworkDomainModel.DelayValidateElement(table, DelayValidateCustomizeColumnPositions); } ValidateSchemaNamesChanged(schema); } } }
/// <summary> /// ChangeRule: typeof(ORMSolutions.ORMArchitect.RelationalModels.ConceptualDatabase.Column) /// </summary> private static void ColumnChangedRule(ElementPropertyChangedEventArgs e) { Guid propertyId = e.DomainProperty.Id; Column column; Table table; Schema schema; SchemaCustomization customization; if (propertyId == Column.IsNullableDomainPropertyId) { column = (Column)e.ModelElement; if (null != (table = column.Table) && table.ColumnOrder != ColumnOrdering.Custom) { ValidateTableNameChanged(table); } } else if (propertyId == Column.CustomNameDomainPropertyId) { column = (Column)e.ModelElement; if (null != (table = column.Table) && null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeColumnName(column, (bool)e.NewValue ? column.Name : null); ValidateSchemaNamesChanged(schema); } } else if (propertyId == Column.NameDomainPropertyId) { column = (Column)e.ModelElement; if (column.CustomName && null != (table = column.Table) && null != (schema = table.Schema) && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeColumnName(column, (string)e.NewValue); ValidateSchemaNamesChanged(schema); } } }
private static void SchemaPropertyChanged(object sender, ElementPropertyChangedEventArgs e) { // Transitions: // Name changed, CustomName set->update schema customization // CustomName changed: add or remove customization ModelElement element = e.ModelElement; if (!element.IsDeleted) { Schema schema = null; SchemaCustomization customization; string updatedName = null; bool customNameChanged = false; Guid propertyId = e.DomainProperty.Id; if (propertyId == Schema.NameDomainPropertyId) { schema = (Schema)element; if (schema.CustomName) { updatedName = schema.Name; customNameChanged = true; } } else if (propertyId == Schema.CustomNameDomainPropertyId) { schema = (Schema)element; if (schema.CustomName) { updatedName = schema.Name; } customNameChanged = true; } if (customNameChanged && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeSchemaName(schema, updatedName); } } }
/// <summary> /// ChangeRule: typeof(ORMSolutions.ORMArchitect.RelationalModels.ConceptualDatabase.Schema) /// </summary> private static void SchemaChangedRule(ElementPropertyChangedEventArgs e) { Guid propertyId = e.DomainProperty.Id; Schema schema; SchemaCustomization customization; if (propertyId == Schema.DefaultColumnOrderDomainPropertyId) { // Note that this does not affect custom ordering, so there is nothing to // record in the schema customizations ValidateSchemaNamesChanged((Schema)e.ModelElement); } else if (propertyId == Schema.CustomNameDomainPropertyId) { schema = (Schema)e.ModelElement; if (null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeSchemaName(schema, (bool)e.NewValue ? schema.Name : null); // Don't use the full ValidateSchemaNamesChanged, which rebuilds the customization // object and regenerates all names. FrameworkDomainModel.DelayValidateElement(schema, DelayValidateSchemaNameChanged); } } else if (propertyId == Schema.NameDomainPropertyId) { schema = (Schema)e.ModelElement; if (schema.CustomName && null != (customization = SchemaCustomization.GetCustomization(schema))) { customization.CustomizeSchemaName(schema, (string)e.NewValue); // Don't use the full ValidateSchemaNamesChanged, which rebuilds the customization // object and regenerates all names. FrameworkDomainModel.DelayValidateElement(schema, DelayValidateSchemaNameChanged); } } }