コード例 #1
0
        private void UpdateSettingsFromGui()
        {
            if (!EscherAttributeContentValidator.IsValidCsdlEntityTypeName(entityNameTextBox.Text))
            {
                baseTypeComboBox.Enabled = false;
                entitySetTextBox.Enabled = false;
                groupBox2.Enabled        = false;
            }
            else
            {
                groupBox2.Enabled        = true;
                baseTypeComboBox.Enabled = true;

                if (BaseEntityType == null)
                {
                    entitySetTextBox.Enabled = true;
                    groupBox2.Enabled        = true;
                    var proposedEntitySetName = ModelHelper.ConstructProposedEntitySetName(_model.Artifact, EntityName);
                    entitySetTextBox.Text       = ModelHelper.GetUniqueName(typeof(EntitySet), _model.FirstEntityContainer, proposedEntitySetName);
                    keyPropertyCheckBox.Checked = true;
                }
                else
                {
                    keyPropertyCheckBox.Checked = false;
                    entitySetTextBox.Enabled    = false;
                    entitySetTextBox.Text       = BaseEntityType.EntitySet.LocalName.Value;
                    groupBox2.Enabled           = false;
                }
            }
        }
コード例 #2
0
        private static void PopluateReplacementDictionary(Project project, Dictionary <string, string> replacementsDictionary, string modelName)
        {
            // create a "fixed" version that removes non-valid characters and leading underscores
            var fixedModelName = XmlConvert.EncodeName(modelName).TrimStart('_');

            //  make sure that the model name is a valid xml attribute value
            if (!EscherAttributeContentValidator.IsValidXmlAttributeValue(fixedModelName))
            {
                VsUtils.ShowErrorDialog(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.ModelObjectItemWizard_NonValidXmlAttributeValue,
                        modelName));
                Marshal.ThrowExceptionForHR(VSConstants.E_ABORT);
            }

            // set the value to be used for namespace in blank models
            replacementsDictionary.Add("$namespace$", fixedModelName);

            // set the value to be used for EntityContainerName in blank models
            var entityContainerName = PackageManager.Package.ConnectionManager.ConstructUniqueEntityContainerName(
                fixedModelName + EntityContainerNameSuffix, project);

            replacementsDictionary.Add("$conceptualEntityContainerName$", entityContainerName);

            // set default value of the EnablePluralization flag dependent on current culture
            var pluralizationDefault = (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "en").ToString();

            replacementsDictionary.Add("$enablePluralization$", pluralizationDefault);
        }
コード例 #3
0
ファイル: Property.cs プロジェクト: rvegajr/entityframework
 private void ValidateName(ValidationContext context)
 {
     if (!EscherAttributeContentValidator.IsValidCsdlPropertyName(Name))
     {
         var message = String.Format(CultureInfo.CurrentCulture, Resources.Error_PropertyNameInvalid, Name);
         context.LogError(message, Properties.Resources.ErrorCode_PropertyNameInvalid, this);
     }
 }
コード例 #4
0
ファイル: EdmUtils.cs プロジェクト: phekmat/ef6
        // <summary>
        //     Returns a string which is valid as a model namespace given the
        //     proposedModelNamespace as a starting point.
        // </summary>
        // <param name="proposedModelNamespace">The proposed model namespace</param>
        // <param name="defaultModelNamespace">The model namespace to use if removal of invalid chars results in an empty string</param>
        internal static string ConstructValidModelNamespace(string proposedModelNamespace, string defaultModelNamespace)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(defaultModelNamespace), "defaultModelNamespace must not be null or empty");

            if (IsValidModelNamespace(proposedModelNamespace))
            {
                return(proposedModelNamespace);
            }

            if (String.IsNullOrEmpty(proposedModelNamespace))
            {
                return(defaultModelNamespace);
            }

            var trialModelNamespace = proposedModelNamespace.Replace("<", "").Replace(">", "").Replace("&", "");

            if (!EscherAttributeContentValidator.IsValidXmlAttributeValue(trialModelNamespace) ||
                string.IsNullOrEmpty(trialModelNamespace))
            {
                return(defaultModelNamespace);
            }

            if (IsValidModelNamespace(trialModelNamespace))
            {
                // if trialModelNamespace is now valid just return it
                return(trialModelNamespace);
            }

            // if trialModelNamespace is invalid must be an invalid identifier
            // try stripping any leading numbers
            while (trialModelNamespace.Length > 0 &&
                   !Char.IsLetter(trialModelNamespace[0]))
            {
                trialModelNamespace = trialModelNamespace.Substring(1);
            }

            if (String.IsNullOrEmpty(trialModelNamespace))
            {
                return(defaultModelNamespace);
            }

            if (IsValidModelNamespace(trialModelNamespace))
            {
                return(trialModelNamespace);
            }

            // try adding a one to the end
            trialModelNamespace += "1";
            if (IsValidModelNamespace(trialModelNamespace))
            {
                return(trialModelNamespace);
            }

            // give up and return default
            return(defaultModelNamespace);
        }
