Esempio n. 1
0
        public void CopyLayoutInformationFrom(View source)
        {
            if (PaperSize == null)
            {
                PaperSize = source.PaperSize;
            }

            foreach (ElementView sourceElementView in source.Elements)
            {
                ElementView destinationElementView = FindElementView(sourceElementView);
                if (destinationElementView != null)
                {
                    destinationElementView.CopyLayoutInformationFrom(sourceElementView);
                }
            }

            foreach (RelationshipView sourceRelationshipView in source.Relationships)
            {
                RelationshipView destinationRelationshipView = FindRelationshipView(sourceRelationshipView);
                if (destinationRelationshipView != null)
                {
                    destinationRelationshipView.CopyLayoutInformationFrom(sourceRelationshipView);
                }
            }
        }
Esempio n. 2
0
        /**
         * Finds an element. Override this to change the behaviour.
         *
         * @param viewWithLayoutInformation             the view to search
         * @param elementWithoutLayoutInformation       the Element to find
         * @return  an ElementView
         */
        protected ElementView findElementView(View viewWithLayoutInformation, Element elementWithoutLayoutInformation)
        {
            // see if we can find an element with the same canonical name in the source view
            ElementView elementView = viewWithLayoutInformation.Elements.FirstOrDefault(ev => ev.Element.CanonicalName.Equals(elementWithoutLayoutInformation.CanonicalName));

            if (elementView == null)
            {
                // no element was found, so try finding an element of the same type with the same name (in this situation, the parent element may have been renamed)
                elementView = viewWithLayoutInformation.Elements.FirstOrDefault(ev => ev.Element.Name.Equals(elementWithoutLayoutInformation.Name) && ev.Element.GetType().Equals(elementWithoutLayoutInformation.GetType()));
            }

            if (elementView == null)
            {
                // no element was found, so try finding an element of the same type with the same description if set (in this situation, the element itself may have been renamed)
                if (!String.IsNullOrEmpty(elementWithoutLayoutInformation.Description))
                {
                    elementView = viewWithLayoutInformation.Elements.FirstOrDefault(ev => elementWithoutLayoutInformation.Description.Equals(ev.Element.Description) && ev.Element.GetType().Equals(elementWithoutLayoutInformation.GetType()));
                }
            }

            if (elementView == null)
            {
                // no element was found, so try finding an element of the same type with the same ID (in this situation, the name and description may have changed)
                elementView = viewWithLayoutInformation.Elements.FirstOrDefault(ev => ev.Element.Id.Equals(elementWithoutLayoutInformation.Id) && ev.Element.GetType().Equals(elementWithoutLayoutInformation.GetType()));
            }

            return(elementView);
        }
Esempio n. 3
0
        private ElementView FindElementView(ElementView sourceElementView)
        {
            foreach (ElementView elementView in Elements)
            {
                if (elementView.Element.Equals(sourceElementView.Element))
                {
                    return(elementView);
                }
            }

            return(null);
        }
Esempio n. 4
0
        protected void RemoveElement(Element element)
        {
            if (element != null)
            {
                ElementView elementView = new ElementView(element);
                _elements.Remove(elementView);

                _relationships.RemoveWhere(r =>
                                           r.Relationship.Source.Equals(element) ||
                                           r.Relationship.Destination.Equals(element));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Attempts to copy the visual layout information (e.g. x,y coordinates) of elements and relationships
        /// from the specified source view into the specified destination view.
        /// </summary>
        /// <param name="viewWithLayoutInformation">the source view (e.g. the version stored by the Structurizr service)</param>
        /// <param name="viewWithoutLayoutInformation">the destination View (e.g. the new version, created locally with code)</param>
        public void CopyLayoutInformation(View viewWithLayoutInformation, View viewWithoutLayoutInformation)
        {
            setPaperSizeIfNotSpecified(viewWithLayoutInformation, viewWithoutLayoutInformation);

            Dictionary <ElementView, ElementView> elementViewMap = new Dictionary <ElementView, ElementView>();
            Dictionary <Element, Element>         elementMap     = new Dictionary <Element, Element>();

            foreach (ElementView elementViewWithoutLayoutInformation in viewWithoutLayoutInformation.Elements)
            {
                ElementView elementViewWithLayoutInformation = findElementView(viewWithLayoutInformation, elementViewWithoutLayoutInformation.Element);
                if (elementViewWithLayoutInformation != null)
                {
                    elementViewMap.Add(elementViewWithoutLayoutInformation, elementViewWithLayoutInformation);
                    elementMap.Add(elementViewWithoutLayoutInformation.Element, elementViewWithLayoutInformation.Element);
                }
                else
                {
                    Console.WriteLine("There is no layout information for the element named " + elementViewWithoutLayoutInformation.Element.Name + " on view " + viewWithLayoutInformation.Key);
                }
            }

            foreach (ElementView elementViewWithoutLayoutInformation in elementViewMap.Keys)
            {
                ElementView elementViewWithLayoutInformation = elementViewMap[elementViewWithoutLayoutInformation];
                elementViewWithoutLayoutInformation.CopyLayoutInformationFrom(elementViewWithLayoutInformation);
            }

            foreach (RelationshipView relationshipViewWithoutLayoutInformation in viewWithoutLayoutInformation.Relationships)
            {
                RelationshipView relationshipViewWithLayoutInformation;
                if (viewWithoutLayoutInformation is DynamicView)
                {
                    relationshipViewWithLayoutInformation = findRelationshipView(viewWithLayoutInformation, relationshipViewWithoutLayoutInformation, elementMap);
                }
                else
                {
                    relationshipViewWithLayoutInformation = findRelationshipView(viewWithLayoutInformation, relationshipViewWithoutLayoutInformation.Relationship, elementMap);
                }

                if (relationshipViewWithLayoutInformation != null)
                {
                    relationshipViewWithoutLayoutInformation.CopyLayoutInformationFrom(relationshipViewWithLayoutInformation);
                }
            }
        }