internal static IEnumerable<Command> LaunchReferentialConstraintDialog(Association association) { var commands = new List<Command>(); if (association != null) { if (association.ReferentialConstraint == null || (association.ReferentialConstraint != null && association.ReferentialConstraint.Principal != null && association.ReferentialConstraint.Principal.Role.Target != null && association.ReferentialConstraint.Principal.Role.Target.Type.Target != null && association.ReferentialConstraint.Dependent != null && association.ReferentialConstraint.Dependent.Role.Target != null && association.ReferentialConstraint.Dependent.Role.Target.Type.Target != null ) ) { using (var dlg = new ReferentialConstraintDialog(association)) { var result = dlg.ShowDialog(); if (result != DialogResult.Cancel && dlg.Principal != null && dlg.Dependent != null) { if (association.ReferentialConstraint != null) { // first, enqueue the delete command (always) commands.Add(association.ReferentialConstraint.GetDeleteCommand()); } if (dlg.ShouldDeleteOnly == false) { var principalProps = new List<Property>(); var dependentProps = new List<Property>(); var keys = GetKeysForType(dlg.Principal.Type.Target); foreach (var mli in dlg.MappingList) { if (mli.IsValidPrincipalKey) { // try to resolve the symbol into a property Property p = null; Property d = null; if (mli.PrincipalKey != null) { p = GetKeyForType(mli.PrincipalKey, dlg.Principal.Type.Target, keys); } if (mli.DependentProperty != null) { d = dlg.Dependent.Artifact.ArtifactSet.LookupSymbol(mli.DependentProperty) as Property; } if (p != null && d != null) { principalProps.Add(p); dependentProps.Add(d); } } } // now enqueue the command to create a new one if the user didn't click Delete Debug.Assert( principalProps.Count == dependentProps.Count, "principal (" + principalProps.Count + ") & dependent (" + dependentProps.Count + ") property counts must match!"); if (principalProps.Count > 0) { Command cmd = new CreateReferentialConstraintCommand( dlg.Principal, dlg.Dependent, principalProps, dependentProps); commands.Add(cmd); } } } } } else { VsUtils.ShowMessageBox( PackageManager.Package, Resources.Error_CannotEditRefConstraint, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_WARNING); } } return commands; }
internal static IEnumerable <Command> LaunchReferentialConstraintDialog(Association association) { var commands = new List <Command>(); if (association != null) { if (association.ReferentialConstraint == null || (association.ReferentialConstraint != null && association.ReferentialConstraint.Principal != null && association.ReferentialConstraint.Principal.Role.Target != null && association.ReferentialConstraint.Principal.Role.Target.Type.Target != null && association.ReferentialConstraint.Dependent != null && association.ReferentialConstraint.Dependent.Role.Target != null && association.ReferentialConstraint.Dependent.Role.Target.Type.Target != null ) ) { using (var dlg = new ReferentialConstraintDialog(association)) { var result = dlg.ShowDialog(); if (result != DialogResult.Cancel && dlg.Principal != null && dlg.Dependent != null) { if (association.ReferentialConstraint != null) { // first, enqueue the delete command (always) commands.Add(association.ReferentialConstraint.GetDeleteCommand()); } if (dlg.ShouldDeleteOnly == false) { var principalProps = new List <Property>(); var dependentProps = new List <Property>(); var keys = GetKeysForType(dlg.Principal.Type.Target); foreach (var mli in dlg.MappingList) { if (mli.IsValidPrincipalKey) { // try to resolve the symbol into a property Property p = null; Property d = null; if (mli.PrincipalKey != null) { p = GetKeyForType(mli.PrincipalKey, dlg.Principal.Type.Target, keys); } if (mli.DependentProperty != null) { d = dlg.Dependent.Artifact.ArtifactSet.LookupSymbol(mli.DependentProperty) as Property; } if (p != null && d != null) { principalProps.Add(p); dependentProps.Add(d); } } } // now enqueue the command to create a new one if the user didn't click Delete Debug.Assert( principalProps.Count == dependentProps.Count, "principal (" + principalProps.Count + ") & dependent (" + dependentProps.Count + ") property counts must match!"); if (principalProps.Count > 0) { Command cmd = new CreateReferentialConstraintCommand( dlg.Principal, dlg.Dependent, principalProps, dependentProps); commands.Add(cmd); } } } } } else { VsUtils.ShowMessageBox( PackageManager.Package, Resources.Error_CannotEditRefConstraint, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_WARNING); } } return(commands); }