コード例 #5
0
        /// <summary>
        ///     Do the following when an EntityType changes:
        ///     - Update roles in related Associations
        /// </summary>
        /// <param name="e"></param>
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            // if the element is deleted or about to be deleted, this rule will get fired.
            // Just return immediately here because we don't care if the entity-type's property has changed.
            if (e.ModelElement.IsDeleted ||
                e.ModelElement.IsDeleting)
            {
                return;
            }

            var changedEntity = e.ModelElement as EntityType;

            Debug.Assert(changedEntity != null);
            Debug.Assert(changedEntity.EntityDesignerViewModel != null);

            if (changedEntity != null &&
                changedEntity.EntityDesignerViewModel != null)
            {
                var viewModel = changedEntity.EntityDesignerViewModel;
                var tx        = ModelUtils.GetCurrentTx(e.ModelElement.Store);
                Debug.Assert(tx != null);
                // don't do the auto update stuff if we are in the middle of deserialization
                if (tx != null &&
                    !tx.IsSerializing)
                {
                    // are they changing the name?
                    if (e.DomainProperty.Id == NameableItem.NameDomainPropertyId)
                    {
                        // if we are creating this Entity, there is no 'change' to do
                        if (viewModel.ModelXRef.GetExisting(changedEntity) == null)
                        {
                            return;
                        }

                        if (!EscherAttributeContentValidator.IsValidCsdlEntityTypeName(changedEntity.Name))
                        {
                            throw new InvalidOperationException(
                                      String.Format(CultureInfo.CurrentCulture, Resources.Error_EntityNameInvalid, changedEntity.Name));
                        }

                        if (ModelUtils.IsUniqueName(changedEntity, changedEntity.Name, viewModel.EditingContext) == false)
                        {
                            throw new InvalidOperationException(
                                      String.Format(CultureInfo.CurrentCulture, Resources.Error_EntityNameDuplicate, changedEntity.Name));
                        }

                        ViewModelChangeContext.GetNewOrExistingContext(tx).ViewModelChanges.Add(new EntityTypeChange(changedEntity));
                    }
                }
            }
        }
コード例 #6
0
 private void associationNameTextBox_TextChanged(object sender, EventArgs e)
 {
     if (!EscherAttributeContentValidator.IsValidCsdlAssociationName(AssociationName))
     {
         end1GroupBox.Enabled = false;
         end2GroupBox.Enabled = false;
     }
     else
     {
         end1GroupBox.Enabled = true;
         end2GroupBox.Enabled = true;
     }
 }
コード例 #7
0
 private void ValidateNamespace(ValidationContext context)
 {
     if (String.IsNullOrEmpty(this.Namespace))
     {
         string message = String.Format(CultureInfo.CurrentCulture, Properties.Resources.Error_ModelNamespaceEmpty);
         context.LogError(message, Properties.Resources.ErrorCode_ModelNamespaceEmpty, this);
     }
     else if (EscherAttributeContentValidator.IsValidCSDLNamespaceName(this.Namespace) == false)
     {
         string message = String.Format(CultureInfo.CurrentCulture, Properties.Resources.Error_ModelNamespaceInvalid, this.Namespace);
         context.LogError(message, Properties.Resources.ErrorCode_ModelNamespaceInvalid, this);
     }
 }
