Ejemplo n.º 1
0
        protected PersonBase(Workspace workspace, Action <ElementType, string> onCreatedFromExistingElement)
            : base(workspace.Views.Configuration.Styles, onCreatedFromExistingElement)
        {
            Workspace = workspace;
            if (!TryGetMetadata(out string description, out Location location))
            {
                throw new System.Exception($"Missing PersonAttribute on Person {GetType().Name}");
            }

            StyleContainer = workspace.Views.Configuration.Styles;
            Styles         = new ElementStyleBase[0];

            var name   = NamedIdentity.GetNameFromType(GetType());
            var person = workspace.Model.GetPersonWithName(name);

            if (person == null)
            {
                person = workspace.Model.AddPerson(location, name, description);
            }
            else
            {
                onCreatedFromExistingElement(ElementType.Element, person.Id);
                person.Location    = location;
                person.Description = description;
            }
            Element = Me = person;
        }
Ejemplo n.º 2
0
        protected SoftwareSystemBase(Workspace workspace, Action <ElementType, string> onCreatedFromExistingElement)
            : base(workspace.Views.Configuration.Styles, onCreatedFromExistingElement)
        {
            Workspace = workspace;
            _onCreatedFromExistingElement = onCreatedFromExistingElement;

            Styles     = new ElementStyleBase[0];
            Containers = new ContainerBase[0];

            if (!TryGetMetadata(out string description, out Location location))
            {
                throw new System.Exception($"Missing SoftwareSystemAttribute on SoftwareSystem {GetType().Name}");
            }
            StyleContainer = workspace.Views.Configuration.Styles;
            var name           = NamedIdentity.GetNameFromType(GetType());
            var softwareSystem = workspace.Model.GetSoftwareSystemWithName(name);

            if (softwareSystem == null)
            {
                softwareSystem = workspace.Model.AddSoftwareSystem(location, name, description);
            }
            else
            {
                onCreatedFromExistingElement(ElementType.Element, softwareSystem.Id);
                softwareSystem.Location    = location;
                softwareSystem.Description = description;
            }
            Element = Me = softwareSystem;
        }
        protected ContainerBase(SoftwareSystem softwareSystem, Structurizr.Styles styleContainer, Action <ElementType, string> onCreatedFromExistingElement)
            : base(styleContainer, onCreatedFromExistingElement)
        {
            if (!TryGetMetadata(out string description, out string technology))
            {
                throw new System.Exception($"Missing ContainerAttribute on Container class {GetType().Name}");
            }

            SoftwareSystem = softwareSystem;
            StyleContainer = styleContainer;
            _onCreatedFromExistingElement = onCreatedFromExistingElement;

            Components = new ComponentBase[0];
            Styles     = new ElementStyleBase[0];

            var name      = NamedIdentity.GetNameFromType(GetType());
            var container = softwareSystem.GetContainerWithName(name);

            if (container == null)
            {
                container = softwareSystem.AddContainer(name, description, technology);
            }
            else
            {
                _onCreatedFromExistingElement(ElementType.Element, container.Id);
                container.Description = description;
                container.Technology  = technology;
            }
            Element = Me = container;
        }
        protected ComponentBase(Container container, Structurizr.Styles styleContainer, Action <ElementType, string> onCreatedFromExistingElement)
            : base(styleContainer, onCreatedFromExistingElement)
        {
            if (!TryGetMetadata(out string description, out string technology, out string type))
            {
                throw new System.Exception($"Missing ComponentAttribute on Component {GetType().Name}");
            }

            StyleContainer = styleContainer;
            Styles         = new ElementStyleBase[0];

            var name      = NamedIdentity.GetNameFromType(GetType());
            var component = container.GetComponentWithName(name);

            if (component == null)
            {
                if (type.Length > 0)
                {
                    try
                    {
                        component = container.AddComponent(name, description, technology, type);
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        throw new System.Exception($"The type parameter in the ComponentAttribute on {name} has an invalid value");
                    }
                }
                else
                {
                    component = container.AddComponent(name, description, technology);
                }
            }
            else
            {
                onCreatedFromExistingElement(ElementType.Element, component.Id);
                component.Description = description;
                component.Technology  = technology;
                component.Type        = type;
            }
            Element = Me = component;
        }