/// <summary>
        /// Return the name of the object.
        /// </summary>
        /// <remarks>
        /// This returns the name of the model element.
        /// </remarks>
        /// <param name="namedObject">The object.</param>
        /// <returns>The name of the object.</returns>
        public override string GetObjectName(object named)
        {
            if (named == null)
            {
                return(string.Empty);
            }

            ModelElement modelElement = named as ModelElement;

            if (modelElement == null)
            {
                return(named.ToString());
            }

            string modelElementName = string.Empty;

            if (!DomainClassInfo.TryGetName(modelElement, out modelElementName))
            {
                //if model element doesnt have a name, we return the class' displayname
                DomainClassInfo classInfo = modelElement.GetDomainClass();
                modelElementName = classInfo.DisplayName;
            }

            return(modelElementName);
        }
        private static ModelElement GetCompartmentElementFirstParentElement(this ModelElement modelElement)
        {
            // Get the domain class associated with model element.
            DomainClassInfo domainClass = modelElement.GetDomainClass();

            if (domainClass != null)
            {
                // A element is only considered to be in a compartment if it participates in only 1 embedding relationship
                // This might be wrong for some models

                if (domainClass.AllEmbeddedByDomainRoles.Count == 1)
                {
                    DomainRoleInfo roleInfo = domainClass.AllEmbeddedByDomainRoles[0];

                    // Get a collection of all the links to this model element
                    // Since this is in a compartment there should be at least one
                    // There can be only one.
                    if (roleInfo != null)
                    {
                        ElementLink link = roleInfo.GetElementLinks(modelElement).FirstOrDefault();

                        // Get the model element participating in the link that isn't the current one
                        // That will be the parent
                        // Probably there is a better way to achieve the same result
                        return(link?.LinkedElements?.FirstOrDefault(linkedElement => !modelElement.Equals(linkedElement)));
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Retrieves all children of a specific parent element. This includes all model elements that are reachable
        /// from the parent element through the embedding relationship.
        /// </summary>
        /// <param name="parentElement">Parent element to retrieve children for.</param>
        /// <param name="bOnlyLocal">Specifies if children of the found children of the given element should be processed too.</param>
        /// <returns>List of model elements that are embedded under the parent element. May be empty.</returns>
        public virtual List<ModelElement> GetChildren(ModelElement parentElement, bool bOnlyLocal)
        {
            List<ModelElement> allChildren = new List<ModelElement>();

            DomainClassInfo info = parentElement.GetDomainClass();
            ReadOnlyCollection<DomainRoleInfo> roleInfoCol = info.AllDomainRolesPlayed;

            foreach (DomainRoleInfo roleInfo in roleInfoCol)
            {
                if (roleInfo.IsSource)
                    if ((parentElement as IDomainModelOwnable).Store.DomainDataAdvDirectory.IsEmbeddingRelationship(roleInfo.DomainRelationship.Id))
                    {
                        global::System.Collections.Generic.IList<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(parentElement, roleInfo.Id);
                        foreach (ElementLink link in links)
                        {
                            ModelElement child = DomainRoleInfo.GetTargetRolePlayer(link);
                            allChildren.Add(child);

                            if (!bOnlyLocal)
                            {
                                allChildren.AddRange(
                                    (child as IDomainModelOwnable).GetDomainModelServices().ElementChildrenProvider.GetChildren(child, bOnlyLocal));

                            }
                        }
                    }
            }

            return allChildren;
        }
        /// <summary>
        /// Gets the embedding domain element of a specific type for a given model element.
        /// </summary>
        /// <param name="modelElement">ModelElement to get the embedding domain element for.</param>
        /// <param name="parentTypeDomainClassId">Type of the embedding domain element to find.</param>
        /// <returns>Domain element as ModelElement if found. Null otherwise</returns>
        public virtual ModelElement GetEmbeddingParent(ModelElement modelElement, System.Guid parentTypeDomainClassId)
        {
            if (!(modelElement is DomainModelElement))
            {
                return(null);
            }

            List <EmbeddingRelationshipAdvancedInfo> embeddings = (modelElement as DomainModelElement).Store.DomainDataAdvDirectory.FindDomainClassTargetEmbeddings((modelElement as DomainModelElement).GetDomainClassId());

            if (embeddings != null)
            {
                foreach (EmbeddingRelationshipAdvancedInfo emb in embeddings)
                {
                    IList <ElementLink> links = DomainRoleInfo.GetElementLinks <ElementLink>(modelElement, emb.TargetRoleId);
                    if (links.Count == 1)
                    {
                        ModelElement m = DomainRoleInfo.GetSourceRolePlayer(links[0]);
                        if (m.GetDomainClass().IsDerivedFrom(parentTypeDomainClassId))
                        {
                            return(m);
                        }

                        return(GetEmbeddingParent(m, parentTypeDomainClassId));
                    }
                }
            }

            return(null);
        }
        public static string GetTargetName(object named)
        {
            if (named == null)
            {
                return(string.Empty);
            }

            ModelElement modelElement = named as ModelElement;

            if (modelElement == null)
            {
                PropertyInfo property = named.GetType().GetProperty("ModelElement");
                if (property == null)
                {
                    return(named.ToString());
                }
                modelElement = property.GetValue(named, null) as ModelElement;
            }

            string modelElementName = string.Empty;

            if (!DomainClassInfo.TryGetName(modelElement, out modelElementName))
            {
                //if model element doesnt have a name, we return the class' displayname
                DomainClassInfo classInfo = modelElement.GetDomainClass();
                modelElementName = classInfo.DisplayName;
            }

            return(modelElementName);
        }
Beispiel #6
0
 /// <summary>
 /// Gets the linked elements for the specified element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="masterDictionary">A master dictionary of all elements</param>
 /// <param name="localDictionary">A local dictionary for this pass through.
 /// Allows us to track multiple passes while iterating through the elements of another dictionary.</param>
 /// <param name="generations">The generations.</param>
 private static void GetLinkedElements(IHierarchyContextEnabled element, Dictionary<IHierarchyContextEnabled, int> masterDictionary, ref Dictionary<IHierarchyContextEnabled, int> localDictionary, int generations)
 {
     ModelElement mel = (ModelElement)element;
     Type contextType = typeof(IHierarchyContextEnabled);
     foreach (DomainRoleInfo roleInfo in mel.GetDomainClass().AllDomainRolesPlayed)
     {
         DomainRoleInfo oppositeRole = roleInfo.OppositeDomainRole;
         Type oppositeType = oppositeRole.RolePlayer.ImplementationClass;
         if (!oppositeType.IsAbstract &&
             contextType.IsAssignableFrom(oppositeType))
         {
             foreach (ElementLink link in roleInfo.GetElementLinks(mel, true)) // Exclude derived, these will also be played roles and be picked up.
             {
                 IHierarchyContextLinkFilter filter = link as IHierarchyContextLinkFilter;
                 if (filter != null &&
                     !filter.ContinueHierachyWalking(roleInfo))
                 {
                     continue;
                 }
                 ModelElement oppositeMel = oppositeRole.GetRolePlayer(link);
                 if (oppositeMel == mel)
                 {
                     continue;
                 }
                 IHierarchyContextEnabled contextableElement = (IHierarchyContextEnabled)oppositeMel; // Cast must work, already checked at the type level
                 int decrement = contextableElement.HierarchyContextDecrementCount;
                 if (masterDictionary.Count == 1 && contextableElement.ForwardHierarchyContextTo != null)
                 {
                     decrement = 0;
                 }
                 GetRelatedContextableElementsHelper(contextableElement, masterDictionary, ref localDictionary, generations - decrement);
             }
         }
     }
 }
        /// <summary>
        /// Constructor. This view model constructed with 'bHookUpEvents=true' does react on model changes.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="element">Element represented by this view model.</param>
        /// <param name="bHookUpEvents">Hook up into model events to update the created view model on changes in model if true.</param>
        public BaseModelElementViewModel(ViewModelStore viewModelStore, ModelElement element, bool bHookUpEvents)
            : base(viewModelStore)
        {
            this.element       = element;
            this.bHookUpEvents = bHookUpEvents;


            if (element != null)
            {
                if (ImmutabilityExtensionMethods.GetLocks(element) != Locks.None)
                {
                    this.IsLocked = true;
                }
            }

            if (this.bHookUpEvents)
            {
                if (element != null)
                {
                    DomainPropertyInfo info = element.GetDomainClass().NameDomainProperty;
                    if (info != null)
                    {
                        this.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Subscribe(
                            info, this.Element.Id, new System.Action <ElementPropertyChangedEventArgs>(NamePropertyChanged));
                    }
                }
            }
        }
Beispiel #8
0
        private static HashSet <ModelElement> GetAllEmbeddedElements(ModelElement element)
        {
            HashSet <ModelElement>   embeddedElements = new HashSet <ModelElement>();
            HashSet <DomainRoleInfo> embeddingRoles   = GetAllEmbeddingRoles(element.GetDomainClass());

            foreach (DomainRoleInfo roleInfo in embeddingRoles)
            {
                // The role could have a multiplicity of 1 or many - which is it?
                if (roleInfo.IsMany)
                {
                    // Fetch and add each of the elements to the set
                    roleInfo.GetLinkedElements(element).ForEach(e => { embeddedElements.Add(e); });
                }
                else
                {
                    // Add the single element to the set
                    ModelElement linkedElement = roleInfo.GetLinkedElement(element);
                    if (linkedElement != null)
                    {
                        embeddedElements.Add(linkedElement);
                    }
                }
            }

            return(embeddedElements);
        }
        private static string GetUniqueName(ModelElement element, ModelElement container, DomainRoleInfo embeddedDomainRole, string baseName)
        {
            Guard.NotNull(() => element, element);
            Guard.NotNull(() => container, container);
            Guard.NotNull(() => embeddedDomainRole, embeddedDomainRole);
            Guard.NotNull(() => baseName, baseName);

            var nameDomainProperty  = element.GetDomainClass().NameDomainProperty;
            var dictionary          = new Dictionary <string, ModelElement>();
            var linkedElements      = embeddedDomainRole.OppositeDomainRole.GetLinkedElements(container);
            var implementationClass = nameDomainProperty.DomainClass.ImplementationClass;
            int count = linkedElements.Count;

            for (int i = 0; i < count; i++)
            {
                var linkedElement = linkedElements[i];

                if ((linkedElement != element) && implementationClass.IsInstanceOfType(linkedElement))
                {
                    var key = nameDomainProperty.GetValue(linkedElement) as string;

                    if ((key != null) && !dictionary.ContainsKey(key))
                    {
                        dictionary.Add(key, linkedElement);
                    }
                }
            }

            return(GetUniqueName(element, baseName, dictionary));
        }
Beispiel #10
0
        private static ModelElement GetCompartmentElementFirstParent(ModelElement modelElement)
        {
            // Get the domain class associated with model element.
            DomainClassInfo domainClass = modelElement.GetDomainClass();

            if (domainClass != null)
            {
                // A element is only considered to be in a compartment if it participates in only 1 embedding relationship
                // This might be wrong for some models

                if (domainClass.AllEmbeddedByDomainRoles.Count == 1)
                {
                    // Get a collection of all the links to this model element
                    // Since this is in a compartment there will only be one
                    ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetAllElementLinks(modelElement);
                    if (links.Count == 1)
                    {
                        // Get the model element participating in the link that isn't the current one
                        // That will be the parent
                        // Probably there is a better way to achieve the same result
                        foreach (ModelElement linkedElement in links[0].LinkedElements)
                        {
                            if (!modelElement.Equals(linkedElement))
                            {
                                return(linkedElement);
                            }
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Retrieves all children of a specific parent element. This includes all model elements that are reachable
        /// from the parent element through the embedding relationship.
        /// </summary>
        /// <param name="parentElement">Parent element to retrieve children for.</param>
        /// <param name="bOnlyLocal">Specifies if children of the found children of the given element should be processed too.</param>
        /// <returns>List of model elements that are embedded under the parent element. May be empty.</returns>
        public virtual List <ModelElement> GetChildren(ModelElement parentElement, bool bOnlyLocal)
        {
            List <ModelElement> allChildren = new List <ModelElement>();

            DomainClassInfo info = parentElement.GetDomainClass();
            ReadOnlyCollection <DomainRoleInfo> roleInfoCol = info.AllDomainRolesPlayed;

            foreach (DomainRoleInfo roleInfo in roleInfoCol)
            {
                if (roleInfo.IsSource)
                {
                    if ((parentElement as IDomainModelOwnable).Store.DomainDataAdvDirectory.IsEmbeddingRelationship(roleInfo.DomainRelationship.Id))
                    {
                        global::System.Collections.Generic.IList <ElementLink> links = DomainRoleInfo.GetElementLinks <ElementLink>(parentElement, roleInfo.Id);
                        foreach (ElementLink link in links)
                        {
                            ModelElement child = DomainRoleInfo.GetTargetRolePlayer(link);
                            allChildren.Add(child);

                            if (!bOnlyLocal)
                            {
                                allChildren.AddRange(
                                    (child as IDomainModelOwnable).GetDomainModelServices().ElementChildrenProvider.GetChildren(child, bOnlyLocal));
                            }
                        }
                    }
                }
            }

            return(allChildren);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="element">Model element.</param>
        public ModelProtoElement(ModelElement element)
        {
            if (element == null)
                throw new System.ArgumentNullException("element");

            elementId = element.Id;
            domainClassId = element.GetDomainClass().Id;

            List<PropertyAssignment> list = GetAssignablePropertyValues(element);
            properties = new System.Collections.ArrayList(list.Count);

            foreach (PropertyAssignment propertyAssignment in list)
                properties.Add(new ModelProtoPropertyValue(propertyAssignment.PropertyId, propertyAssignment.Value));

            DomainClassInfo d = element.GetDomainClass();
            name = d.Name;
        }
Beispiel #13
0
        /// <summary>
        /// Method used to create a new element's name based on the range of available names.
        /// Excluded are names used by the child elements embedded in the given parent element.
        /// </summary>
        /// <param name="parent">Parent element, embedding the model element.</param>
        /// <param name="modelElement">ModelElement to create the name for.</param>
        /// <returns>Created name for the given ModelElement. </returns>
        public virtual string CreateName(ModelElement parent, ModelElement modelElement)
        {
            if (parent is IDomainModelOwnable && modelElement is IDomainModelOwnable)
            {
                if (!(modelElement as IDomainModelOwnable).DomainElementHasName)
                {
                    return(null);
                }

                DomainClassInfo infoParent = parent.GetDomainClass();
                DomainClassInfo infoChild  = modelElement.GetDomainClass();

                IModelElementParentProvider parentprovider = (parent as IDomainModelOwnable).GetDomainModelServices().ElementParentProvider;
                foreach (DomainRoleInfo roleInfo in infoParent.AllDomainRolesPlayed)
                {
                    if (roleInfo.IsSource)
                    {
                        //if (roleInfo.OppositeDomainRole.RolePlayer.Id == infoChild.Id)
                        if (infoChild.IsDerivedFrom(roleInfo.OppositeDomainRole.RolePlayer))
                        {
                            if ((modelElement as IDomainModelOwnable).Store.DomainDataAdvDirectory.IsEmbeddingRelationship(roleInfo.DomainRelationship.Id))
                            {
                                int    counter = 0;
                                string name    = (modelElement as IDomainModelOwnable).DomainElementTypeDisplayName;
                                while (true)
                                {
                                    bool bFound = false;
                                    IList <ElementLink> links = DomainRoleInfo.GetElementLinks <ElementLink>(parent, roleInfo.Id);

                                    foreach (ElementLink c in links)
                                    {
                                        if ((DomainRoleInfo.GetTargetRolePlayer(c) as IDomainModelOwnable).DomainElementName == name + counter.ToString())
                                        {
                                            bFound = true;
                                            break;
                                        }
                                    }

                                    if (!bFound)
                                    {
                                        return(name + counter.ToString());
                                    }

                                    counter++;
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #14
0
 public static void NotifyChangesToDesigner(this ModelElement modelElement, PropertyChangedEventArgs args)
 {
     if (!modelElement.IsDeleting && !modelElement.IsDeleted && (!modelElement.Store.InSerializationTransaction))
     {
         using (Transaction transaction = modelElement.Store.TransactionManager.BeginTransaction("Notify changes"))
         {
             DomainClassInfo    domainClassInfo = modelElement.GetDomainClass();
             DomainPropertyInfo domainProperty  = domainClassInfo.FindDomainProperty(args.PropertyName, true);
             domainProperty.NotifyValueChange(modelElement);
             transaction.Commit();
         }
     }
 }
        protected virtual IList <ModelElement> GetRelatedElements(ModelElement element)
        {
            List <ModelElement> elementList  = new List <ModelElement>();
            List <ModelElement> elementLinks = IncludeLinks ? new List <ModelElement>() : null;

            // All the links to this element needs to be examined to determine whether we should continue copying process or not
            // Find all the links connect to this element (or elementLink since it's legal to have element link to be a roleplayer as well...)
            foreach (DomainRoleInfo domainRole in element.GetDomainClass().AllDomainRolesPlayed)
            {
                // this function supports demand loading
                ReadOnlyCollection <ElementLink> links = domainRole.GetElementLinks(element);

                foreach (ElementLink eachElemLink in links)
                {
                    if (eachElemLink.GetType() != typeof(PresentationViewsSubject))
                    {
                        DomainRelationshipInfo domainRelInfo = eachElemLink.GetDomainRelationship();

                        if (Filter.ShouldVisitRelationship(this, element, domainRole, domainRelInfo, eachElemLink) == VisitorFilterResult.Yes)
                        {
                            if (IncludeLinks)
                            {
                                elementLinks.Add(eachElemLink);
                            }

                            IList <DomainRoleInfo> domainRoles = domainRelInfo.DomainRoles;

                            for (int i = 0; i < domainRoles.Count; i++)
                            {
                                DomainRoleInfo role       = domainRoles[i];
                                ModelElement   rolePlayer = role.GetRolePlayer(eachElemLink);

                                // Find each roleplayer and add them to the queue list
                                if ((rolePlayer != element) && !Visited(rolePlayer) && (Filter.ShouldVisitRolePlayer(this, element, eachElemLink, role, rolePlayer) == VisitorFilterResult.Yes))
                                {
                                    elementList.Add(rolePlayer);
                                }
                            }
                        }
                    }
                }
            }

            if (IncludeLinks)
            {
                elementList.AddRange(elementLinks);
            }
            elementList.TrimExcess();

            return(elementList);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="element">Model element.</param>
        public ModelProtoElement(ModelElement element)
        {
            if (element == null)
            {
                throw new System.ArgumentNullException("element");
            }

            elementId     = element.Id;
            domainClassId = element.GetDomainClass().Id;

            List <PropertyAssignment> list = GetAssignablePropertyValues(element);

            properties = new System.Collections.ArrayList(list.Count);

            foreach (PropertyAssignment propertyAssignment in list)
            {
                properties.Add(new ModelProtoPropertyValue(propertyAssignment.PropertyId, propertyAssignment.Value));
            }

            DomainClassInfo d = element.GetDomainClass();

            name = d.Name;
        }
        /// <summary>
        /// Returns the default value of a property of the given element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        public static TResult GetPropertyDefaultValue <T, TResult>(this ModelElement element, Expression <Func <T, TResult> > property)
        {
            Guard.NotNull(() => element, element);

            var propertyName = Reflector <T> .GetProperty(property).Name;

            var domainProperty = element.GetDomainClass().FindDomainProperty(propertyName, true);

            if (domainProperty == null)
            {
                throw new InvalidOperationException(Resources.ModelElementExtensions_GetPropertyDefaultValue_NoProperty);
            }

            return((TResult)domainProperty.DefaultValue);
        }
Beispiel #18
0
        /// <summary>
        ///    Called when the user selects this command.
        /// </summary>
        /// <param name="command"></param>
        public void Execute(IMenuCommand command)
        {
            // Transaction is required if you want to update elements.
            //using (Transaction t = SelectionContext.CurrentStore
            //                                       .TransactionManager.BeginTransaction("fix names"))
            {
                foreach (ShapeElement shape in SelectionContext.CurrentSelection)
                {
                    ModelElement element = shape.ModelElement;
                    MessageBox.Show(element.GetDomainClass().Name);
                }

                //t.Commit();
            }
        }
        private IDictionary<string, ModelElement> GetElementNames(ModelElement element)
        {
            var names = new Dictionary<string, ModelElement>();
            element.Store.ElementDirectory.AllElements
                .Where(e => e.GetDomainClass().ImplementationClass == element.GetDomainClass().ImplementationClass)
                .Where(e => !e.Equals(element))
                .ForEach(e =>
                {
                    var name = (string)this.DomainProperty.GetValue(e);
                    if (!names.ContainsKey(name))
                    {
                        names.Add(name, e);
                    }
                });

            return names;
        }
        /// <summary>
        /// Method used to create a new element's name based on the range of available names. 
        /// Excluded are names used by the child elements embedded in the given parent element.
        /// </summary>
        /// <param name="parent">Parent element, embedding the model element.</param>
        /// <param name="modelElement">ModelElement to create the name for.</param>
        /// <returns>Created name for the given ModelElement. </returns>
        public virtual string CreateName(ModelElement parent, ModelElement modelElement)
        {
            if (parent is IDomainModelOwnable && modelElement is IDomainModelOwnable)
            {
                if (!(modelElement as IDomainModelOwnable).DomainElementHasName)
                    return null;

                DomainClassInfo infoParent = parent.GetDomainClass();
                DomainClassInfo infoChild = modelElement.GetDomainClass();

                IModelElementParentProvider parentprovider = (parent as IDomainModelOwnable).GetDomainModelServices().ElementParentProvider;
                foreach (DomainRoleInfo roleInfo in infoParent.AllDomainRolesPlayed)
                {
                    if (roleInfo.IsSource)
                        //if (roleInfo.OppositeDomainRole.RolePlayer.Id == infoChild.Id)
                        if( infoChild.IsDerivedFrom(roleInfo.OppositeDomainRole.RolePlayer) )
                            if ((modelElement as IDomainModelOwnable).Store.DomainDataAdvDirectory.IsEmbeddingRelationship(roleInfo.DomainRelationship.Id))
                            {
                                int counter = 0;
                                string name = (modelElement as IDomainModelOwnable).DomainElementTypeDisplayName;
                                while (true)
                                {
                                    bool bFound = false;
                                    IList<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(parent, roleInfo.Id);

                                    foreach (ElementLink c in links)
                                    {
                                        if ((DomainRoleInfo.GetTargetRolePlayer(c) as IDomainModelOwnable).DomainElementName == name + counter.ToString())
                                        {
                                            bFound = true;
                                            break;
                                        }
                                    }

                                    if (!bFound)
                                        return name + counter.ToString();

                                    counter++;
                                }
                            }
                }
            }

            return null;
        }
        private IDictionary <string, ModelElement> GetElementNames(ModelElement element)
        {
            var names = new Dictionary <string, ModelElement>();

            element.Store.ElementDirectory.AllElements
            .Where(e => e.GetDomainClass().ImplementationClass == element.GetDomainClass().ImplementationClass)
            .Where(e => !e.Equals(element))
            .ForEach(e =>
            {
                var name = (string)this.DomainProperty.GetValue(e);
                if (!names.ContainsKey(name))
                {
                    names.Add(name, e);
                }
            });

            return(names);
        }
        /// <summary>
        /// Gets a list of PropertyAssignments for all assignable properties.
        /// </summary>
        /// <param name="element">Element to get PropertyAssignments for.</param>
        /// <returns>List of PropertyAssignment.</returns>
        public static List <PropertyAssignment> GetAssignablePropertyValues(ModelElement element)
        {
            List <PropertyAssignment> list = new List <PropertyAssignment>();
            ReadOnlyCollection <DomainPropertyInfo> readOnlyCollection = element.GetDomainClass().AllDomainProperties;

            foreach (DomainPropertyInfo domainPropertyInfo in readOnlyCollection)
            {
                if (domainPropertyInfo.Kind != Microsoft.VisualStudio.Modeling.DomainPropertyKind.Calculated)
                {
                    object obj = domainPropertyInfo.GetValue(element);
                    if (obj != null)
                    {
                        list.Add(new PropertyAssignment(domainPropertyInfo.Id, obj));
                    }
                }
            }
            return(list);
        }
        /// <summary>
        /// Clean up.
        /// </summary>
        protected override void OnDispose()
        {
            if (this.bHookUpEvents)
            {
                if (element != null)
                {
                    DomainPropertyInfo info = element.GetDomainClass().NameDomainProperty;
                    if (info != null)
                    {
                        this.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Unsubscribe(
                            info, this.Element.Id, new System.Action <ElementPropertyChangedEventArgs>(NamePropertyChanged));
                    }
                }
            }

            base.OnDispose();

            this.element = null;
        }
Beispiel #24
0
        /// <summary>
        /// Creates a shape for the specified model element.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected virtual NodeShape CreateShape(ModelElement element)
        {
            DiagramDomainDataDirectory data = this.Store.DomainDataAdvDirectory.ResolveExtensionDirectory <DiagramDomainDataDirectory>();

            Guid domainClassId = element.GetDomainClass().Id;

            if (data.HasDependenciesShapeForElement(domainClassId))
            {
                return(this.ViewModelStore.TopMostStore.GetDomainModelServices().ShapeProvider.CreateDependenciesShapeForElement(domainClassId, element) as NodeShape);
            }

            NodeShape dShape = new NodeShape(this.Store);

            dShape.Element = element;
            dShape.SetLocation(new PointD(5, 5));
            dShape.SetSize(new SizeD(200, 40));

            return(dShape);
        }
        /// <summary>
        /// Verifies if a specific model element should be excluded or not.
        /// </summary>
        /// <param name="modelElement">Model element to verify</param>
        /// <returns>True if the specified element should be excluded; False otherwise.</returns>
        public virtual bool ShouldExcludeDomainClass(ModelElement modelElement)
        {
            if (bUseExcludedDomainClasses || bUseIncludedDomainClasses || bUseExcludedDomainModels || bUseIncludedDomainModels)
            {
                Guid t = modelElement.GetDomainClass().Id;
                if (bUseExcludedDomainClasses)
                {
                    if (this.excludedDomainClasses.Contains(t))
                    {
                        return(true);
                    }
                }

                if (bUseIncludedDomainClasses)
                {
                    if (!this.includedDomainClasses.Contains(t))
                    {
                        return(true);
                    }
                }

                if (bUseExcludedDomainModels)
                {
                    IDomainModelOwnable o = modelElement as IDomainModelOwnable;
                    if (this.excludedDomainModels.Contains(o.GetDomainModelTypeId()))
                    {
                        return(true);
                    }
                }

                if (bUseIncludedDomainModels)
                {
                    IDomainModelOwnable o = modelElement as IDomainModelOwnable;
                    if (!this.includedDomainModels.Contains(o.GetDomainModelTypeId()))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// Constructor. This view model constructed with 'bHookUpEvents=true' does react on model changes.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="element">Element represented by this view model.</param>
        /// <param name="bHookUpEvents">Hook up into model events to update the created view model on changes in model if true.</param>
        public BaseModelElementViewModel(ViewModelStore viewModelStore, ModelElement element, bool bHookUpEvents)
            : base(viewModelStore)
        {
            this.element = element;
            this.bHookUpEvents = bHookUpEvents;


            if (element != null)
                if (ImmutabilityExtensionMethods.GetLocks(element) != Locks.None)
                    this.IsLocked = true;

            if( this.bHookUpEvents )
                if (element != null)
                {
                    DomainPropertyInfo info = element.GetDomainClass().NameDomainProperty;
                    if (info != null)
                        this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(
                            info, this.Element.Id, new System.Action<ElementPropertyChangedEventArgs>(NamePropertyChanged));
                }
        }
Beispiel #27
0
        private static ModelElement GetCompartmentElementFirstParentElement(this ModelElement modelElement)
        {
            // Get the domain class associated with model element.

            DomainClassInfo domainClass = modelElement.GetDomainClass();

            if (domainClass?.AllEmbeddedByDomainRoles?.Count == 1)
            {
                DomainRoleInfo roleInfo = domainClass.AllEmbeddedByDomainRoles[0];

                // Get a collection of all the links to this model element
                // Since this is in a compartment there should be at least one
                // There can be only one.

                ElementLink elementLink = roleInfo.GetElementLinks(modelElement)?.FirstOrDefault();
                return(elementLink?.LinkedElements?.FirstOrDefault(e => !modelElement.Equals(e)));
            }

            return(null);
        }
Beispiel #28
0
        /// <summary>
        /// Creates a <see cref="PropertyDescriptor"/> for the <c>Name</c> property of <paramref name="element"/>.
        /// </summary>
        /// <param name="element">
        /// The instance of <see cref="ModelElement"/> containing the <c>Name</c> property for which a
        /// <see cref="PropertyDescriptor"/> should be created.
        /// </param>
        /// <returns>
        /// A <see cref="PropertyDescriptor"/> for the <c>Name</c> property of <paramref name="element"/>
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="element"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <paramref name="element"/> does not have a <c>Name</c> property.
        /// </exception>
        public static PropertyDescriptor CreateNamePropertyDescriptor(ModelElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            DomainPropertyInfo nameDomainPropertyInfo = element.GetDomainClass().NameDomainProperty;

            if (nameDomainPropertyInfo == null)
            {
                // Cheat and use the Exception that DSL Tools throws so that we don't need to worry about localizing it.
                try
                {
                    DomainClassInfo.GetName(element);
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;                     // Yes, we want to reset the stack trace.
                }
            }
            return(DomainTypeDescriptor.CreatePropertyDescriptor(element, nameDomainPropertyInfo));
        }
        /// <summary>
        /// Gets the name of the unique.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="baseName">Name of the base.</param>
        public static string GetUniqueName(this ModelElement element, string baseName)
        {
            Guard.NotNull(() => element, element);

            Guard.NotNullOrEmpty(() => baseName, baseName);

            var domainClass = element.GetDomainClass();

            var nameDomainProperty = domainClass.NameDomainProperty;

            if (nameDomainProperty == null)
            {
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture, Resources.ModelElementExtensions_ElementNameNotSupported, element.GetDomainClass().Name));
            }

            var allDomainRolesPlayed = domainClass.AllDomainRolesPlayed;
            int count = allDomainRolesPlayed.Count;

            for (int i = 0; i < count; i++)
            {
                var embeddedDomainRole = allDomainRolesPlayed[i];
                var oppositeDomainRole = embeddedDomainRole.OppositeDomainRole;
                if (oppositeDomainRole.IsEmbedding)
                {
                    var elementLinks = embeddedDomainRole.GetElementLinks(element);
                    if ((elementLinks != null) && (elementLinks.Count > 0))
                    {
                        var rolePlayer = oppositeDomainRole.GetRolePlayer(elementLinks[0]);
                        return(GetUniqueName(element, rolePlayer, embeddedDomainRole, baseName));
                    }
                }
            }

            return(baseName);
        }
Beispiel #30
0
            /// <summary>
            /// Verify that the element belongs to the correct domain model
            /// </summary>
            protected override bool VerifyElementType(ModelElement element)
            {
                DomainModelInfo modelFilter = myDomainModelFilter;

                return((modelFilter != null) ? element.GetDomainClass().DomainModel == modelFilter : true);
            }
Beispiel #31
0
        private static HashSet<ModelElement> GetAllEmbeddedElements(ModelElement element)
        {
            HashSet<ModelElement> embeddedElements = new HashSet<ModelElement>();
            HashSet<DomainRoleInfo> embeddingRoles = GetAllEmbeddingRoles(element.GetDomainClass());

            foreach (DomainRoleInfo roleInfo in embeddingRoles)
            {
                // The role could have a multiplicity of 1 or many - which is it?  
                if (roleInfo.IsMany)
                {
                    // Fetch and add each of the elements to the set  
                    roleInfo.GetLinkedElements(element).ForEach(e => { embeddedElements.Add(e); });
                }
                else
                {
                    // Add the single element to the set  
                    ModelElement linkedElement = roleInfo.GetLinkedElement(element);
                    if (linkedElement != null)
                    {
                        embeddedElements.Add(linkedElement);
                    }
                }
            }

            return embeddedElements;
        }
Beispiel #32
0
        public static DomainClassXmlSerializer GetSerializer(this ModelElement modelElement)
        {
            Guid domainClassId = modelElement.GetDomainClass().Id;

            return(GetSerializer(domainClassId));
        }
Beispiel #33
0
        /// <summary>
        /// Search a specific model element by using the given search criteria.
        /// </summary>
        /// <param name="modelElement">Model element to be searched.</param>
        /// <param name="criteria">Search criteria to use.</param>
        /// <param name="searchText">Text to search.</param>
        /// <param name="options">Search options.</param>
        /// <returns>Search result list if any found. Empty list otherwise.</returns>
        public virtual List <SearchResult> Search(ModelElement modelElement, SearchCriteriaEnum criteria, string searchText, SearchOptions options)
        {
            List <SearchResult> results = new List <SearchResult>();
            DomainClassInfo     info    = modelElement.GetDomainClass();
            Type modelElementType       = modelElement.GetType();

            #region properties
            if (criteria == SearchCriteriaEnum.Name ||
                criteria == SearchCriteriaEnum.NameAndType ||
                criteria == SearchCriteriaEnum.All ||
                criteria == SearchCriteriaEnum.Properties ||
                criteria == SearchCriteriaEnum.PropertiesWithoutName)
            {
                foreach (DomainPropertyInfo propertyInfo in info.AllDomainProperties)
                {
                    if (propertyInfo == info.NameDomainProperty &&
                        criteria != SearchCriteriaEnum.Name &&
                        criteria != SearchCriteriaEnum.NameAndType &&
                        criteria != SearchCriteriaEnum.Properties &&
                        criteria != SearchCriteriaEnum.All)
                    {
                        continue;
                    }
                    else if (propertyInfo != info.NameDomainProperty &&
                             criteria != SearchCriteriaEnum.All &&
                             criteria != SearchCriteriaEnum.Properties &&
                             criteria != SearchCriteriaEnum.PropertiesWithoutName)
                    {
                        continue;
                    }

                    object nameValue = GetPropertyValue(modelElement, modelElementType, propertyInfo.Name);
                    if (nameValue == null && System.String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source        = modelElement;
                        searchResult.Reason        = "Property " + propertyInfo.Name + " is 'null'";

                        results.Add(searchResult);
                    }
                    else if (nameValue != null && !System.String.IsNullOrEmpty(searchText))
                    {
                        if (Contains(nameValue.ToString(), searchText, options))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source        = modelElement;
                            searchResult.Reason        = "Property " + propertyInfo.Name + " contains '" + searchText + "'";

                            results.Add(searchResult);
                        }
                    }
                }
            }
            #endregion

            #region roles
            if (criteria == SearchCriteriaEnum.Roles ||
                criteria == SearchCriteriaEnum.All)
            {
                foreach (DomainRoleInfo roleInfo in info.AllDomainRolesPlayed)
                {
                    if (!roleInfo.IsSource)
                    {
                        continue;
                    }

                    DomainRelationshipInfo relInfo = roleInfo.DomainRelationship;
                    if (!IsLinkIncludedInDomainTree(modelElement.Store as DomainModelStore, relInfo.Id))
                    {
                        continue;
                    }

                    ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetElementLinks <ElementLink>(modelElement, roleInfo.Id);
                    if (links.Count == 0 && String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source        = modelElement;
                        searchResult.Reason        = "Role " + roleInfo.PropertyName + " is empty";

                        results.Add(searchResult);
                    }

                    foreach (ElementLink link in links)
                    {
                        ModelElement m = DomainRoleInfo.GetTargetRolePlayer(link);
                        if (m == null && System.String.IsNullOrEmpty(searchText))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source        = modelElement;
                            searchResult.Reason        = "Role " + roleInfo.PropertyName + " is null";

                            results.Add(searchResult);
                        }
                        else if (m != null && !System.String.IsNullOrEmpty(searchText))
                        {
                            if (Contains((m as IDomainModelOwnable).DomainElementFullName, searchText, options))
                            {
                                SearchResult searchResult = new SearchResult();
                                searchResult.IsSuccessFull = true;
                                searchResult.Source        = modelElement;
                                searchResult.Reason        = "Role " + roleInfo.PropertyName + " contains '" + searchText + "' in the Full Name property on referenced element " + (m as IDomainModelOwnable).DomainElementFullName;

                                results.Add(searchResult);
                            }
                        }
                    }
                }
            }
            #endregion

            #region type
            if (criteria == SearchCriteriaEnum.Type ||
                criteria == SearchCriteriaEnum.NameAndType ||
                criteria == SearchCriteriaEnum.All)
            {
                if (Contains((modelElement as IDomainModelOwnable).DomainElementType, searchText, options) ||
                    Contains((modelElement as IDomainModelOwnable).DomainElementTypeDisplayName, searchText, options))
                {
                    SearchResult searchResult = new SearchResult();
                    searchResult.IsSuccessFull = true;
                    searchResult.Source        = modelElement;
                    searchResult.Reason        = "Type '" + searchText + "' found";

                    results.Add(searchResult);
                }
            }
            #endregion

            return(results);
        }
Beispiel #34
0
        private void CustomWriteElements(SerializationContext serializationContext, ModelElement element, XmlWriter writer)
        {
            //DefaultWriteElements(context, element, writer);

            if (!serializationContext.Result.Failed)
            {
                writer.WriteAttributeString("modelVersion", ModelApp.ApplicationVersion.ToString());
            }


            // EntityModelHasDomainTypes
            // Non-public getter, use DomainRoleInfo methods.
            System.Collections.ObjectModel.ReadOnlyCollection <EntityModelHasDomainTypes> allEntityModelHasDomainTypesInstances = DomainRoleInfo.GetElementLinks <EntityModelHasDomainTypes>(element, EntityModelHasDomainTypes.EntityModelDomainRoleId);
            if (!serializationContext.Result.Failed && allEntityModelHasDomainTypesInstances.Count > 0)
            {
                writer.WriteStartElement("domainTypes");
                System.Type typeofEntityModelHasDomainTypes = typeof(EntityModelHasDomainTypes);
                foreach (EntityModelHasDomainTypes eachEntityModelHasDomainTypesInstance in allEntityModelHasDomainTypesInstances)
                {
                    if (serializationContext.Result.Failed)
                    {
                        break;
                    }

                    if (eachEntityModelHasDomainTypesInstance.GetType() != typeofEntityModelHasDomainTypes)
                    {   // Derived relationships will be serialized in full-form.
                        DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachEntityModelHasDomainTypesInstance.GetDomainClass().Id);
                        System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachEntityModelHasDomainTypesInstance.GetDomainClass().Name + "!");
                        derivedRelSerializer.Write(serializationContext, eachEntityModelHasDomainTypesInstance, writer);
                    }
                    else
                    {   // No need to serialize the relationship itself, just serialize the role-player directly.
                        ModelElement             targetElement    = eachEntityModelHasDomainTypesInstance.DomainType;
                        DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
                        System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");
                        targetSerializer.Write(serializationContext, targetElement, writer);
                    }
                }
                writer.WriteEndElement();
            }

            // EntityModelHasPersistentTypes
            // Non-public getter, use DomainRoleInfo methods.
            System.Collections.ObjectModel.ReadOnlyCollection <EntityModelHasPersistentTypes> allEntityModelHasPersistentTypesInstances = DomainRoleInfo.GetElementLinks <EntityModelHasPersistentTypes>(element, EntityModelHasPersistentTypes.EntityModelDomainRoleId);
            if (!serializationContext.Result.Failed && allEntityModelHasPersistentTypesInstances.Count > 0)
            {
                writer.WriteStartElement("persistentTypes");
                Type typeofEntityModelHasPersistentTypes = typeof(EntityModelHasPersistentTypes);
                foreach (EntityModelHasPersistentTypes eachEntityModelHasPersistentTypesInstance in allEntityModelHasPersistentTypesInstances)
                {
                    if (serializationContext.Result.Failed)
                    {
                        break;
                    }

                    if (eachEntityModelHasPersistentTypesInstance.GetType() != typeofEntityModelHasPersistentTypes)
                    {   // Derived relationships will be serialized in full-form.
                        DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachEntityModelHasPersistentTypesInstance.GetDomainClass().Id);
                        System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachEntityModelHasPersistentTypesInstance.GetDomainClass().Name + "!");
                        derivedRelSerializer.Write(serializationContext, eachEntityModelHasPersistentTypesInstance, writer);
                    }
                    else
                    {   // No need to serialize the relationship itself, just serialize the role-player directly.
                        ModelElement             targetElement    = eachEntityModelHasPersistentTypesInstance.Element;
                        DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
                        System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");
                        targetSerializer.Write(serializationContext, targetElement, writer);
                    }
                }
                writer.WriteEndElement();
            }
        }
		protected virtual IList<ModelElement> GetRelatedElements(ModelElement element)
		{
			List<ModelElement> elementList = new List<ModelElement>();
			List<ModelElement> elementLinks = IncludeLinks ? new List<ModelElement>() : null;

			// All the links to this element needs to be examined to determine whether we should continue copying process or not
			// Find all the links connect to this element (or elementLink since it's legal to have element link to be a roleplayer as well...)
			foreach(DomainRoleInfo domainRole in element.GetDomainClass().AllDomainRolesPlayed)
			{
				// this function supports demand loading
				ReadOnlyCollection<ElementLink> links = domainRole.GetElementLinks(element);

				foreach(ElementLink eachElemLink in links)
				{
					if(eachElemLink.GetType() != typeof(PresentationViewsSubject))
					{
						DomainRelationshipInfo domainRelInfo = eachElemLink.GetDomainRelationship();

						if(Filter.ShouldVisitRelationship(this, element, domainRole, domainRelInfo, eachElemLink) == VisitorFilterResult.Yes)
						{
							if(IncludeLinks)
							{
								elementLinks.Add(eachElemLink);
							}

							IList<DomainRoleInfo> domainRoles = domainRelInfo.DomainRoles;

							for(int i = 0; i < domainRoles.Count; i++)
							{
								DomainRoleInfo role = domainRoles[i];
								ModelElement rolePlayer = role.GetRolePlayer(eachElemLink);

								// Find each roleplayer and add them to the queue list
								if((rolePlayer != element) && !Visited(rolePlayer) && (Filter.ShouldVisitRolePlayer(this, element, eachElemLink, role, rolePlayer) == VisitorFilterResult.Yes))
								{
									elementList.Add(rolePlayer);
								}
							}
						}
					}
				}
			}

			if(IncludeLinks)
			{
				elementList.AddRange(elementLinks);
			}
			elementList.TrimExcess();

			return elementList;
		}
        public CodeGenerationResults Generate(IArtifactLink link)
        {
            CodeGenerationResults result = new CodeGenerationResults();

            if (link is IModelReference)
            {
                this.serviceProvider = Utility.GetData <IServiceProvider>(link);
                ProjectNode project = Utility.GetData <ProjectNode>(link);

                ModelElement modelElement = ((IModelReference)link).ModelElement;
                TextTemplateArtifactLinkWrapper textTemplateArtifactLink = new TextTemplateArtifactLinkWrapper(link);
                textTemplateArtifactLink.ResourceResolver = ResourceResolver;
                string template = GetTemplateBasedOnProject(textTemplateArtifactLink, project);

                if (modelElement != null && !string.IsNullOrEmpty(template))
                {
                    Engine           engine = new Engine();
                    DomainModel      model  = (DomainModel)modelElement.Store.GetDomainModel(modelElement.GetDomainClass().DomainModel.Id);
                    TextTemplateHost host   = new TextTemplateHost(model, modelElement, modelElement, GetService <ICodeGenerationService>());
                    host.ResourceResolver = textTemplateArtifactLink.ResourceResolver;
                    string content = engine.ProcessTemplate(template, host);

                    if (host.GenerateOutput)
                    {
                        this.projectReferences  = new List <Guid>(host.ProjectReferences);
                        this.assemblyReferences = GetAssemblyReferences(link);
                        if (host.CompilerErrors.Count > 0)
                        {
                            foreach (CompilerError error in host.CompilerErrors)
                            {
                                LogError(error);
                            }
                        }
                        // Will create a file with the 'ErrorGeneratingOutput' text in the generated file.
                        result.Add(link.ItemPath, content);
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// Verifies if a specific model element should be excluded or not.
        /// </summary>
        /// <param name="modelElement">Model element to verify</param>
        /// <returns>True if the specified element should be excluded; False otherwise.</returns>
        public virtual bool ShouldExcludeDomainClass(ModelElement modelElement)
        {
            if (bUseExcludedDomainClasses || bUseIncludedDomainClasses || bUseExcludedDomainModels || bUseIncludedDomainModels)
            {
                Guid t = modelElement.GetDomainClass().Id;
                if (bUseExcludedDomainClasses)
                    if (this.excludedDomainClasses.Contains(t))
                        return true;

                if (bUseIncludedDomainClasses)
                    if (!this.includedDomainClasses.Contains(t))
                        return true;

                if (bUseExcludedDomainModels)
                {
                    IDomainModelOwnable o = modelElement as IDomainModelOwnable;
                    if (this.excludedDomainModels.Contains(o.GetDomainModelTypeId()))
                        return true;
                }

                if (bUseIncludedDomainModels)
                {
                    IDomainModelOwnable o = modelElement as IDomainModelOwnable;
                    if (!this.includedDomainModels.Contains(o.GetDomainModelTypeId()))
                        return true;
                }                    
            }

            return false;
        }
Beispiel #38
0
 bool IORMModelErrorActivationService.ActivateError(ModelElement selectedElement, ModelError error)
 {
     return(ActivateError(selectedElement, error, selectedElement.GetDomainClass()));
 }
        /// <summary>
        /// Search a specific model element by using the given search criteria.
        /// </summary>
        /// <param name="modelElement">Model element to be searched.</param>
        /// <param name="criteria">Search criteria to use.</param>
		/// <param name="searchText">Text to search.</param>
        /// <param name="options">Search options.</param>
        /// <returns>Search result list if any found. Empty list otherwise.</returns>
        public virtual List<SearchResult> Search(ModelElement modelElement, SearchCriteriaEnum criteria, string searchText, SearchOptions options)
        {
            List<SearchResult> results = new List<SearchResult>();
            DomainClassInfo info = modelElement.GetDomainClass();
            Type modelElementType = modelElement.GetType();

            #region properties
            if (criteria == SearchCriteriaEnum.Name ||
                criteria == SearchCriteriaEnum.NameAndType ||
                criteria == SearchCriteriaEnum.All ||
                criteria == SearchCriteriaEnum.Properties || 
				criteria == SearchCriteriaEnum.PropertiesWithoutName)
                foreach (DomainPropertyInfo propertyInfo in info.AllDomainProperties)
                {
                    if (propertyInfo == info.NameDomainProperty &&
                        criteria != SearchCriteriaEnum.Name &&
                        criteria != SearchCriteriaEnum.NameAndType &&
                        criteria != SearchCriteriaEnum.Properties &&
                        criteria != SearchCriteriaEnum.All)
                        continue;
                    else if (propertyInfo != info.NameDomainProperty &&
                        criteria != SearchCriteriaEnum.All &&
                        criteria != SearchCriteriaEnum.Properties &&
                        criteria != SearchCriteriaEnum.PropertiesWithoutName)
                        continue;

                    object nameValue = GetPropertyValue(modelElement, modelElementType, propertyInfo.Name);
                    if (nameValue == null && System.String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source = modelElement;
                        searchResult.Reason = "Property " + propertyInfo.Name + " is 'null'";

                        results.Add(searchResult);
                    }
                    else if (nameValue != null && !System.String.IsNullOrEmpty(searchText))
                        if (Contains(nameValue.ToString(), searchText, options))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source = modelElement;
                            searchResult.Reason = "Property " + propertyInfo.Name + " contains '" + searchText + "'";

                            results.Add(searchResult);
                        }

                }
			#endregion

            #region roles
            if (criteria == SearchCriteriaEnum.Roles ||
                criteria == SearchCriteriaEnum.All)
            {
                foreach (DomainRoleInfo roleInfo in info.AllDomainRolesPlayed)
                {
                    if (!roleInfo.IsSource)
                        continue;

                    DomainRelationshipInfo relInfo = roleInfo.DomainRelationship;
                    if (!IsLinkIncludedInDomainTree(modelElement.Store as DomainModelStore, relInfo.Id))
                        continue;

                    ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(modelElement, roleInfo.Id);
                    if (links.Count == 0 && String.IsNullOrEmpty(searchText))
                    {
                        SearchResult searchResult = new SearchResult();
                        searchResult.IsSuccessFull = true;
                        searchResult.Source = modelElement;
                        searchResult.Reason = "Role " + roleInfo.PropertyName + " is empty";

                        results.Add(searchResult);
                    }

                    foreach (ElementLink link in links)
                    {
                        ModelElement m = DomainRoleInfo.GetTargetRolePlayer(link);
                        if (m == null && System.String.IsNullOrEmpty(searchText))
                        {
                            SearchResult searchResult = new SearchResult();
                            searchResult.IsSuccessFull = true;
                            searchResult.Source = modelElement;
                            searchResult.Reason = "Role " + roleInfo.PropertyName + " is null";

                            results.Add(searchResult);
                        }
                        else if (m != null && !System.String.IsNullOrEmpty(searchText))
                            if (Contains((m as IDomainModelOwnable).DomainElementFullName, searchText, options))
                            {
                                SearchResult searchResult = new SearchResult();
                                searchResult.IsSuccessFull = true;
                                searchResult.Source = modelElement;
                                searchResult.Reason = "Role " + roleInfo.PropertyName + " contains '" + searchText + "' in the Full Name property on referenced element " + (m as IDomainModelOwnable).DomainElementFullName;

                                results.Add(searchResult);
                            }
                    }
                }
            }
            #endregion

            #region type
            if (criteria == SearchCriteriaEnum.Type ||
                criteria == SearchCriteriaEnum.NameAndType ||
                criteria == SearchCriteriaEnum.All)
            {
                if (Contains((modelElement as IDomainModelOwnable).DomainElementType, searchText, options) ||
                    Contains((modelElement as IDomainModelOwnable).DomainElementTypeDisplayName, searchText, options))
                {
                    SearchResult searchResult = new SearchResult();
                    searchResult.IsSuccessFull = true;
                    searchResult.Source = modelElement;
                    searchResult.Reason = "Type '" + searchText + "' found";

                    results.Add(searchResult);
                }
            }
            #endregion

            return results;
        }
Beispiel #40
0
        protected override Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement CreateChildShape(ModelElement element)
        {
            var btProcess = (SubProcess)ModelElement;

            if (btProcess.VisioId == string.Empty)
                using (Transaction trans = this.Store.TransactionManager.BeginTransaction("create process visio id"))
                {
                    btProcess.VisioId = btProcess.Id.ToString().ToLower();

                    trans.Commit();
                }

            var elementClass = element.GetDomainClass();
            using (Transaction trans = Store.TransactionManager.BeginTransaction("create activity code id"))
            {
                
                if (element is FlowMinimal)
                {
                    if (string.IsNullOrEmpty(((FlowMinimal)element).VisioId))
                        ((FlowMinimal)element).VisioId = element.Id.ToString().ToLower();
                }
                else if (element is Activity)
                {
                    if (string.IsNullOrEmpty(((Activity)element).VisioId))
                        ((Activity)element).VisioId = element.Id.ToString().ToLower();
                }

                trans.Commit();
            }

            switch (elementClass.Name)
            {
                case "CloudcoreUser":
                    SubProcessFiles.AddPage(Store, ((Activity)element).VisioId, btProcess.VisioId);
                    break;
                case "MobileActivity":
                    SubProcessFiles.AddPage(Store, ((Activity)element).VisioId, btProcess.VisioId);
                    break;
                case "HybridActivity":
                    SubProcessFiles.AddPage(Store, ((Activity)element).VisioId, btProcess.VisioId);
                    break;
                case "WorkflowRule":
                    SubProcessFiles.AddSql(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.SqlWorkflowRuleActivity));
                    break;
                case "DatabaseEvent":
                    SubProcessFiles.AddSql(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.SqlCustomActivity));
                    break;
                case "DatabasePark":
                    SubProcessFiles.AddSql(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.SqlParkedActivity));
                    break;
                case "CloudPark":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudParkedActivity));
                    break;
                case "CloudCustom":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudCustomActivity));
                    break;
                case "PostageApp":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudPostageActivity));
                    break;
                case "Email":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.Email));
                    break;
                case "Clickatell":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudClickatellActivity));
                    break;
                case "DatabaseCosting":
                    SubProcessFiles.AddSql(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.SqlCostingActivity));
                    break;
                case "CloudCosting":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudCostingActivity));
                    break;
                case "DatabaseBatchStart":
                    SubProcessFiles.AddSql(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.SqlBatchStartActivity));
                    break;
                case "CloudBatchStart":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudBatchStartActivity));
                    break;
                case "BatchWait":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudBatchWaitActivity));
                    break;
                case "DatabaseBatchWait":
                    SubProcessFiles.AddSql(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.SqlBatchWaitActivity));
                    break;
                case "Corticon":
                    SubProcessFiles.AddClass(Store, ((Activity)element).VisioId, btProcess.VisioId, FileTypes.getFileType(FileType.CloudCorticonActivity));
                    break;
            }

            return base.CreateChildShape(element);

        }
 /// <summary>
 /// Gets a list of PropertyAssignments for all assignable properties.
 /// </summary>
 /// <param name="element">Element to get PropertyAssignments for.</param>
 /// <returns>List of PropertyAssignment.</returns>
 public static List<PropertyAssignment> GetAssignablePropertyValues(ModelElement element)
 {
     List<PropertyAssignment> list = new List<PropertyAssignment>();
     ReadOnlyCollection<DomainPropertyInfo> readOnlyCollection = element.GetDomainClass().AllDomainProperties;
     foreach (DomainPropertyInfo domainPropertyInfo in readOnlyCollection)
     {
         if (domainPropertyInfo.Kind != Microsoft.VisualStudio.Modeling.DomainPropertyKind.Calculated)
         {
             object obj = domainPropertyInfo.GetValue(element);
             if (obj != null)
                 list.Add(new PropertyAssignment(domainPropertyInfo.Id, obj));
         }
     }
     return list;
 }