コード例 #8
0
        public string this[string propertyName]
        {
            get
            {
                if (Parent == null ||
                    (String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Value)))
                {
                    return(String.Empty);
                }

                var sb = new StringBuilder();

                if (propertyName == null ||
                    propertyName == "Name")
                {
                    if (string.IsNullOrWhiteSpace(Name) ||
                        !EscherAttributeContentValidator.IsValidCsdlEnumMemberName(Name))
                    {
                        sb.AppendLine(String.Format(CultureInfo.CurrentCulture, Resources.EnumDialog_ErrorEnumMemberBadname, Name));
                    }
                    else if (Parent.Members.Count(etm => String.Compare(etm.Name, Name, StringComparison.CurrentCulture) == 0) > 1)
                    {
                        sb.AppendLine(
                            String.Format(CultureInfo.CurrentCulture, Resources.EnumDialog_ErrorEnumMemberDuplicateName, Name));
                    }
                }

                if (propertyName == null ||
                    propertyName == "Value")
                {
                    if (string.IsNullOrEmpty(Value) == false) // we will validate if the user entered white spaces.
                    {
                        var type =
                            ModelHelper.UnderlyingEnumTypes.FirstOrDefault(
                                t => String.CompareOrdinal(t.Name, Parent.SelectedUnderlyingType) == 0);

                        Debug.Assert(
                            type != null,
                            "The type :" + Parent.SelectedUnderlyingType + " is not a valid underlying type for an enum.");

                        // if value is not null or empty, we will validate the input based on enum type's underlying type.
                        if (type != null &&
                            ModelHelper.IsValidValueForType(type, Value) == false)
                        {
                            sb.AppendLine(String.Format(CultureInfo.CurrentCulture, Model.Resources.BadEnumTypeMemberValue, Value));
                        }
                    }
                }
                return(sb.ToString());
            }
        }
コード例 #9
0
 internal override void DetermineIfArtifactIsDesignerSafe()
 {
     // XmlSchemaValidator by default does not report any errors or warning if the namespace of the validated document
     // does not match the targetNamespace in the schema considering the schema not being applicable. With XmlReader
     // it is possible to pass XmlSchemaValidationFlags.ReportValidationWarnings to be notified if this happens. However
     // it is not possible to pass this flag when using XDocument.Validate. Therefore before trying to validate the Xml
     // we just check that this is a known edmx namespace. If it is not we set the flag to false and skip validating.
     if (IsDesignerSafe = SchemaManager.GetEDMXNamespaceNames().Contains(XDocument.Root.Name.NamespaceName))
     {
         XDocument.Validate(
             EscherAttributeContentValidator.GetInstance(SchemaVersion).EdmxSchemaSet,
             (sender, args) => IsDesignerSafe = false);
     }
 }
コード例 #10
0
 // <summary>
 //     This method will return validation error for a given property (if there is one).
 // </summary>
 public string this[string propertyName]
 {
     get
     {
         if (propertyName == "Name")
         {
             string errorMessage;
             if (string.IsNullOrWhiteSpace(_name) ||
                 !EscherAttributeContentValidator.IsValidCsdlEnumTypeName(_name))
             {
                 return(String.Format(CultureInfo.CurrentCulture, Resources.EnumDialog_ErrorEnumTypeBadname, _name));
             }
             else if (IsNew &&
                      ModelHelper.IsUniqueName(typeof(EnumType), _artifact.ConceptualModel, _name, true, out errorMessage)
                      == false)
             {
                 return(Resources.EnumDialog_EnsureEnumTypeUnique);
             }
             // if the name has changed, ensure that it will be unique across other types.
             else if (IsNew == false &&
                      string.CompareOrdinal(_enumType.Name.Value, Name) != 0 &&
                      ModelHelper.IsUniqueNameForExistingItem(_enumType, Name, true, out errorMessage) == false)
             {
                 return(errorMessage);
             }
         }
         else if (propertyName == "ExternalTypeName")
         {
             if (IsReferenceExternalType && String.IsNullOrWhiteSpace(ExternalTypeName))
             {
                 return(Resources.EnumDialog_ErrorEnterValueForExternalTypeName);
             }
         }
         return(String.Empty);
     }
 }
