Exemple #1
0
        /// <summary>
        /// This method Validates an ObjectType name.
        /// If the ObjectType name has a name of "ObjectType"
        /// followed by any digits it will create a new error.
        /// </summary>
        /// <param name="objectType">The ObjectType you wish to be validated.</param>
        private static void ValidateObjectTypeName(ObjectType objectType, INotifyElementAdded notifyAdded)
        {
            ORMModel model;

            if (!objectType.IsDeleted &&
                null != (model = objectType.Model))
            {
                Regex regex = objectTypeRegex;
                if (regex == null)
                {
                    ResourceManager resMgr = ResourceAccessor <ORMModel> .ResourceManager;
                    regex = System.Threading.Interlocked.CompareExchange <Regex>(
                        ref objectTypeRegex,
                        new Regex(string.Format(CultureInfo.InvariantCulture, @"\A({0}|{1})\d+\z", resMgr.GetString("ObjectModel.ValueType"), resMgr.GetString("ObjectModel.EntityType")), RegexOptions.Compiled | RegexOptions.IgnoreCase),
                        null);
                    regex = objectTypeRegex;
                }
                string objectTypeName = objectType.Name;
                Match  regexMatch     = regex.Match(objectType.Name);

                LinkedElementCollection <ModelError>  extensions = objectType.ExtensionModelErrorCollection;
                ObjectTypeRequiresMeaningfulNameError nameError  = null;
                int extensionCount = extensions.Count;
                int i;
                for (i = 0; i < extensionCount; ++i)
                {
                    if (extensions[i] is ObjectTypeRequiresMeaningfulNameError)
                    {
                        nameError = extensions[i] as ObjectTypeRequiresMeaningfulNameError;
                        break;
                    }
                }

                if (regexMatch.Success)
                {
                    if (nameError == null)
                    {
                        nameError = new ObjectTypeRequiresMeaningfulNameError(objectType.Store);
                        ExtensionElementUtility.AddExtensionModelError(objectType, nameError);
                        nameError.Model = model;
                        nameError.GenerateErrorText();
                        if (notifyAdded != null)
                        {
                            notifyAdded.ElementAdded(nameError, true);
                        }
                    }
                    else
                    {
                        nameError.GenerateErrorText();
                    }
                }
                else
                {
                    if (nameError != null)
                    {
                        nameError.Delete();
                    }
                }
            }
        }
Exemple #2
0
 public override void ElementPropertyChanged(Microsoft.VisualStudio.Modeling.ElementPropertyChangedEventArgs e)
 {
     ORMSolutions.ORMArchitect.Framework.Diagnostics.TraceUtility.TraceRuleStart(e.ModelElement.Store, "ORMSolutions.ORMArchitect.ExtensionExample.ObjectTypeRequiresMeaningfulNameError.ExtensionObjectTypeChangeRule");
     ObjectTypeRequiresMeaningfulNameError.ExtensionObjectTypeChangeRule(e);
     ORMSolutions.ORMArchitect.Framework.Diagnostics.TraceUtility.TraceRuleEnd(e.ModelElement.Store, "ORMSolutions.ORMArchitect.ExtensionExample.ObjectTypeRequiresMeaningfulNameError.ExtensionObjectTypeChangeRule");
 }