private bool ValidateName(out string errorMessage) { // Unlike C# and TSql refactoring, we won't allow the user to proceed with a rename that causes a name conflict (C# and TSql // give a warning and allow you to proceed). This is because our rename command will fail in the case of name conflicts, so // we need return a hard error in the rename dialog. EFAttribute attr = _objectToRename.GetNameAttribute(); errorMessage = null; AttributeContentValidator contentValidator = _objectToRename.Artifact.ModelManager.GetAttributeContentValidator(_objectToRename.Artifact); if (!contentValidator.IsValidAttributeValue(this.NewName, attr)) { // not valid content errorMessage = Microsoft.Data.Entity.Design.Resources.RefactorRename_InvalidName; return(false); } Property property = _objectToRename as Property; if (_objectToRename is EntityType) { if (!ModelHelper.IsUniqueNameForExistingItem(_objectToRename, this.NewName, true, out errorMessage)) { return(false); } } else if (property != null) { if (!ModelHelper.IsUniqueNameForExistingItem(property, this.NewName, true, out errorMessage)) { errorMessage = string.Format(CultureInfo.CurrentCulture, Microsoft.Data.Entity.Design.Model.Resources.NAME_NOT_UNIQUE, this.NewName); return(false); } } else if (_objectToRename is Association) { if (!ModelHelper.IsUniqueNameForExistingItem(_objectToRename, this.NewName, true, out errorMessage)) { return(false); } } return(true); }
/// <summary> /// Returns true if the proposed string is valid for the given attribute's XSD schema type /// </summary> internal override bool IsValidAttributeValue(string proposedString, EFAttribute attribute) { if (attribute.XObject == null) { // attribute isn't hooked up into an xlinq tree, so we can't validate it. return true; } var nameStack = MakeAttributePathFromEFObject(attribute); if (nameStack == null) { return true; } else { return IsValidStringForSchemaType(proposedString, nameStack); } }
/// <summary> /// Returns true if the proposed string is valid for the given attribute's XSD schema type /// </summary> internal override bool IsValidAttributeValue(string proposedString, EFAttribute attribute) { if (attribute.XObject == null) { // attribute isn't hooked up into an xlinq tree, so we can't validate it. return(true); } var nameStack = MakeAttributePathFromEFObject(attribute); if (nameStack == null) { return(true); } else { return(IsValidStringForSchemaType(proposedString, nameStack)); } }
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); }
/// <summary> /// Returns true if the proposed string is valid for the given attribute's XSD schema type /// </summary> /// <param name="proposedString"></param> /// <param name="attribute"></param> /// <returns></returns> internal abstract bool IsValidAttributeValue(string proposedString, EFAttribute attribute);