コード例 #11
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            if (null == _conceptualEntityModel)
            {
                Debug.Fail("Null ConceptualEntityModel");
                return;
            }

            var artifact = _conceptualEntityModel.Artifact;

            if (null == artifact)
            {
                Debug.Fail("Null Artifact");
                return;
            }

            var artifactSet = artifact.ArtifactSet;

            if (null == artifactSet)
            {
                Debug.Fail("Null ArtifactSet");
                return;
            }

            // make sure this name doesn't conflict with an EntityContainer name
            foreach (var bec in _conceptualEntityModel.EntityContainers())
            {
                if (_newNamespace == bec.LocalName.Value)
                {
                    var msg = string.Format(
                        CultureInfo.CurrentCulture, Resources.EntityContainerNameConflictsWithNamespaceName, _newNamespace);
                    throw new CommandValidationFailedException(msg);
                }
            }

            // check to see if the new namespace is valid
            if (EscherAttributeContentValidator.GetInstance(artifact.SchemaVersion)
                .IsValidAttributeValue(_newNamespace, _conceptualEntityModel.Namespace))
            {
                var previousConceptualNamespace = _conceptualEntityModel.Namespace.Value;
                if (string.IsNullOrEmpty(previousConceptualNamespace))
                {
                    Debug.Fail("Null or empty conceptual namespace");
                    return;
                }

                // find all Symbols in the ArtifactSet which have first part
                // equal to existing previousConceptualNamespace
                var allElementsWithConceptualNamespaceSymbol =
                    artifactSet.GetElementsContainingFirstSymbolPart(previousConceptualNamespace);

                // change all references which include the namespace to the new namespace
                foreach (var element in allElementsWithConceptualNamespaceSymbol)
                {
                    var itemBindings = element.GetDependentBindings();
                    foreach (var itemBinding in itemBindings)
                    {
                        itemBinding.UpdateRefNameNamespaces(
                            previousConceptualNamespace, _newNamespace);
                    }
                }

                // now update the namespace attribute itself
                _conceptualEntityModel.Namespace.Value = _newNamespace;

                // symbols need to be recalculated throughout the
                // CSDL, MSL & DesignerInfo sections, and bindings need to be rebound ...
                XmlModelHelper.NormalizeAndResolve(_conceptualEntityModel);
                if (artifact.MappingModel() != null)
                {
                    XmlModelHelper.NormalizeAndResolve(artifact.MappingModel());
                }
                if (artifact.DesignerInfo() != null)
                {
                    XmlModelHelper.NormalizeAndResolve(artifact.DesignerInfo());
                }
            }
            else
            {
                // if not a valid namespace, throw an error message
                var msg = string.Format(CultureInfo.CurrentCulture, Resources.InvalidNamespaceName, _newNamespace);
                throw new CommandValidationFailedException(msg);
            }
        }
コード例 #12
0
        /// <summary>
        ///     Do the following when an Entity changes:
        ///     - Update roles in related Associations
        /// </summary>
        /// <param name="e"></param>
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            var changedNavigationProperty = e.ModelElement as NavigationProperty;

            Debug.Assert(changedNavigationProperty != null);
            Debug.Assert(
                changedNavigationProperty.EntityType != null && changedNavigationProperty.EntityType.EntityDesignerViewModel != null);

            if ((changedNavigationProperty != null) &&
                (changedNavigationProperty.EntityType != null) &&
                (changedNavigationProperty.EntityType.EntityDesignerViewModel != null))
            {
                var tx = ModelUtils.GetCurrentTx(e.ModelElement.Store);
                Debug.Assert(tx != null);
                // don't do the auto update stuff if we are in the middle of deserialization
                if (tx != null &&
                    !tx.IsSerializing)
                {
                    var viewModel = changedNavigationProperty.EntityType.EntityDesignerViewModel;

                    if (e.DomainProperty.Id == NameableItem.NameDomainPropertyId)
                    {
                        // if we are creating this, the old name will be empty so there is no 'change' to do
                        if (String.IsNullOrEmpty((string)e.OldValue))
                        {
                            return;
                        }

                        if (!EscherAttributeContentValidator.IsValidCsdlNavigationPropertyName(changedNavigationProperty.Name))
                        {
                            throw new InvalidOperationException(
                                      String.Format(
                                          CultureInfo.CurrentCulture, Resources.Error_NavigationPropertyNameInvalid,
                                          changedNavigationProperty.Name));
                        }

                        var modelEntityType =
                            viewModel.ModelXRef.GetExisting(changedNavigationProperty.EntityType) as Model.Entity.EntityType;
                        Debug.Assert(modelEntityType != null, "modelEntityType is null");

                        // ensure name is unique
                        if (modelEntityType.LocalName.Value.Equals(changedNavigationProperty.Name, StringComparison.Ordinal))
                        {
                            var msg = string.Format(
                                CultureInfo.CurrentCulture, Model.Resources.Error_MemberNameSameAsParent, changedNavigationProperty.Name,
                                modelEntityType.LocalName.Value);
                            throw new InvalidOperationException(msg);
                        }
                        else if (!EDMModelUtils.IsUniquePropertyName(modelEntityType, changedNavigationProperty.Name, true))
                        {
                            var msg = string.Format(
                                CultureInfo.CurrentCulture, Model.Resources.Error_MemberNameNotUnique, changedNavigationProperty.Name,
                                modelEntityType.LocalName.Value);
                            throw new InvalidOperationException(msg);
                        }

                        ViewModelChangeContext.GetNewOrExistingContext(tx)
                        .ViewModelChanges.Add(new NavigationPropertyChange(changedNavigationProperty));
                    }
                }
            }
        }
