Exemplo n.º 1
0
        private void PopulateWorkspace()
        {
            Model model = _workspace.Model;

            model.Enterprise = new Enterprise("Some Enterprise");

            Person         user           = model.AddPerson(Location.Internal, "User", "");
            SoftwareSystem softwareSystem = model.AddSoftwareSystem(Location.Internal, "Software System", "");

            user.Uses(softwareSystem, "Uses");

            SoftwareSystem emailSystem = model.AddSoftwareSystem(Location.External, "E-mail System", "");

            softwareSystem.Uses(emailSystem, "Sends e-mail using");
            emailSystem.Delivers(user, "Delivers e-mails to");

            Container webApplication = softwareSystem.AddContainer("Web Application", "", "");
            Container database       = softwareSystem.AddContainer("Database", "", "");

            user.Uses(webApplication, "Uses", "HTTP");
            webApplication.Uses(database, "Reads from and writes to", "JDBC");
            webApplication.Uses(emailSystem, "Sends e-mail using");

            Component controller     = webApplication.AddComponent("SomeController", "", "Spring MVC Controller");
            Component emailComponent = webApplication.AddComponent("EmailComponent", "");
            Component repository     = webApplication.AddComponent("SomeRepository", "", "Spring Data");

            user.Uses(controller, "Uses", "HTTP");
            controller.Uses(repository, "Uses");
            controller.Uses(emailComponent, "Sends e-mail using");
            repository.Uses(database, "Reads from and writes to", "JDBC");
            emailComponent.Uses(emailSystem, "Sends e-mails using", "SMTP");

            EnterpriseContextView enterpriseContextView = _workspace.Views.CreateEnterpriseContextView("enterpriseContext", "");

            enterpriseContextView.AddAllElements();

            SystemContextView systemContextView = _workspace.Views.CreateSystemContextView(softwareSystem, "systemContext", "");

            systemContextView.AddAllElements();

            ContainerView containerView = _workspace.Views.CreateContainerView(softwareSystem, "containers", "");

            containerView.AddAllElements();

            ComponentView componentView = _workspace.Views.CreateComponentView(webApplication, "components", "");

            componentView.AddAllElements();

            DynamicView dynamicView = _workspace.Views.CreateDynamicView(webApplication, "dynamic", "");

            dynamicView.Add(user, "Requests /something", controller);
            dynamicView.Add(controller, repository);
            dynamicView.Add(repository, "select * from something", database);
        }
