/// <summary>Called when a property changes.</summary> /// <param name="e">An EventArgs that contains the event data.</param> /// <remarks> /// This method will be called when the value changes for an /// IMS property that has been associated with a shape field. /// See ShapeField.AssociateValueWith for more detail. /// </remarks> /// <remarks> /// This method should be called from the setter of any CLR property /// (i.e., a non-IMS property on this shape) that has been associated /// with a shape field. /// See ShapeField.AssociateValueWith for more detail. /// </remarks> protected override void OnAssociatedPropertyChanged(PropertyChangedEventArgs e) { switch (e.PropertyName) { case "FKPropertyName": PresentationHelper.UpdateAssociationDisplay(this); break; case "Persistent": PresentationHelper.UpdateAssociationDisplay(this); break; case "SourceDeleteAction": PresentationHelper.UpdateAssociationDisplay(this, sourceDeleteAction: (DeleteAction)e.NewValue); break; case "TargetDeleteAction": PresentationHelper.UpdateAssociationDisplay(this, targetDeleteAction: (DeleteAction)e.NewValue); break; case "SourceMultiplicity": PresentationHelper.UpdateAssociationDisplay(this); break; case "TargetMultiplicity": PresentationHelper.UpdateAssociationDisplay(this); break; } base.OnAssociatedPropertyChanged(e); }
public override void ElementAdded(ElementAddedEventArgs e) { base.ElementAdded(e); Association element = (Association)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; if (current.IsSerializing || ModelRoot.BatchUpdating) { return; } if (e.ModelElement is UnidirectionalAssociation u) { ConfigureNewAssociation(u); } else if (e.ModelElement is BidirectionalAssociation b) { ConfigureNewAssociation(b); } AssociationChangedRules.SetEndpointRoles(element); PresentationHelper.UpdateAssociationDisplay(element); }
public override void ElementAdded(ElementAddedEventArgs e) { base.ElementAdded(e); UnidirectionalAssociation element = (UnidirectionalAssociation)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; if (current.IsSerializing || ModelRoot.BatchUpdating) { return; } PresentationHelper.UpdateAssociationDisplay(element); }
public override void ElementAdded(ElementAddedEventArgs e) { base.ElementAdded(e); Association element = (Association)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; PluralizationService pluralizationService = ModelRoot.PluralizationService; if (current.IsSerializing || ModelRoot.BatchUpdating) { return; } // add unidirectional // source can't be dependent (connection builder handles this) // if target is dependent, // source cardinality is 0..1 // target cardinality is 0..1 // source is principal if (element is UnidirectionalAssociation && element.Target.IsDependentType) { element.TargetMultiplicity = Multiplicity.ZeroOne; element.SourceRole = EndpointRole.Principal; element.TargetRole = EndpointRole.Dependent; } // add bidirectional // neither can be dependent (connection builder handles this) if (string.IsNullOrEmpty(element.TargetPropertyName)) { string rootName = element.TargetMultiplicity == Multiplicity.ZeroMany && pluralizationService?.IsSingular(element.Target.Name) == true ? pluralizationService.Pluralize(element.Target.Name) : element.Target.Name; string identifierName = rootName; int index = 0; while (element.Source.HasPropertyNamed(identifierName)) { identifierName = $"{rootName}_{++index}"; } element.TargetPropertyName = identifierName; } if (element is BidirectionalAssociation bidirectionalAssociation) { if (string.IsNullOrEmpty(bidirectionalAssociation.SourcePropertyName)) { string rootName = element.SourceMultiplicity == Multiplicity.ZeroMany && pluralizationService?.IsSingular(element.Source.Name) == true ? pluralizationService.Pluralize(element.Source.Name) : element.Source.Name; string identifierName = rootName; int index = 0; while (element.Target.HasPropertyNamed(identifierName)) { identifierName = $"{rootName}_{++index}"; } bidirectionalAssociation.SourcePropertyName = identifierName; } } AssociationChangedRules.SetEndpointRoles(element); PresentationHelper.UpdateAssociationDisplay(element); }
public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e) { base.ElementPropertyChanged(e); ModelRoot element = (ModelRoot)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; if (current.IsSerializing || ModelRoot.BatchUpdating) { return; } if (Equals(e.NewValue, e.OldValue)) { return; } List <string> errorMessages = EFCoreValidator.GetErrors(element).ToList(); bool redraw = false; switch (e.DomainProperty.Name) { case "ConnectionString": if (e.NewValue != null) { element.ConnectionStringName = null; } break; case "ConnectionStringName": if (e.NewValue != null) { element.ConnectionString = null; } break; case "EntityFrameworkVersion": element.EntityFrameworkPackageVersion = "Latest"; if (element.EntityFrameworkVersion == EFVersion.EFCore) { element.InheritanceStrategy = CodeStrategy.TablePerHierarchy; } if (element.EntityFrameworkVersion == EFVersion.EF6) { List <Association> associations = store.ElementDirectory .AllElements .OfType <Association>() .Where(a => !string.IsNullOrEmpty(a.FKPropertyName) && a.SourceMultiplicity != Multiplicity.ZeroMany && a.TargetMultiplicity != Multiplicity.ZeroMany) .ToList(); string message = $"This will remove declared foreign key properties from {associations.Count} association{(associations.Count == 1 ? "" : "s")}. Are you sure?"; if (associations.Any() && BooleanQuestionDisplay.Show(store, message) == true) { foreach (Association association in associations) { association.FKPropertyName = null; AssociationChangedRules.FixupForeignKeys(association); } } } ModelRoot.ExecuteValidator?.Invoke(); break; case "EntityOutputDirectory": if (string.IsNullOrEmpty(element.EnumOutputDirectory) || element.EnumOutputDirectory == (string)e.OldValue) { element.EnumOutputDirectory = (string)e.NewValue; } if (string.IsNullOrEmpty(element.StructOutputDirectory) || element.StructOutputDirectory == (string)e.OldValue) { element.StructOutputDirectory = (string)e.NewValue; } break; case "EnumOutputDirectory": if (string.IsNullOrEmpty((string)e.NewValue) && !string.IsNullOrEmpty(element.EntityOutputDirectory)) { element.EnumOutputDirectory = element.EntityOutputDirectory; } break; case "ExposeForeignKeys": if (!element.ExposeForeignKeys) { foreach (Association association in element.Store.GetAll <Association>() .Where(a => (a.SourceRole == EndpointRole.Dependent || a.TargetRole == EndpointRole.Dependent) && !string.IsNullOrWhiteSpace(a.FKPropertyName))) { association.FKPropertyName = null; AssociationChangedRules.FixupForeignKeys(association); } } break; case "FileNameMarker": string newFileNameMarker = (string)e.NewValue; if (!Regex.Match($"a.{newFileNameMarker}.cs", @"^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*:\"";|/]+$") .Success) { errorMessages.Add("Invalid value to make part of file name"); } break; case "GridColor": foreach (EFModelDiagram diagram in element.GetDiagrams()) { diagram.GridColor = (Color)e.NewValue; } redraw = true; break; case "InheritanceStrategy": if ((element.EntityFrameworkVersion == EFVersion.EFCore) && (element.NuGetPackageVersion.MajorMinorVersionNum < 2.1)) { element.InheritanceStrategy = CodeStrategy.TablePerHierarchy; } break; case "Namespace": errorMessages.Add(CommonRules.ValidateNamespace((string)e.NewValue, CodeGenerator.IsValidLanguageIndependentIdentifier)); break; case "ShowCascadeDeletes": // Normally you'd think that we should be able to register this in a AssociateValueWith call // in AssociationConnector, but that doesn't appear to work. So call the update method here. foreach (Association association in store.ElementDirectory.FindElements <Association>()) { PresentationHelper.UpdateAssociationDisplay(association); } redraw = true; break; case "ShowGrid": foreach (EFModelDiagram diagram in element.GetDiagrams()) { diagram.ShowGrid = (bool)e.NewValue; } redraw = true; break; case "ShowWarningsInDesigner": redraw = true; if ((bool)e.NewValue) { ModelRoot.ExecuteValidator?.Invoke(); } break; case "SnapToGrid": foreach (EFModelDiagram diagram in element.GetDiagrams()) { diagram.SnapToGrid = (bool)e.NewValue; } redraw = true; break; case "StructOutputDirectory": if (string.IsNullOrEmpty((string)e.NewValue) && !string.IsNullOrEmpty(element.EntityOutputDirectory)) { element.StructOutputDirectory = element.EntityOutputDirectory; } break; case "WarnOnMissingDocumentation": if (element.ShowWarningsInDesigner) { redraw = true; } ModelRoot.ExecuteValidator?.Invoke(); break; } errorMessages = errorMessages.Where(m => m != null).ToList(); if (errorMessages.Any()) { current.Rollback(); ErrorDisplay.Show(store, string.Join("\n", errorMessages)); } if (redraw) { foreach (EFModelDiagram diagram in element.GetDiagrams().Where(d => d.ActiveDiagramView != null)) { diagram.Invalidate(true); } } }
public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e) { base.ElementPropertyChanged(e); ModelRoot element = (ModelRoot)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; if (current.IsSerializing) { return; } if (Equals(e.NewValue, e.OldValue)) { return; } List <string> errorMessages = EFCoreValidator.GetErrors(element).ToList(); bool redraw = false; switch (e.DomainProperty.Name) { case "ConnectionString": if (e.NewValue != null) { element.ConnectionStringName = null; } break; case "ConnectionStringName": if (e.NewValue != null) { element.ConnectionString = null; } break; case "DatabaseSchema": if (string.IsNullOrEmpty((string)e.NewValue)) { element.DatabaseSchema = "dbo"; } break; case "EntityFrameworkVersion": element.EntityFrameworkPackageVersion = "Latest"; if (element.EntityFrameworkVersion == EFVersion.EFCore) { element.InheritanceStrategy = CodeStrategy.TablePerHierarchy; } break; case "EnumOutputDirectory": if (string.IsNullOrEmpty((string)e.NewValue) && !string.IsNullOrEmpty(element.EntityOutputDirectory)) { element.EnumOutputDirectory = element.EntityOutputDirectory; } break; case "StructOutputDirectory": if (string.IsNullOrEmpty((string)e.NewValue) && !string.IsNullOrEmpty(element.EntityOutputDirectory)) { element.StructOutputDirectory = element.EntityOutputDirectory; } break; case "EntityOutputDirectory": if (string.IsNullOrEmpty(element.EnumOutputDirectory) || element.EnumOutputDirectory == (string)e.OldValue) { element.EnumOutputDirectory = (string)e.NewValue; } if (string.IsNullOrEmpty(element.StructOutputDirectory) || element.StructOutputDirectory == (string)e.OldValue) { element.StructOutputDirectory = (string)e.NewValue; } break; case "FileNameMarker": string newFileNameMarker = (string)e.NewValue; if (!Regex.Match($"a.{newFileNameMarker}.cs", @"^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*:\"";|/]+$") .Success) { errorMessages.Add("Invalid value to make part of file name"); } break; case "InheritanceStrategy": if ((element.EntityFrameworkVersion == EFVersion.EFCore) && (element.NuGetPackageVersion.MajorMinorVersionNum < 2.1)) { element.InheritanceStrategy = CodeStrategy.TablePerHierarchy; } break; case "LayoutAlgorithm": ModelDisplay.LayoutDiagram(element.Classes.FirstOrDefault()?.GetActiveDiagram() as EFModelDiagram); break; case "Namespace": errorMessages.Add(CommonRules.ValidateNamespace((string)e.NewValue, CodeGenerator.IsValidLanguageIndependentIdentifier)); break; case "ShowCascadeDeletes": // Normally you'd think that we should be able to register this in a AssociateValueWith call // in AssociationConnector, but that doesn't appear to work. So call the update method here. foreach (Association association in store.ElementDirectory.FindElements <Association>()) { PresentationHelper.UpdateAssociationDisplay(association); } redraw = true; break; case "ShowWarningsInDesigner": redraw = true; break; case "WarnOnMissingDocumentation": if (element.ShowWarningsInDesigner) { redraw = true; } ModelRoot.ExecuteValidator?.Invoke(); break; } errorMessages = errorMessages.Where(m => m != null).ToList(); if (errorMessages.Any()) { current.Rollback(); ErrorDisplay.Show(string.Join("\n", errorMessages)); } if (redraw) { element.InvalidateDiagrams(); } }