コード例 #13
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (_needsValidation)
            {
                _needsValidation = false;
                string msg = null;

                if (!EscherAttributeContentValidator.IsValidCsdlAssociationName(AssociationName))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewAssociationDialog_InvalidAssociationNameMsg);
                    e.Cancel = true;
                    associationNameTextBox.Focus();
                }
                else if (navigationPropertyCheckbox.Checked &&
                         !EscherAttributeContentValidator.IsValidCsdlNavigationPropertyName(End1NavigationPropertyName))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewAssociationDialog_InvalidNavigationPropertyNameMsg);
                    e.Cancel = true;
                    navigationProperty1TextBox.Focus();
                }
                else if (navigationProperty2Checkbox.Checked &&
                         !EscherAttributeContentValidator.IsValidCsdlNavigationPropertyName(End2NavigationPropertyName))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewAssociationDialog_InvalidNavigationPropertyNameMsg);
                    e.Cancel = true;
                    navigationProperty2TextBox.Focus();
                }
                else if (!ModelHelper.IsUniqueName(typeof(Association), End1Entity.Parent, AssociationName, false, out msg))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewAssociationDialog_EnsureUniqueNameMsg);
                    e.Cancel = true;
                    associationNameTextBox.Focus();
                }
                else if (navigationPropertyCheckbox.Checked &&
                         End1NavigationPropertyName.Equals(End1Entity.LocalName.Value, StringComparison.Ordinal))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.SameEntityAndPropertyNameMsg);
                    e.Cancel = true;
                    navigationProperty1TextBox.Focus();
                }
                else if (navigationPropertyCheckbox.Checked &&
                         !ModelHelper.IsUniquePropertyName(End1Entity, End1NavigationPropertyName, true))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewAssociationDialog_EnsureUniquePropertyNameMsg);
                    e.Cancel = true;
                    navigationProperty1TextBox.Focus();
                }
                else if (End2NavigationPropertyName.Equals(End2Entity.LocalName.Value, StringComparison.Ordinal))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.SameEntityAndPropertyNameMsg);
                    e.Cancel = true;
                    navigationProperty2TextBox.Focus();
                }
                else if (navigationProperty2Checkbox.Checked &&
                         !ModelHelper.IsUniquePropertyName(End2Entity, End2NavigationPropertyName, true) ||
                         (End1Entity == End2Entity && navigationProperty2Checkbox.Checked &&
                          End2NavigationPropertyName.Equals(End1NavigationPropertyName, StringComparison.Ordinal)))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewAssociationDialog_EnsureUniquePropertyNameMsg);
                    e.Cancel = true;
                    navigationProperty2TextBox.Focus();
                }
            }
        }
コード例 #14
0
ファイル: EdmUtils.cs プロジェクト: phekmat/ef6
 // <summary>
 //     Returns whether the proposedModelNamespace is valid as a model namespace.
 // </summary>
 // <param name="proposedModelNamespace">The proposed model namespace</param>
 internal static bool IsValidModelNamespace(string proposedModelNamespace)
 {
     return
         (!string.IsNullOrEmpty(proposedModelNamespace) &&
          EscherAttributeContentValidator.IsValidCsdlNamespaceName(proposedModelNamespace));
 }