Exemplo n.º 2
0
        private static void CreateContosoExample(int workSpaceId, string apiKey, string apiSecret)
        {
            Workspace workspace = new Workspace("Contoso University", "A software architecture model of the Contoso University sample project.");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;
            Styles    styles    = views.Configuration.Styles;

            Person         universityStaff   = model.AddPerson("University Staff", "A staff member of the Contoso University.");
            SoftwareSystem contosoUniversity = model.AddSoftwareSystem("Contoso University", "Allows staff to view and update student, course, and instructor information.");

            universityStaff.Uses(contosoUniversity, "uses");

            SystemContextView contextView = views.CreateSystemContextView(contosoUniversity, "Context", "The system context view for the Contoso University system.");

            contextView.AddAllElements();

            #region Containers

            //Container webApplication = contosoUniversity.AddContainer("Web Application", "Allows staff to view and update student, course, and instructor information.", "Microsoft ASP.NET MVC");
            //Container database = contosoUniversity.AddContainer("Database", "Stores information about students, courses and instructors", "Microsoft SQL Server Express LocalDB");
            //database.AddTags("Database");
            //database.Url = "https://github.com/simonbrowndotje/ContosoUniversity/tree/master/ContosoUniversity/Migrations";

            //universityStaff.Uses(webApplication, "Uses", "HTTPS");
            //webApplication.Uses(database, "Reads from and writes to");

            //ContainerView containerView = views.CreateContainerView(contosoUniversity, "Containers", "The containers that make up the Contoso University system.");
            //containerView.AddAllElements();

            #endregion

            #region Dynamic components

            //ComponentFinder componentFinder = new ComponentFinder(
            //    webApplication,
            //    typeof(ContosoUniversity.MvcApplication).Namespace,
            //    new TypeBasedComponentFinderStrategy(
            //        new InterfaceImplementationTypeMatcher(typeof(System.Web.Mvc.IController), null, "ASP.NET MVC Controller"),
            //        new ExtendsClassTypeMatcher(typeof(System.Data.Entity.DbContext), null, "Entity Framework DbContext")
            //    )
            //);
            //componentFinder.FindComponents();

            //// connect the user to the web MVC controllers
            //webApplication.Components.ToList().FindAll(c => c.Technology == "ASP.NET MVC Controller").ForEach(c => universityStaff.Uses(c, "uses"));

            //// connect all DbContext components to the database
            //webApplication.Components.ToList().FindAll(c => c.Technology == "Entity Framework DbContext").ForEach(c => c.Uses(database, "Reads from and writes to"));

            //ComponentView componentView = views.CreateComponentView(webApplication, "Components", "The components inside the Contoso University web application.");
            //componentView.AddAllElements();

            #endregion

            #region Documentation

            //Documentation documentation = workspace.Documentation;
            //FileInfo documentationRoot = new FileInfo(@"..\..\ContosoDocs");
            //documentation.Add(contosoUniversity, SectionType.Context, DocumentationFormat.Markdown,
            //    new FileInfo(Path.Combine(documentationRoot.FullName, "context.md")));
            //documentation.Add(contosoUniversity, SectionType.FunctionalOverview, DocumentationFormat.Markdown,
            //    new FileInfo(Path.Combine(documentationRoot.FullName, "functional-overview.md")));
            //documentation.Add(contosoUniversity, SectionType.QualityAttributes, DocumentationFormat.Markdown,
            //    new FileInfo(Path.Combine(documentationRoot.FullName, "quality-attributes.md")));
            //documentation.AddImages(documentationRoot);

            #endregion

            // add some styling
            styles.Add(new ElementStyle(Tags.Person)
            {
                Background = "#0d4d4d", Color = "#ffffff", Shape = Shape.Person
            });
            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#003333", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.Container)
            {
                Background = "#226666", Color = "#ffffff"
            });
            styles.Add(new ElementStyle("Database")
            {
                Shape = Shape.Cylinder
            });
            styles.Add(new ElementStyle(Tags.Component)
            {
                Background = "#407f7f", Color = "#ffffff"
            });

            StructurizrClient structurizrClient = new StructurizrClient(apiKey, apiSecret);
            structurizrClient.PutWorkspace(workSpaceId, workspace);
        }
Exemplo n.º 3
0
 public void test_AddAllElements_DoesNothing_WhenThereAreNoSoftwareSystemsOrPeople()
 {
     Assert.AreEqual(1, view.Elements.Count);
     view.AddAllElements();
     Assert.AreEqual(1, view.Elements.Count);
 }
