コード例 #1
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(_element != null, "InvokeIntenal is called when _element is null");

            if (_element == null)
            {
                throw new InvalidOperationException();
            }

            if (_rebindAllBindings)
            {
                CheckArtifactBindings.ScheduleChildAntiDependenciesForRebinding(cpc, _element);
            }

            // delete the item
            _element.Delete();
        }
コード例 #2
0
ファイル: RenameCommand.cs プロジェクト: dotnet/ef6tools
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(Element != null);

            // check to see if this name is valid
            EFAttribute attr = Element.GetNameAttribute();

            var contentValidator = Element.Artifact.ModelManager.GetAttributeContentValidator(Element.Artifact);

            Debug.Assert(contentValidator != null, "Attribute content validator is null");
            if (!contentValidator.IsValidAttributeValue(NewName, attr))
            {
                // not valid content
                var msg = string.Format(CultureInfo.CurrentCulture, Resources.INVALID_NC_NAME_CHAR, NewName);
                throw new CommandValidationFailedException(msg);
            }

            string errorMessage = null;

            if (!IsUniqueNameForExistingItem(out errorMessage))
            {
                if (String.IsNullOrEmpty(errorMessage))
                {
                    errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.NAME_NOT_UNIQUE, NewName);
                }
                throw new CommandValidationFailedException(errorMessage);
            }

            RenameRelatedElements(cpc);

            // before doing the rename, identify any binding that was referencing this node or a child of this node,
            // and add it to the list of things to rebind
            CheckArtifactBindings.ScheduleChildAntiDependenciesForRebinding(cpc, Element);

            // Get the list of anti-dependencies before doing the rename, normalize and resolve steps.
            // This way all dependent items, including child elements which get unbound during NormalizeAndResolve, are included in the antiDeps list.
            var antiDeps = new List <EFObject>();

            antiDeps.AddRange(Element.GetAntiDependencies());

            // do the rename
            Element.Rename(NewName);
            XmlModelHelper.NormalizeAndResolve(Element);

            // now update any items that point to this item so that they use the new name
            foreach (var efObject in antiDeps)
            {
                var binding = efObject as ItemBinding;
                if (binding != null)
                {
                    binding.SetRefName(Element);
                }
            }

            // identify any binding that was referencing this node or a child of this node,
            // and add it to the list of things to rebind
            CheckArtifactBindings.ScheduleChildAntiDependenciesForRebinding(cpc, Element);

            // schedule unknown symbols for rebinding, since they may be fixed by the rename
            CheckArtifactBindings.ScheduleUnknownBindingsForRebind(cpc, Element.Artifact.ArtifactSet);
        }