コード例 #15
0
ファイル: VSArtifact.cs プロジェクト: rvegajr/entityframework
        internal override bool IsXmlValid()
        {
            // If there is a VSXmlModelProvider, we should be able to find a docdata for it.
            // In any other case, it doesn't matter whether there is document data or not.
            var docData = VSHelpers.GetDocData(PackageManager.Package, Uri.LocalPath);

            Debug.Assert(
                !(XmlModelProvider is VSXmlModelProvider) || docData != null, "Using a VSXmlModelProvider but docData is null for Artifact!");

            try
            {
                XmlDocument xmldoc;
                if (docData != null)
                {
                    var textLines = VSHelpers.GetVsTextLinesFromDocData(docData);
                    Debug.Assert(textLines != null, "Failed to get IVSTextLines from docdata");

                    xmldoc = EdmUtils.SafeLoadXmlFromString(VSHelpers.GetTextFromVsTextLines(textLines));
                }
                else
                {
                    // If there is no docdata then attempt to create the XmlDocument from the internal
                    // XLinq tree in the artifact
                    xmldoc = new XmlDocument();
                    xmldoc.Load(XDocument.CreateReader());
                }
                // For the most part, the Edmx schema version of an artifact should be in sync with the schema version
                // that is compatible with the project's target framework; except when the user adds an existing edmx to a project (the version could be different).
                // For all cases, we always want to validate using the XSD's version that matches the artifact's version.
                var documentSchemaVersion = base.SchemaVersion;
                Debug.Assert(
                    EntityFrameworkVersion.IsValidVersion(documentSchemaVersion),
                    "The EF Schema Version is not valid. Value:"
                    + (documentSchemaVersion != null ? documentSchemaVersion.ToString() : "null"));

                // does the XML parse? If not, the load call below will throw
                if (EntityFrameworkVersion.IsValidVersion(documentSchemaVersion))
                {
                    var nsMgr = SchemaManager.GetEdmxNamespaceManager(xmldoc.NameTable, documentSchemaVersion);
                    // Do XSD validation on the document.
                    xmldoc.Schemas = EscherAttributeContentValidator.GetInstance(documentSchemaVersion).EdmxSchemaSet;
                    var svec = new SchemaValidationErrorCollector();

                    // remove runtime specific lines
                    // find the ConceptualModel Schema node
                    RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Configurations", nsMgr);
                    RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels", nsMgr);
                    RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Runtime/edmx:StorageModels", nsMgr);
                    RemoveRunTimeNode(xmldoc, "/edmx:Edmx/edmx:Runtime/edmx:Mappings", nsMgr);

                    xmldoc.Validate(svec.ValidationCallBack);

                    return(svec.ErrorCount == 0);
                }
            }
            catch
            {
            }

            return(false);
        }
コード例 #16
0
 internal override AttributeContentValidator GetAttributeContentValidator(EFArtifact artifact)
 {
     return(EscherAttributeContentValidator.GetInstance(artifact.SchemaVersion));
 }