Exemplo n.º 4
0
        static void Main()
        {
            Workspace workspace = new Workspace("Structurizr for .NET Annotations", "This is a model of my software system.");
            Model     model     = workspace.Model;

            Person         user           = model.AddPerson("User", "A user of my software system.");
            SoftwareSystem softwareSystem = model.AddSoftwareSystem("Software System", "My software system.");

            Container webApplication = softwareSystem.AddContainer("Web Application", "Provides users with information.", "C#");
            Container database       = softwareSystem.AddContainer("Database", "Stores information.", "Relational database schema");

            database.AddTags(DatabaseTag);

            string assemblyPath = typeof(StructurizrAnnotations).Assembly.Location;
            DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();

            resolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath));
            AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(
                assemblyPath,
                new ReaderParameters {
                AssemblyResolver = resolver
            }
                );

            ComponentFinder componentFinder = new ComponentFinder(
                webApplication,
                "Structurizr.Examples.Annotations",
                new StructurizrAnnotationsComponentFinderStrategy(assembly)
                );

            componentFinder.FindComponents();
            model.AddImplicitRelationships();

            ViewSet           views       = workspace.Views;
            SystemContextView contextView = views.CreateSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram.");

            contextView.AddAllElements();

            ContainerView containerView = views.CreateContainerView(softwareSystem, "Containers", "The container diagram from my software system.");

            containerView.AddAllElements();

            ComponentView componentView = views.CreateComponentView(webApplication, "Components", "The component diagram for the web application.");

            componentView.AddAllElements();

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Element)
            {
                Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#1168bd"
            });
            styles.Add(new ElementStyle(Tags.Container)
            {
                Background = "#438dd5"
            });
            styles.Add(new ElementStyle(Tags.Component)
            {
                Background = "#85bbf0", Color = "#000000"
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Background = "#08427b", Shape = Shape.Person
            });
            styles.Add(new ElementStyle(DatabaseTag)
            {
                Shape = Shape.Cylinder
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
        private void PopulateWorkspace()
        {
            Model   model = _workspace.Model;
            ViewSet views = _workspace.Views;

            model.Enterprise = new Enterprise("Some Enterprise");

            Person         user           = model.AddPerson(Location.Internal, "User", "");
            SoftwareSystem softwareSystem = model.AddSoftwareSystem(Location.Internal, "Software System", "");

            user.Uses(softwareSystem, "Uses");

            SoftwareSystem emailSystem = model.AddSoftwareSystem(Location.External, "E-mail System", "");

            softwareSystem.Uses(emailSystem, "Sends e-mail using");
            emailSystem.Delivers(user, "Delivers e-mails to");

            Container webApplication = softwareSystem.AddContainer("Web Application", "", "");
            Container database       = softwareSystem.AddContainer("Database", "", "");

            user.Uses(webApplication, null, "HTTP");
            webApplication.Uses(database, "Reads from and writes to", "JDBC");
            webApplication.Uses(emailSystem, "Sends e-mail using");

            Component controller     = webApplication.AddComponent("SomeController", "", "Spring MVC Controller");
            Component emailComponent = webApplication.AddComponent("EmailComponent", "");
            Component repository     = webApplication.AddComponent("SomeRepository", "", "Spring Data");

            user.Uses(controller, "Uses", "HTTP");
            controller.Uses(repository, "Uses");
            controller.Uses(emailComponent, "Sends e-mail using");
            repository.Uses(database, "Reads from and writes to", "JDBC");
            emailComponent.Uses(emailSystem, "Sends e-mails using", "SMTP");

            DeploymentNode webServer = model.AddDeploymentNode("Web Server", "A server hosted at AWS EC2.", "Ubuntu 12.04 LTS");

            webServer.AddDeploymentNode("Apache Tomcat", "The live web server", "Apache Tomcat 8.x")
            .Add(webApplication);
            DeploymentNode databaseServer = model.AddDeploymentNode("Database Server", "A server hosted at AWS EC2.", "Ubuntu 12.04 LTS");

            databaseServer.AddDeploymentNode("MySQL", "The live database server", "MySQL 5.5.x")
            .Add(database);

            SystemLandscapeView
                systemLandscapeView = views.CreateSystemLandscapeView("enterpriseContext", "");

            systemLandscapeView.AddAllElements();

            SystemContextView systemContextView = views.CreateSystemContextView(softwareSystem, "systemContext", "");

            systemContextView.AddAllElements();

            ContainerView containerView = views.CreateContainerView(softwareSystem, "containers", "");

            containerView.AddAllElements();

            ComponentView componentView = views.CreateComponentView(webApplication, "components", "");

            componentView.AddAllElements();

            DynamicView dynamicView = views.CreateDynamicView(webApplication, "dynamic", "");

            dynamicView.Add(user, "Requests /something", controller);
            dynamicView.Add(controller, repository);
            dynamicView.Add(repository, "select * from something", database);

            DeploymentView deploymentView = views.CreateDeploymentView(softwareSystem, "deployment", "");

            deploymentView.AddAllDeploymentNodes();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Workspace workspace = new Workspace("Contoso University", "A software architecture model of the Contoso University sample project.");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;
            Styles    styles    = views.Configuration.Styles;

            Person         universityStaff   = model.AddPerson("University Staff", "A staff member of the Contoso University.");
            SoftwareSystem contosoUniversity = model.AddSoftwareSystem("Contoso University", "Allows staff to view and update student, course, and instructor information.");

            universityStaff.Uses(contosoUniversity, "uses");

            // if the client-side of this application was richer (e.g. it was a single-page app), I would include the web browser
            // as a container (i.e. User --uses-> Web Browser --uses-> Web Application (backend for frontend) --uses-> Database)
            Container webApplication = contosoUniversity.AddContainer("Web Application", "Allows staff to view and update student, course, and instructor information.", "Microsoft ASP.NET MVC");
            Container database       = contosoUniversity.AddContainer("Database", "Stores information about students, courses and instructors", "Microsoft SQL Server Express LocalDB");

            database.AddTags("Database");
            universityStaff.Uses(webApplication, "Uses", "HTTPS");
            webApplication.Uses(database, "Reads from and writes to");

            DirectoryInfo directory = new DirectoryInfo(AssemblyLocation);

            foreach (FileInfo file in directory.EnumerateFiles())
            {
                if (file.Extension == ".dll")
                {
                    Assembly.LoadFrom(file.FullName);
                }
            }

            Type iController = Assembly.LoadFrom(Path.Combine(AssemblyLocation, "System.Web.Mvc.dll")).GetType("System.Web.Mvc.IController");
            Type dbContext   = Assembly.LoadFrom(Path.Combine(AssemblyLocation, "EntityFramework.dll")).GetType("System.Data.Entity.DbContext");

            TypeMatcherComponentFinderStrategy typeMatcherComponentFinderStrategy = new TypeMatcherComponentFinderStrategy(
                new InterfaceImplementationTypeMatcher(iController, null, "ASP.NET MVC Controller"),
                new ExtendsClassTypeMatcher(dbContext, null, "Entity Framework DbContext")
                );

            typeMatcherComponentFinderStrategy.AddSupportingTypesStrategy(new ReferencedTypesSupportingTypesStrategy(false));

            ComponentFinder componentFinder = new ComponentFinder(
                webApplication,
                "ContosoUniversity",
                typeMatcherComponentFinderStrategy
                //new TypeSummaryComponentFinderStrategy(@"C:\Users\simon\ContosoUniversity\ContosoUniversity.sln", "ContosoUniversity")
                );

            componentFinder.FindComponents();

            // connect the user to the web MVC controllers
            webApplication.Components.ToList().FindAll(c => c.Technology == "ASP.NET MVC Controller").ForEach(c => universityStaff.Uses(c, "uses"));

            // connect all DbContext components to the database
            webApplication.Components.ToList().FindAll(c => c.Technology == "Entity Framework DbContext").ForEach(c => c.Uses(database, "Reads from and writes to"));

            // link the components to the source code
            foreach (Component component in webApplication.Components)
            {
                foreach (CodeElement codeElement in component.CodeElements)
                {
                    if (codeElement.Url != null)
                    {
                        codeElement.Url = codeElement.Url.Replace(new Uri(@"C:\Users\simon\ContosoUniversity\").AbsoluteUri, "https://github.com/simonbrowndotje/ContosoUniversity/blob/master/");
                        codeElement.Url = codeElement.Url.Replace('\\', '/');
                    }
                }
            }

            // rather than creating a component model for the database, let's simply link to the DDL
            // (this is really just an example of linking an arbitrary element in the model to an external resource)
            database.Url = "https://github.com/simonbrowndotje/ContosoUniversity/tree/master/ContosoUniversity/Migrations";

            SystemContextView contextView = views.CreateSystemContextView(contosoUniversity, "Context", "The system context view for the Contoso University system.");

            contextView.AddAllElements();

            ContainerView containerView = views.CreateContainerView(contosoUniversity, "Containers", "The containers that make up the Contoso University system.");

            containerView.AddAllElements();

            ComponentView componentView = views.CreateComponentView(webApplication, "Components", "The components inside the Contoso University web application.");

            componentView.AddAllElements();

            // create an example dynamic view for a feature
            DynamicView dynamicView      = views.CreateDynamicView(webApplication, "GetCoursesForDepartment", "A summary of the \"get courses for department\" feature.");
            Component   courseController = webApplication.GetComponentWithName("CourseController");
            Component   schoolContext    = webApplication.GetComponentWithName("SchoolContext");

            dynamicView.Add(universityStaff, "Requests the list of courses from", courseController);
            dynamicView.Add(courseController, "Uses", schoolContext);
            dynamicView.Add(schoolContext, "Gets a list of courses from", database);

            // add some styling
            styles.Add(new ElementStyle(Tags.Person)
            {
                Background = "#0d4d4d", Color = "#ffffff", Shape = Shape.Person
            });
            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#003333", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.Container)
            {
                Background = "#226666", Color = "#ffffff"
            });
            styles.Add(new ElementStyle("Database")
            {
                Shape = Shape.Cylinder
            });
            styles.Add(new ElementStyle(Tags.Component)
            {
                Background = "#407f7f", Color = "#ffffff"
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Exemplo n.º 7
0
        static void Main()
        {
            Workspace workspace = new Workspace("adr-tools", "A description of the adr-tools command line utility.");
            Model     model     = workspace.Model;

            Person         user     = model.AddPerson("User", "Somebody on a software development team.");
            SoftwareSystem adrTools = model.AddSoftwareSystem("adr-tools", "A command-line tool for working with Architecture Decision Records (ADRs).");

            adrTools.Url = "https://github.com/npryce/adr-tools";

            Container adrShellScripts = adrTools.AddContainer("adr", "A command-line tool for working with Architecture Decision Records (ADRs).", "Shell Scripts");

            adrShellScripts.Url = "https://github.com/npryce/adr-tools/tree/master/src";
            Container fileSystem = adrTools.AddContainer("File System", "Stores ADRs, templates, etc.", "File System");

            fileSystem.AddTags(FileSystemTag);
            user.Uses(adrShellScripts, "Manages ADRs using");
            adrShellScripts.Uses(fileSystem, "Reads from and writes to");
            model.AddImplicitRelationships();

            ViewSet           views       = workspace.Views;
            SystemContextView contextView = views.CreateSystemContextView(adrTools, "SystemContext", "The system context diagram for adr-tools.");

            contextView.AddAllElements();

            ContainerView containerView = views.CreateContainerView(adrTools, "Containers", "The container diagram for adr-tools.");

            containerView.AddAllElements();

            DirectoryInfo adrDirectory = new DirectoryInfo("Documentation" + Path.DirectorySeparatorChar + "adr");

            AdrToolsImporter adrToolsImporter = new AdrToolsImporter(workspace, adrDirectory);

            adrToolsImporter.ImportArchitectureDecisionRecords(adrTools);

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Element)
            {
                Shape = Shape.RoundedBox, Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#18ADAD", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person, Background = "#008282", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.Container)
            {
                Background = "#6DBFBF"
            });
            styles.Add(new ElementStyle(FileSystemTag)
            {
                Shape = Shape.Folder
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }