Esempio n. 1
0
            /// <summary>
            /// Process elements for each FactTypeHasRole definition added
            /// during deserialization. If one of our extension elements is not
            /// included in the set of extension elements then create a new one
            /// and add it.
            /// </summary>
            /// <param name="element">A Role element</param>
            /// <param name="store">The context store</param>
            /// <param name="notifyAdded">The listener to notify if elements are added during fixup</param>
            protected sealed override void ProcessElement(Role element, Store store, INotifyElementAdded notifyAdded)
            {
                IORMExtendableElement extendableElement           = element as IORMExtendableElement;
                LinkedElementCollection <ModelElement> extensions = extendableElement.ExtensionCollection;
                int extensionCount = extensions.Count;
                int i;

                for (i = 0; i < extensionCount; ++i)
                {
                    // Look for any of our extension elements
                    if (extensions[i] is MyCustomExtensionElement)
                    {
                        break;
                    }
                }
                if (i == extensionCount)
                {
                    MyCustomExtensionElement customElement = new MyCustomExtensionElement(store);
                    ExtensionElementUtility.AddExtensionElement(extendableElement, customElement);
                    // Always notify during deserialization. All rules are turned off, so
                    // any additions need to be explicitly notified so that other deserialization
                    // fixup listeners can respond appropriately.
                    notifyAdded.ElementAdded(customElement, true);
                }
            }
Esempio n. 2
0
        bool IElementEquivalence.MapEquivalentElements(Store foreignStore, IEquivalentElementTracker elementTracker)
        {
            CustomPropertyDefinition definition;
            CustomPropertyDefinition otherDefinition;
            ModelElement             extendedModelElement;
            IORMExtendableElement    otherExtendedElement;

            if (null != (definition = CustomPropertyDefinition) &&
                null != (otherDefinition = CopyMergeUtility.GetEquivalentElement(definition, foreignStore, elementTracker)) &&
                null != (extendedModelElement = ExtensionElementUtility.GetExtendedElement(this) as ModelElement) &&
                null != (otherExtendedElement = CopyMergeUtility.GetEquivalentElement(extendedModelElement, foreignStore, elementTracker) as IORMExtendableElement))
            {
                // UNDONE: COPYMERGE This will not work for custom properties on a model,
                // but these are not currently selectable and all other contained elements should work correctly.
                foreach (ModelElement element in otherExtendedElement.ExtensionCollection)
                {
                    CustomProperty otherProperty = element as CustomProperty;
                    if (otherProperty != null &&
                        otherProperty.CustomPropertyDefinition == otherDefinition)
                    {
                        elementTracker.AddEquivalentElement(this, otherProperty);
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 3
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();
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This method recreated the Error Text that will be displayed in the Error List.
        /// </summary>
        public override void GenerateErrorText()
        {
            ObjectType objectType = (ObjectType)ExtensionElementUtility.GetExtendedErrorOwnerElement(this);

            if (objectType != null)
            {
                string newText = string.Format(CultureInfo.CurrentCulture,
                                               "Object type '{0}' in model '{1}' requires a meaningful name.",
                                               objectType.Name,
                                               objectType.Model.Name);
                ErrorText = newText;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// AddRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.FactTypeHasRole)
        /// Rules are defined to respond to changes in the object
        /// model that occur during user editing. In this case, we're adding
        /// our custom extension element to a Role object when it is added to
        /// a FactType via the FactTypeHasRole relationship. See the
        /// ExtensionDomainModel.AttachRules.xml file to see how this
        /// method is attached as a rule.
        /// </summary>
        private static void RoleAddRule(ElementAddedEventArgs e)
        {
            FactTypeHasRole factTypeHasRole = (FactTypeHasRole)e.ModelElement;

            ExtensionElementUtility.AddExtensionElement(factTypeHasRole.Role, new MyCustomExtensionElement(factTypeHasRole.Store));
        }