コード例 #17
0
        internal override bool OnWizardFinish()
        {
            using (new VsUtils.HourglassHelper())
            {
                UpdateSettingsFromGui();
            }

            //
            // validate app config connection name
            //
            if (checkBoxSaveInAppConfig.Checked)
            {
                var id = textBoxAppConfigConnectionName.Text;
                if (!EscherAttributeContentValidator.IsValidCsdlEntityContainerName(id) ||
                    !_identifierUtil.IsValidIdentifier(id))
                {
                    VsUtils.ShowErrorDialog(
                        string.Format(CultureInfo.CurrentCulture, Resources.ConnectionStringNonValidIdentifier, id));
                    textBoxAppConfigConnectionName.Focus();
                    _isFocusSet = true;
                    return(false);
                }

                // only check that the connection string name is new if started in
                // 'PerformAllFunctionality' mode
                if (ModelBuilderWizardForm.WizardMode.PerformAllFunctionality == Wizard.Mode)
                {
                    string connectionString;
                    if (ConnectionManager.GetExistingConnectionStrings(_configFileUtils).TryGetValue(id, out connectionString) &&
                        !string.Equals(textBoxConnectionString.Text, connectionString, StringComparison.Ordinal))
                    {
                        VsUtils.ShowErrorDialog(
                            string.Format(CultureInfo.CurrentCulture, Resources.ConnectionStringDuplicateIdentifer, id));
                        textBoxAppConfigConnectionName.Focus();
                        _isFocusSet = true;
                        return(false);
                    }
                }
            }

            // the Model Namespace and the Entity Container name must differ
            if (ModelBuilderWizardForm.ModelNamespaceAndEntityContainerNameSame(Wizard.ModelBuilderSettings))
            {
                var s = Resources.NamespaceAndEntityContainerSame;
                VsUtils.ShowErrorDialog(
                    String.Format(CultureInfo.CurrentCulture, s, Wizard.ModelBuilderSettings.AppConfigConnectionPropertyName));
                textBoxAppConfigConnectionName.Focus();
                _isFocusSet = true;
                return(false);
            }

            try
            {
                // this might cause dataConnection to include some sensitive data into connectionString
                // the Open function also can cause DDEX to put up a prompt for the username/password for an existing connection
                // that does not have any saved password information.
                _dataConnection.Open();

                if (!IsDataValid)
                {
                    sensitiveInfoTextBox.Enabled        = true;
                    allowSensitiveInfoButton.Checked    = false;
                    allowSensitiveInfoButton.Enabled    = true;
                    disallowSensitiveInfoButton.Checked = false;
                    disallowSensitiveInfoButton.Enabled = true;

                    var result = VsUtils.ShowMessageBox(
                        PackageManager.Package,
                        Resources.SensitiveDataInfoText,
                        OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_THIRD,
                        OLEMSGICON.OLEMSGICON_QUERY);

                    switch (result)
                    {
                    case DialogResult.Yes:
                        allowSensitiveInfoButton.Checked = true;
                        break;

                    case DialogResult.No:
                        disallowSensitiveInfoButton.Checked = true;
                        break;

                    default:
                        Wizard.OnValidationStateChanged(this);
                        return(false);
                    }
                }
            }
            catch (DataConnectionOpenCanceledException)
            {
                return(false);
            }
            catch (Exception e)
            {
                // show error dialog
                ModelBuilderWizardForm.ShowDatabaseConnectionErrorDialog(e);

                return(false);
            }
            finally
            {
                if (_dataConnection.State != DataConnectionState.Closed)
                {
                    _dataConnection.Close();
                }
            }

            return(true);
        }
コード例 #18
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (_needsValidation)
            {
                _needsValidation = false;

                if (!EscherAttributeContentValidator.IsValidCsdlEntityTypeName(entityNameTextBox.Text))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_InvalidEntityNameMsg);
                    e.Cancel = true;
                    entityNameTextBox.Focus();
                }
                else
                {
                    string msg;
                    if (!ModelHelper.IsUniqueName(typeof(EntityType), _model, entityNameTextBox.Text, false, out msg))
                    {
                        VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_EnsureUniqueNameMsg);
                        e.Cancel = true;
                        entityNameTextBox.Focus();
                        return;
                    }

                    if (entitySetTextBox.Enabled)
                    {
                        if (!EscherAttributeContentValidator.IsValidCsdlEntitySetName(EntitySetName))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_InvalidEntitySetMsg);
                            e.Cancel = true;
                            entitySetTextBox.Focus();
                            return;
                        }

                        if (!ModelHelper.IsUniqueName(typeof(EntitySet), _model.FirstEntityContainer, EntitySetName, false, out msg))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_EnsureUniqueSetNameMsg);
                            e.Cancel = true;
                            entitySetTextBox.Focus();
                            return;
                        }
                    }

                    if (propertyNameTextBox.Enabled)
                    {
                        if (!EscherAttributeContentValidator.IsValidCsdlPropertyName(propertyNameTextBox.Text))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_InvalidKeyPropertyNameMsg);
                            e.Cancel = true;
                            propertyNameTextBox.Focus();
                            return;
                        }
                        else if (propertyNameTextBox.Text.Equals(EntityName, StringComparison.Ordinal))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.SameEntityAndPropertyNameMsg);
                            e.Cancel = true;
                            propertyNameTextBox.Focus();
                            return;
                        }
                    }
                }
            }
        }