Пример #1
0
        public RelationshipView Add(StaticStructureElement source, string description, StaticStructureElement destination)
        {
            if (source == null)
            {
                throw new ArgumentException("A source element must be specified.");
            }

            if (destination == null)
            {
                throw new ArgumentException("A destination element must be specified.");
            }

            CheckElementCanBeAdded(source);
            CheckElementCanBeAdded(destination);

            // check that the relationship is in the model before adding it
            Relationship relationship = source.GetEfferentRelationshipWith(destination);

            if (relationship != null)
            {
                AddElement(source, false);
                AddElement(destination, false);

                return(AddRelationship(relationship, description, _sequenceNumber.GetNext(), false));
            }
            else
            {
                // perhaps model this as a return/reply/response message instead, if the reverse relationship exists
                relationship = destination.GetEfferentRelationshipWith(source);

                if (relationship != null)
                {
                    AddElement(source, false);
                    AddElement(destination, false);

                    return(AddRelationship(relationship, description, _sequenceNumber.GetNext(), true));
                }
                else
                {
                    throw new ArgumentException("A relationship between " + source.Name + " and " + destination.Name + " does not exist in model.");
                }
            }
        }
Пример #2
0
        private void checkParentAndChildrenHaveNotAlreadyBeenAdded(StaticStructureElement elementToBeAdded)
        {
            // check the parent hasn't been added already
            ISet <String> elementIds = new HashSet <string>(Elements.Select(ev => ev.Element.Id));

            if (elementToBeAdded.Parent != null)
            {
                if (elementIds.Contains(elementToBeAdded.Parent.Id))
                {
                    throw new ElementNotPermittedInViewException("The parent of " + elementToBeAdded.Name + " is already in this view.");
                }
            }

            // and now check a child hasn't been added already
            ISet <String> elementParentIds = new HashSet <string>(Elements.Where(ev => ev.Element.Parent != null).Select(ev => ev.Element.Parent.Id));

            if (elementParentIds.Contains(elementToBeAdded.Id))
            {
                throw new ElementNotPermittedInViewException("The child of " + elementToBeAdded.Name + " is already in this view.");
            }
        }
Пример #3
0
        private void ReplicateElementRelationships(StaticStructureElementInstance elementInstance)
        {
            StaticStructureElement element = elementInstance.getElement();

            // find all StaticStructureElementInstance objects in the same deployment environment and deployment group
            IEnumerable <StaticStructureElementInstance> elementInstances = GetElements().OfType <StaticStructureElementInstance>().Where(ssei => ssei.Environment.Equals(elementInstance.Environment) && ssei.DeploymentGroup.Equals(elementInstance.DeploymentGroup));

            // and replicate the relationships to/from the element instance
            foreach (StaticStructureElementInstance ssei in elementInstances)
            {
                StaticStructureElement sse = ssei.getElement();

                foreach (Relationship relationship in element.Relationships)
                {
                    if (relationship.Destination.Equals(sse))
                    {
                        Relationship newRelationship = AddRelationship(elementInstance, ssei, relationship.Description, relationship.Technology, relationship.InteractionStyle);
                        if (newRelationship != null)
                        {
                            newRelationship.Tags = null;
                            newRelationship.LinkedRelationshipId = relationship.Id;
                        }
                    }
                }

                foreach (Relationship relationship in sse.Relationships)
                {
                    if (relationship.Destination.Equals(element))
                    {
                        Relationship newRelationship = AddRelationship(ssei, elementInstance, relationship.Description, relationship.Technology, relationship.InteractionStyle);
                        if (newRelationship != null)
                        {
                            newRelationship.Tags = null;
                            newRelationship.LinkedRelationshipId = relationship.Id;
                        }
                    }
                }
            }
        }
Пример #4
0
        protected override void CheckElementCanBeAdded(Element elementToBeAdded)
        {
            if (!(elementToBeAdded is StaticStructureElement))
            {
                throw new ElementNotPermittedInViewException(
                          "Only people, software systems, containers and components can be added to dynamic views.");
            }

            StaticStructureElement staticStructureElementToBeAdded = (StaticStructureElement)elementToBeAdded;

            // people can always be added
            if (staticStructureElementToBeAdded is Person)
            {
                return;
            }

            // if the scope of this dynamic view is a software system, we only want:
            //  - containers
            //  - other software systems
            if (Element is SoftwareSystem)
            {
                if (staticStructureElementToBeAdded.Equals(Element))
                {
                    throw new ElementNotPermittedInViewException(
                              staticStructureElementToBeAdded.Name +
                              " is already the scope of this view and cannot be added to it.");
                }

                if (staticStructureElementToBeAdded is SoftwareSystem ||
                    staticStructureElementToBeAdded is Container)
                {
                    checkParentAndChildrenHaveNotAlreadyBeenAdded(staticStructureElementToBeAdded);
                }
                else if (staticStructureElementToBeAdded is Component)
                {
                    throw new ElementNotPermittedInViewException(
                              "Components can't be added to a dynamic view when the scope is a software system.");
                }
            }

            // dynamic view with container scope:
            //  - other containers
            //  - components
            if (Element is Container)
            {
                if (staticStructureElementToBeAdded.Equals(Element) ||
                    staticStructureElementToBeAdded.Equals(Element.Parent))
                {
                    throw new ElementNotPermittedInViewException(
                              staticStructureElementToBeAdded.Name +
                              " is already the scope of this view and cannot be added to it.");
                }

                checkParentAndChildrenHaveNotAlreadyBeenAdded(staticStructureElementToBeAdded);
            }

            // dynamic view with no scope
            //  - software systems
            if (Element == null)
            {
                if (!(staticStructureElementToBeAdded is SoftwareSystem))
                {
                    throw new ElementNotPermittedInViewException(
                              "Only people and software systems can be added to this dynamic view.");
                }
            }
        }
Пример #5
0
 public RelationshipView Add(StaticStructureElement source, StaticStructureElement destination)
 {
     return(Add(source, "", destination));
 }