private void ValidateXmlName(ValidationContext context) { if (string.IsNullOrEmpty(this.XmlName) && !this.IsDefaultCollection) { context.LogError("The Xml Name is required and cannot be an empty string.", "RequiredProperty", this); } if (!NamingHelper.IsValidOrEmptyXmlName(this.XmlName)) { context.LogError(Resources.Error_InvalidName, "RequiredProperty", this); } }
protected override void OnNameChanged(EventArgs e) { // When the name changes, set the XML name to the same name but camelCased. this.XmlSectionName = NamingHelper.ToCamelCase(this.Name); // Always call the base class method. base.OnNameChanged(e); /* * foreach (BaseConfigurationType type in this.ConfigurationSectionModel.ConfigurationElements) * { * var element = type as ConfigurationElement; * IConfigSectionElement configSectionElement = type as IConfigSectionElement; * }*/ }
private void ValidatePropertyNames(ValidationContext context) { foreach (ConfigurationProperty property in Properties) { if (property.Name == this.Name) { context.LogError("An element cannot have a property with the same name as its own name.", "InvalidName", property); break; } if (!NamingHelper.IsValidOrEmptyName(this.Name)) { context.LogError(Resources.Error_InvalidName, "RequiredProperty", this); break; } } IEnumerable <BaseConfigurationType> ancestors; if (!GetAncestors(out ancestors)) { foreach (ConfigurationProperty property in Properties) { foreach (BaseConfigurationType ancestor in ancestors) { if (ancestor == this) { continue; } ConfigurationElement element = ancestor as ConfigurationElement; if (element == null) { continue; } foreach (ConfigurationProperty ancestralProperty in element.Properties) { if (property.Name == ancestralProperty.Name) { context.LogWarning(string.Format("The {1} property on {0} will shadow the {1} property on {2}", this.Name, property.Name, element.Name), "ShadowWarning", this, ancestor); goto nextProperty; } } } nextProperty :; } } }
protected override void OnValueChanged(ConfigurationProperty element, string oldValue, string newValue) { if (!element.Store.InUndoRedoOrRollback) { // Hard validation of the new name. if (string.IsNullOrEmpty(newValue)) { throw new ArgumentException("The Name is required and cannot be an empty string.", newValue); } // When the name changes, set the XML name to the same name but camelCased. element.XmlName = NamingHelper.ToCamelCase(element.Name); } // Always call the base class method. base.OnValueChanged(element, oldValue, newValue); }
private void ValidateName(ValidationContext context) { Debug.WriteLine("ConfigurationProperty.ValidateName called for " + this.Name); // CALLED! // TODO: Should verify IsDefaultCollection validition is enforced or check if parent element is a collection. NamingHelper.ValidationOptions options = NamingHelper.ValidationOptions.None; if (NamingHelper.RequiresValidation(this.Name, this, out options)) { Debug.WriteLine(" - ConfigurationProperty.ValidateName: Reqiures validation!"); string msg = ""; if (!NamingHelper.TryValidateAttributesItemNameProperty(this.Name, this.Name, options, out msg)) { context.LogError(msg, "RequiredProperty", this); } } }
private void ValidateNamespaces(ValidationContext context) { if (string.IsNullOrEmpty(this.Namespace)) { context.LogError("The Namespace is required and cannot be an empty string.", "RequiredProperty", this); } if (!NamingHelper.IsValidName(this.Namespace)) { context.LogError(Resources.Error_InvalidNamespace, "RequiredProperty", this); } if (string.IsNullOrEmpty(this.XmlSchemaNamespace)) { context.LogError("The XML Schema Namespace is required and cannot be an empty string.", "RequiredProperty", this); } if (!NamingHelper.IsValidXmlName(this.XmlSchemaNamespace)) { context.LogError(Resources.Error_InvalidXmlNamespace, "RequiredProperty", this); } }
protected override void OnValueChanged(TypeBase element, string oldValue, string newValue) { if (!element.Store.InUndoRedoOrRollback) { // Hard validation of the new name. if (string.IsNullOrEmpty(newValue)) { throw new ArgumentException("The Name is required and cannot be an empty string.", newValue); } if (!NamingHelper.IsValidName(newValue)) { throw new ArgumentException(Resources.Error_InvalidName, newValue); } // Raise the NameChanged event for derived classes to act upon. element.OnNameChanged(EventArgs.Empty); } // Always call the base class method. base.OnValueChanged(element, oldValue, newValue); }
protected override void OnValueChanged(ConfigurationProperty element, string oldValue, string newValue) { /* * // Accessing validator. * Microsoft.VisualStudio.Modeling.Shell.VsValidationController validator = new Microsoft.VisualStudio.Modeling.Shell.VsValidationController(element.Store); * if (!validator.Validate(element.Store, ValidationCategories.Menu)) * { * element.Store.TransactionManager.CurrentTransaction.Rollback(); * System.Windows.Forms.MessageBox.Show(validator.ValidationMessages.First().Description); * } */ //bool isParentCollection = this.FindAncestor<ConfigurationElementCollection>( // Don't run in an undo or when store is loading from file (CSD with issue could never open!). if (!element.Store.InUndoRedoOrRollback && !element.Store.InSerializationTransaction) { newValue = newValue.Trim(); // Trim and set new value in case user adds spaces by accident. element.Name = newValue; // Hard validation of the new name. //NamingHelper.ValidateRequiredName(newValue); // TODO: Should verify IsDefaultCollection validition is enforced or check if parent element is a collection. NamingHelper.ValidationOptions options = NamingHelper.ValidationOptions.None; if (NamingHelper.RequiresValidation(newValue, element, out options)) { string msg = ""; if (!NamingHelper.TryValidateAttributesItemNameProperty(newValue, newValue, options, out msg)) { throw new ArgumentException(msg, "RequiredProperty"); } } // When the name changes, set the XML name to the same name but camelCased. element.XmlName = NamingHelper.ToCamelCase(element.Name); } // Always call the base class method. base.OnValueChanged(element, oldValue, newValue); }
protected override void OnValueChanged(TypeBase element, string oldValue, string newValue) { // Don't run in an undo or when store is loading from file (CSD with issue could never open!). if (!element.Store.InUndoRedoOrRollback && !element.Store.InSerializationTransaction) { newValue = newValue.Trim(); // Trim and set new value in case user adds spaces by accident. element.Name = newValue; // We will want to use more specific validation if possible, which is done in overrides (property vs element vs section). // Hard validation of the new name. string msg = ""; if (!NamingHelper.TryValidateBaseName(element, newValue, NamingHelper.ValidationOptions.None, out msg)) { throw new ArgumentException(msg, element.GetType().Name); } // Raise the NameChanged event for derived classes to act upon. element.OnNameChanged(EventArgs.Empty); } // Always call the base class method. base.OnValueChanged(element, oldValue, newValue); }
private void ValidateNamespaces(ValidationContext context) { Debug.WriteLine("ConfigurationSectionModel.ValidateNamespaces called."); // CALLED! string msg = ""; if (!NamingHelper.TryValidateNamespace(this, "CSD Model", this.Namespace, NamingHelper.ValidationOptions.IsRequired, out msg)) { context.LogError(msg, "InvalidProperty", this); } if (!NamingHelper.TryValidateNamespace(this, "CSD Model", this.XmlSchemaNamespace, NamingHelper.ValidationOptions.IsRequired | NamingHelper.ValidationOptions.IsXml, out msg)) { context.LogError(msg, "InvalidProperty", this); } /* * if (string.IsNullOrEmpty(this.Namespace)) * { * context.LogError("The Namespace is required and cannot be an empty string.", "RequiredProperty", this); * } * // TODO: We are allowed to have start with config here!!!! Fix!!! * * if (!NamingHelper.IsValidName(this.Namespace)) * { * context.LogError(Resources.Error_InvalidNamespace, "RequiredProperty", this); // DIES HERE. * } * if (string.IsNullOrEmpty(this.XmlSchemaNamespace)) * { * context.LogError("The XML Schema Namespace is required and cannot be an empty string.", "RequiredProperty", this); * } * if (!NamingHelper.IsValidXmlName(this.XmlSchemaNamespace)) * { * context.LogError(Resources.Error_InvalidXmlNamespace, "RequiredProperty", this); * } */ }