public void Test_Construction_WithThreeParameters_TruncatesTheApiUrl_WhenTheApiUrlHasATrailingSlashCharacter()
 {
     _structurizrClient = new StructurizrClient("https://localhost/", "key", "secret");
     Assert.Equal("https://localhost", _structurizrClient.Url);
     Assert.Equal("key", _structurizrClient.ApiKey);
     Assert.Equal("secret", _structurizrClient.ApiSecret);
 }
Ejemplo n.º 2
0
        static void Main()
        {
            Workspace workspace = new Workspace("Corporate Branding", "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.");

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person
            });

            StructurizrDocumentationTemplate template = new StructurizrDocumentationTemplate(workspace);

            template.AddContextSection(softwareSystem, Format.Markdown, "Here is some context about the software system...\n\n![](embed:SystemContext)");

            Branding branding = views.Configuration.Branding;

            branding.Logo = ImageUtils.GetImageAsDataUri(new FileInfo("structurizr-logo.png"));

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
        static void Main()
        {
            Workspace workspace = new Workspace("Documentation - Structurizr", "An empty software architecture document using the Structurizr template.");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;

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

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person
            });

            StructurizrDocumentationTemplate template = new StructurizrDocumentationTemplate(workspace);

            // this is the Markdown version
            DirectoryInfo documentationRoot = new DirectoryInfo("Documentation" + Path.DirectorySeparatorChar + "structurizr" + Path.DirectorySeparatorChar + "markdown");

            template.AddContextSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "01-context.md")));
            template.AddFunctionalOverviewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "02-functional-overview.md")));
            template.AddQualityAttributesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "03-quality-attributes.md")));
            template.AddConstraintsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "04-constraints.md")));
            template.AddPrinciplesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "05-principles.md")));
            template.AddSoftwareArchitectureSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "06-software-architecture.md")));
            template.AddDataSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "07-data.md")));
            template.AddInfrastructureArchitectureSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "08-infrastructure-architecture.md")));
            template.AddDeploymentSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "09-deployment.md")));
            template.AddDevelopmentEnvironmentSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "10-development-environment.md")));
            template.AddOperationAndSupportSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "11-operation-and-support.md")));
            template.AddDecisionLogSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "12-decision-log.md")));

            // this is the AsciiDoc version
//            DirectoryInfo documentationRoot = new DirectoryInfo("Documentation" + Path.DirectorySeparatorChar + "structurizr" + Path.DirectorySeparatorChar + "asciidoc");
//            template.AddContextSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "01-context.adoc")));
//            template.AddFunctionalOverviewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "02-functional-overview.adoc")));
//            template.AddQualityAttributesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "03-quality-attributes.adoc")));
//            template.AddConstraintsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "04-constraints.adoc")));
//            template.AddPrinciplesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "05-principles.adoc")));
//            template.AddSoftwareArchitectureSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "06-software-architecture.adoc")));
//            template.AddDataSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "07-data.adoc")));
//            template.AddInfrastructureArchitectureSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "08-infrastructure-architecture.adoc")));
//            template.AddDeploymentSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "09-deployment.adoc")));
//            template.AddDevelopmentEnvironmentSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "10-development-environment.adoc")));
//            template.AddOperationAndSupportSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "11-operation-and-support.adoc")));
//            template.AddDecisionLogSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "12-decision-log.adoc")));

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspaceAsync(WorkspaceId, workspace).Wait();
        }
        static void Main()
        {
            Workspace workspace = new Workspace("Styling Relationships", "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", "My web application.", "Java and Spring MVC");
            Container      database       = softwareSystem.AddContainer("Database", "My database.", "Relational database schema");

            user.Uses(webApplication, "Uses", "HTTPS");
            webApplication.Uses(database, "Reads from and writes to", "JDBC");

            ViewSet       views         = workspace.Views;
            ContainerView containerView = views.CreateContainerView(softwareSystem, "containers", "An example of a container diagram.");

            containerView.AddAllElements();

            Styles styles = workspace.Views.Configuration.Styles;

            // example 1
//            styles.Add(new RelationshipStyle(Tags.Relationship) { Color = "#ff0000" });

            // example 2
//            model.Relationships.Where(r => "HTTPS".Equals(r.Technology)).ToList().ForEach(r => r.AddTags("HTTPS"));
//            model.Relationships.Where(r => "JDBC".Equals(r.Technology)).ToList().ForEach(r => r.AddTags("JDBC"));
//            styles.Add(new RelationshipStyle("HTTPS") { Color = "#ff0000" });
//            styles.Add(new RelationshipStyle("JDBC") { Color = "#0000ff" });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Workspace workspace = new Workspace("RegAndElig", "Registration and Eligibility Model.");
            var       model     = workspace.Model;

            Person         user           = model.AddPerson("Service Provider", "A user of my software system.");
            SoftwareSystem softwareSystem = model.AddSoftwareSystem("Ess Web", "Web Front end.");

            user.Uses(softwareSystem, "Uses");

            ViewSet           viewSet = workspace.Views;
            SystemContextView contextView
                = viewSet.CreateSystemContextView(
                      softwareSystem, "context", "A simple example of a System Context diagram.");

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = viewSet.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#1168bd", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Background = "#08427b", Color = "#ffffff"
            });

            StructurizrClient structurizrClient = new StructurizrClient("key", "secret");

            structurizrClient.PutWorkspace(1234, workspace);
        }
Ejemplo n.º 6
0
        static void Main()
        {
            Workspace workspace = new Workspace("Documentation - arc42", "An empty software architecture document using the arc42 template.");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;

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

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person
            });

            Arc42DocumentationTemplate template = new Arc42DocumentationTemplate(workspace);

            // this is the Markdown version
            DirectoryInfo documentationRoot = new DirectoryInfo("Documentation" + Path.DirectorySeparatorChar + "arc42" + Path.DirectorySeparatorChar + "markdown");

            template.AddIntroductionAndGoalsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "01-introduction-and-goals.md")));
            template.AddConstraintsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "02-architecture-constraints.md")));
            template.AddContextAndScopeSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "03-system-scope-and-context.md")));
            template.AddSolutionStrategySection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "04-solution-strategy.md")));
            template.AddBuildingBlockViewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "05-building-block-view.md")));
            template.AddRuntimeViewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "06-runtime-view.md")));
            template.AddDeploymentViewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "07-deployment-view.md")));
            template.AddCrosscuttingConceptsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "08-crosscutting-concepts.md")));
            template.AddArchitecturalDecisionsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "09-architecture-decisions.md")));
            template.AddRisksAndTechnicalDebtSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "10-quality-requirements.md")));
            template.AddQualityRequirementsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "11-risks-and-technical-debt.md")));
            template.AddGlossarySection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "12-glossary.md")));

            // this is the AsciiDoc version
//            DirectoryInfo documentationRoot = new DirectoryInfo("Documentation" + Path.DirectorySeparatorChar + "arc42" + Path.DirectorySeparatorChar + "asciidoc");
//            template.AddIntroductionAndGoalsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "01-introduction-and-goals.adoc")));
//            template.AddConstraintsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "02-architecture-constraints.adoc")));
//            template.AddContextAndScopeSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "03-system-scope-and-context.adoc")));
//            template.AddSolutionStrategySection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "04-solution-strategy.adoc")));
//            template.AddBuildingBlockViewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "05-building-block-view.adoc")));
//            template.AddRuntimeViewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "06-runtime-view.adoc")));
//            template.AddDeploymentViewSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "07-deployment-view.adoc")));
//            template.AddCrosscuttingConceptsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "08-crosscutting-concepts.adoc")));
//            template.AddArchitecturalDecisionsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "09-architecture-decisions.adoc")));
//            template.AddRisksAndTechnicalDebtSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "10-quality-requirements.adoc")));
//            template.AddQualityRequirementsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "11-risks-and-technical-debt.adoc")));
//            template.AddGlossarySection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "12-glossary.adoc")));

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Ejemplo n.º 7
0
 public void Test_Construction_WithTwoParameters()
 {
     _structurizrClient = new StructurizrClient("key", "secret");
     Assert.Equal("https://api.structurizr.com", _structurizrClient.Url);
     Assert.Equal("key", _structurizrClient.ApiKey);
     Assert.Equal("secret", _structurizrClient.ApiSecret);
 }
Ejemplo n.º 8
0
 public void Test_Construction_WithThreeParameters()
 {
     _structurizrClient = new StructurizrClient("https://localhost", "key", "secret");
     Assert.Equal("https://localhost", _structurizrClient.Url);
     Assert.Equal("key", _structurizrClient.ApiKey);
     Assert.Equal("secret", _structurizrClient.ApiSecret);
 }
Ejemplo n.º 9
0
        static void Main()
        {
            Workspace workspace = new Workspace("Client-side encrypted workspace", "This is a client-side encrypted workspace. The passphrase is 'password'.");
            Model     model     = workspace.Model;

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

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = viewSet.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#d34407", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Background = "#f86628", Color = "#ffffff", Shape = Shape.Person
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.EncryptionStrategy = new AesEncryptionStrategy("password");
            structurizrClient.PutWorkspaceAsync(WorkspaceId, workspace).Wait();
        }
Ejemplo n.º 10
0
        static void Main()
        {
            Workspace workspace = new Workspace("Getting Started", "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.");

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = viewSet.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#1168bd", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Background = "#08427b", Color = "#ffffff", Shape = Shape.Person
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspaceAsync(WorkspaceId, workspace).Wait();
        }
Ejemplo n.º 11
0
        public void UploadWorkspaceToStructurizr(Workspace workspace, StructurizerOptions structurizerOptions)
        {
            var structurizrClient = new StructurizrClient(
                structurizerOptions.ApiKey,
                structurizerOptions.ApiSecret);

            structurizrClient.PutWorkspace(structurizerOptions.WorkspaceId, workspace);
        }
Ejemplo n.º 12
0
        private static void UploadWorkspaceToStructurizr(Workspace workspace)
        {
            var structurizrClient = new StructurizrClient(_apiKey, _apiSecret)
            {
                MergeFromRemote = false
            };

            structurizrClient.PutWorkspace(_workspaceId, workspace);
            Console.WriteLine($"Workspace can be viewed at {string.Format(WorkspaceUrlFormat, _workspaceId)}");
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Creating diagrams");

            var workspace = CreateWorkspace();

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Workspace workspace = new Workspace("Remote workspace", "A test remote workspace");

            workspace.Source = "https://gist.githubusercontent.com/simonbrowndotje/3bc87b89b82358c74f96470edc7519ad/raw/642ebcffb84e0c6ae612853919cf78b181bb65fe/structurizr-techtribesje.json";

            StructurizrClient structurizrClient = new StructurizrClient("key", "secret");

            structurizrClient.PutWorkspace(1234, workspace);
        }
        private static void UploadToStructurizr(string[] args)
        {
            var workspace = ArchitectureModel(new InfrastructureEnvironment("prod"));

            var configuration = Configuration(args);
            var client        = new StructurizrClient(configuration["Structurizr:Key"], configuration["Structurizr:Secret"])
            {
                WorkspaceArchiveLocation = null
            };

            client.PutWorkspace(int.Parse(configuration["Structurizr:WorkspaceId"]), workspace);
        }
Ejemplo n.º 16
0
 public void Test_Construction_ThrowsAnException_WhenANullApiUrlIsUsed()
 {
     try
     {
         _structurizrClient = new StructurizrClient(null, "key", "secret");
         throw new TestFailedException();
     }
     catch (ArgumentException iae)
     {
         Assert.Equal("The API URL must not be null or empty.", iae.Message);
     }
 }
Ejemplo n.º 17
0
 public void Test_PutWorkspace_ThrowsAnException_WhenTheWorkspaceIdIsNotValid()
 {
     try
     {
         _structurizrClient = new StructurizrClient("key", "secret");
         _structurizrClient.PutWorkspace(0, new Workspace("Name", "Description"));
         throw new TestFailedException();
     }
     catch (ArgumentException iae)
     {
         Assert.Equal("The workspace ID must be a positive integer.", iae.Message);
     }
 }
Ejemplo n.º 18
0
 public void Test_PutWorkspace_ThrowsAnException_WhenANullWorkspaceIsSpecified()
 {
     try
     {
         _structurizrClient = new StructurizrClient("key", "secret");
         _structurizrClient.PutWorkspace(1234, null);
         throw new TestFailedException();
     }
     catch (ArgumentException iae)
     {
         Assert.Equal("The workspace must not be null.", iae.Message);
     }
 }
Ejemplo n.º 19
0
 public void Test_GetWorkspace_ThrowsAnException_WhenTheWorkspaceIdIsNotValid()
 {
     try
     {
         _structurizrClient = new StructurizrClient("key", "secret");
         _structurizrClient.GetWorkspaceAsync(0).Wait();
         throw new TestFailedException();
     }
     catch (AggregateException iae)
     {
         Assert.Equal("The workspace ID must be a positive integer.", iae.InnerException.Message);
     }
 }
Ejemplo n.º 20
0
        static void Main()
        {
            Workspace workspace = new Workspace("Documentation - Viewpoints and Perspectives", "An empty software architecture document using the Viewpoints and Perspectives template.");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;

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

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person
            });

            ViewpointsAndPerspectivesDocumentation template = new ViewpointsAndPerspectivesDocumentation(workspace);

            // this is the Markdown version
            DirectoryInfo documentationRoot = new DirectoryInfo("Documentation" + Path.DirectorySeparatorChar + "viewpointsandperspectives" + Path.DirectorySeparatorChar + "markdown");

            template.AddIntroductionSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "01-introduction.md")));
            template.AddGlossarySection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "02-glossary.md")));
            template.AddSystemStakeholdersAndRequirementsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "03-system-stakeholders-and-requirements.md")));
            template.AddArchitecturalForcesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "04-architectural-forces.md")));
            template.AddArchitecturalViewsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "05-architectural-views")));
            template.AddSystemQualitiesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "06-system-qualities.md")));
            template.AddAppendicesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "07-appendices.md")));

            // this is the AsciiDoc version
//            DirectoryInfo documentationRoot = new DirectoryInfo("Documentation" + Path.DirectorySeparatorChar + "viewpointsandperspectives" + Path.DirectorySeparatorChar + "asciidoc");
//            template.AddIntroductionSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "01-introduction.adoc")));
//            template.AddGlossarySection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "02-glossary.adoc")));
//            template.AddSystemStakeholdersAndRequirementsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "03-system-stakeholders-and-requirements.adoc")));
//            template.AddArchitecturalForcesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "04-architectural-forces.adoc")));
//            template.AddArchitecturalViewsSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "05-architectural-views")));
//            template.AddSystemQualitiesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "06-system-qualities.adoc")));
//            template.AddAppendicesSection(softwareSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "07-appendices.adoc")));

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Ejemplo n.º 21
0
        static void Main()
        {
            Workspace workspace = new Workspace("HTTP-based health checks example", "An example of how to use the HTTP-based health checks feature");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;

            SoftwareSystem structurizr    = model.AddSoftwareSystem("Structurizr", "A publishing platform for software architecture diagrams and documentation based upon the C4 model.");
            Container      webApplication = structurizr.AddContainer("structurizr.com", "Provides all of the server-side functionality of Structurizr, serving static and dynamic content to users.", "Java and Spring MVC");
            Container      database       = structurizr.AddContainer("Database", "Stores information about users, workspaces, etc.", "Relational Database Schema");

            database.AddTags(DatabaseTag);
            webApplication.Uses(database, "Reads from and writes to", "JDBC");

            DeploymentNode    amazonWebServices  = model.AddDeploymentNode("Amazon Web Services", "", "us-east-1");
            DeploymentNode    pivotalWebServices = amazonWebServices.AddDeploymentNode("Pivotal Web Services", "Platform as a Service provider.", "Cloud Foundry");
            ContainerInstance liveWebApplication = pivotalWebServices.AddDeploymentNode("www.structurizr.com", "An open source Java EE web server.", "Apache Tomcat")
                                                   .Add(webApplication);
            ContainerInstance liveDatabaseInstance = amazonWebServices.AddDeploymentNode("Amazon RDS", "Database as a Service provider.", "MySQL")
                                                     .Add(database);

            // add health checks to the container instances, which return a simple HTTP 200 to say everything is okay
            liveWebApplication.AddHealthCheck("Web Application is running", "https://www.structurizr.com/health");
            liveDatabaseInstance.AddHealthCheck("Database is accessible from Web Application", "https://www.structurizr.com/health/database");

            // the pass/fail status from the health checks is used to supplement any deployment views that include the container instances that have health checks defined
            DeploymentView deploymentView = views.CreateDeploymentView(structurizr, "Deployment", "A deployment diagram showing the live environment.");

            deploymentView.Environment = "Live";
            deploymentView.AddAllDeploymentNodes();

            views.Configuration.Styles.Add(new ElementStyle(Tags.Element)
            {
                Color = "#ffffff"
            });
            views.Configuration.Styles.Add(new ElementStyle(DatabaseTag)
            {
                Shape = Shape.Cylinder
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            WorkspaceUtils.PrintWorkspaceAsJson(workspace);
            Console.ReadKey();
            structurizrClient.PutWorkspaceAsync(WorkspaceId, workspace).Wait();
        }
Ejemplo n.º 22
0
        static void Main()
        {
            Workspace workspace = new Workspace("Corporate Branding", "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.");

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person
            });

            StructurizrDocumentationTemplate template = new StructurizrDocumentationTemplate(workspace);

            template.AddContextSection(softwareSystem, Format.Markdown, "Here is some context about the software system...\n\n![](embed:SystemContext)");
            template.AddQualityAttributesSection(softwareSystem, Format.Markdown, "Here is some information about the quality attributes...");
            template.AddSoftwareArchitectureSection(softwareSystem, Format.Markdown, "Here is some information about the software architecture...");
            template.AddOperationAndSupportSection(softwareSystem, Format.Markdown, "Here is some information about how to operate and support the software...");
            template.AddDecisionLogSection(softwareSystem, Format.Markdown, "Here is some information about the decisions made...");

            Branding branding = views.Configuration.Branding;

            branding.Color1 = new ColorPair("#02172c", "#ffffff");
            branding.Color2 = new ColorPair("#08427b", "#ffffff");
            branding.Color3 = new ColorPair("#1168bd", "#ffffff");
            branding.Color4 = new ColorPair("#438dd5", "#ffffff");
            branding.Color5 = new ColorPair("#85bbf0", "#ffffff");
            branding.Logo   = ImageUtils.GetImageAsDataUri(new FileInfo("structurizr-logo.png"));

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Ejemplo n.º 23
0
        static void Main()
        {
            Workspace workspace = new Workspace("Filtered Views", "An example of using filtered views.");
            Model     model     = workspace.Model;

            Person         user            = model.AddPerson("User", "A description of the user.");
            SoftwareSystem softwareSystemA = model.AddSoftwareSystem("Software System A", "A description of software system A.");
            SoftwareSystem softwareSystemB = model.AddSoftwareSystem("Software System B", "A description of software system B.");

            softwareSystemB.AddTags(FutureState);

            user.Uses(softwareSystemA, "Uses for tasks 1 and 2").AddTags(CurrentState);
            user.Uses(softwareSystemA, "Uses for task 1").AddTags(FutureState);
            user.Uses(softwareSystemB, "Uses for task 2").AddTags(FutureState);

            ViewSet views = workspace.Views;
            EnterpriseContextView enterpriseContextView = views.CreateEnterpriseContextView("EnterpriseContext", "An example Enterprise Context diagram.");

            enterpriseContextView.AddAllElements();

            views.CreateFilteredView(enterpriseContextView, "CurrentState", "The current context.", FilterMode.Exclude, FutureState);
            views.CreateFilteredView(enterpriseContextView, "FutureState", "The future state context after Software System B is live.", FilterMode.Exclude, CurrentState);

            Styles styles = views.Configuration.Styles;

            styles.Add(new ElementStyle(Tags.Element)
            {
                Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Background = "#91a437", Shape = Shape.RoundedBox
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Background = "#6a7b15", Shape = Shape.Person
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Ejemplo n.º 24
0
        static void Main()
        {
            Workspace workspace = new Workspace("Styling Elements", "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", "My web application.", "Java and Spring MVC");
            Container      database       = softwareSystem.AddContainer("Database", "My database.", "Relational database schema");

            user.Uses(webApplication, "Uses", "HTTPS");
            webApplication.Uses(database, "Reads from and writes to", "JDBC");

            ViewSet       views         = workspace.Views;
            ContainerView containerView = views.CreateContainerView(softwareSystem, "containers", "An example of a container diagram.");

            containerView.AddAllElements();

            Styles styles = workspace.Views.Configuration.Styles;

            // example 1
//            styles.Add(new ElementStyle(Tags.Element) { Background = "#438dd5", Color = "#ffffff" });

            // example 2
//            styles.Add(new ElementStyle(Tags.Element) { Color = "#ffffff" });
//            styles.Add(new ElementStyle(Tags.Person) { Background = "#08427b" });
//            styles.Add(new ElementStyle(Tags.Container) { Background = "#438dd5" });

            // example 3
//            styles.Add(new ElementStyle(Tags.Element) { Color = "#ffffff" });
//            styles.Add(new ElementStyle(Tags.Person) { Background = "#08427b" , Shape = Shape.Person });
//            styles.Add(new ElementStyle(Tags.Container) { Background = "#438dd5" });
//            database.AddTags("Database");
//            styles.Add(new ElementStyle("Database") { Shape = Shape.Cylinder });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspaceAsync(WorkspaceId, workspace).Wait();
        }
Ejemplo n.º 25
0
        static void Main()
        {
            Workspace workspace = new Workspace("Theme", "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.");

            user.Uses(softwareSystem, "Uses");

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

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            // add a theme
            viewSet.Configuration.Theme = "https://raw.githubusercontent.com/structurizr/dotnet/master/Structurizr.Examples/Theme/theme.json";

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspaceAsync(WorkspaceId, workspace).Wait();
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        static void Main()
        {
            Workspace workspace = new Workspace("Widgets Limited", "Sells widgets to customers online.");
            Model     model     = workspace.Model;
            ViewSet   views     = workspace.Views;
            Styles    styles    = views.Configuration.Styles;

            model.Enterprise = new Enterprise("Widgets Limited");

            Person         customer            = model.AddPerson(Location.External, "Customer", "A customer of Widgets Limited.");
            Person         customerServiceUser = model.AddPerson(Location.Internal, "Customer Service Agent", "Deals with customer enquiries.");
            SoftwareSystem ecommerceSystem     = model.AddSoftwareSystem(Location.Internal, "E-commerce System", "Allows customers to buy widgets online via the widgets.com website.");
            SoftwareSystem fulfilmentSystem    = model.AddSoftwareSystem(Location.Internal, "Fulfilment System", "Responsible for processing and shipping of customer orders.");
            SoftwareSystem taxamo = model.AddSoftwareSystem(Location.External, "Taxamo", "Calculates local tax (for EU B2B customers) and acts as a front-end for Braintree Payments.");

            taxamo.Url = "https://www.taxamo.com";
            SoftwareSystem braintreePayments = model.AddSoftwareSystem(Location.External, "Braintree Payments", "Processes credit card payments on behalf of Widgets Limited.");

            braintreePayments.Url = "https://www.braintreepayments.com";
            SoftwareSystem jerseyPost = model.AddSoftwareSystem(Location.External, "Jersey Post", "Calculates worldwide shipping costs for packages.");

            model.People.Where(p => p.Location == Location.External).ToList().ForEach(p => p.AddTags(ExternalTag));
            model.People.Where(p => p.Location == Location.Internal).ToList().ForEach(p => p.AddTags(InternalTag));

            model.SoftwareSystems.Where(ss => ss.Location == Location.External).ToList().ForEach(ss => ss.AddTags(ExternalTag));
            model.SoftwareSystems.Where(ss => ss.Location == Location.Internal).ToList().ForEach(ss => ss.AddTags(InternalTag));

            customer.InteractsWith(customerServiceUser, "Asks questions to", "Telephone");
            customerServiceUser.Uses(ecommerceSystem, "Looks up order information using");
            customer.Uses(ecommerceSystem, "Places orders for widgets using");
            ecommerceSystem.Uses(fulfilmentSystem, "Sends order information to");
            fulfilmentSystem.Uses(jerseyPost, "Gets shipping charges from");
            ecommerceSystem.Uses(taxamo, "Delegates credit card processing to");
            taxamo.Uses(braintreePayments, "Uses for credit card processing");

            EnterpriseContextView enterpriseContextView = views.CreateEnterpriseContextView("EnterpriseContext", "The enterprise context for Widgets Limited.");

            enterpriseContextView.AddAllElements();

            SystemContextView ecommerceSystemContext = views.CreateSystemContextView(ecommerceSystem, "EcommerceSystemContext", "The system context diagram for the Widgets Limited e-commerce system.");

            ecommerceSystemContext.AddNearestNeighbours(ecommerceSystem);
            ecommerceSystemContext.Remove(customer.GetEfferentRelationshipWith(customerServiceUser));

            SystemContextView fulfilmentSystemContext = views.CreateSystemContextView(fulfilmentSystem, "FulfilmentSystemContext", "The system context diagram for the Widgets Limited fulfilment system.");

            fulfilmentSystemContext.AddNearestNeighbours(fulfilmentSystem);

            DynamicView dynamicView = views.CreateDynamicView("CustomerSupportCall", "A high-level overview of the customer support call process.");

            dynamicView.Add(customer, customerServiceUser);
            dynamicView.Add(customerServiceUser, ecommerceSystem);

            StructurizrDocumentationTemplate template = new StructurizrDocumentationTemplate(workspace);

            template.AddSection("Enterprise Context", 1, Format.Markdown, "Here is some information about the Widgets Limited enterprise context... ![](embed:EnterpriseContext)");
            template.AddContextSection(ecommerceSystem, Format.Markdown, "This is the context section for the E-commerce System... ![](embed:EcommerceSystemContext)");
            template.AddContextSection(fulfilmentSystem, Format.Markdown, "This is the context section for the Fulfilment System... ![](embed:FulfilmentSystemContext)");

            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Shape = Shape.RoundedBox
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Shape = Shape.Person
            });

            styles.Add(new ElementStyle(Tags.Element)
            {
                Color = "#ffffff"
            });
            styles.Add(new ElementStyle(ExternalTag)
            {
                Background = "#EC5381", Border = Border.Dashed
            });
            styles.Add(new ElementStyle(InternalTag)
            {
                Background = "#B60037"
            });

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
        static void Main()
        {
            Workspace workspace = new Workspace("Financial Risk System", "This is a simple (incomplete) example C4 model based upon the financial risk system architecture kata, which can be found at http://bit.ly/sa4d-risksystem");
            Model     model     = workspace.Model;

            SoftwareSystem financialRiskSystem = model.AddSoftwareSystem("Financial Risk System", "Calculates the bank's exposure to risk for product X.");

            Person businessUser = model.AddPerson("Business User", "A regular business user.");

            businessUser.Uses(financialRiskSystem, "Views reports using");

            Person configurationUser = model.AddPerson("Configuration User", "A regular business user who can also configure the parameters used in the risk calculations.");

            configurationUser.Uses(financialRiskSystem, "Configures parameters using");

            SoftwareSystem tradeDataSystem = model.AddSoftwareSystem("Trade Data System", "The system of record for trades of type X.");

            financialRiskSystem.Uses(tradeDataSystem, "Gets trade data from");

            SoftwareSystem referenceDataSystem = model.AddSoftwareSystem("Reference Data System", "Manages reference data for all counterparties the bank interacts with.");

            financialRiskSystem.Uses(referenceDataSystem, "Gets counterparty data from");

            SoftwareSystem referenceDataSystemV2 = model.AddSoftwareSystem("Reference Data System v2.0", "Manages reference data for all counterparties the bank interacts with.");

            referenceDataSystemV2.AddTags("Future State");
            financialRiskSystem.Uses(referenceDataSystemV2, "Gets counterparty data from").AddTags("Future State");

            SoftwareSystem emailSystem = model.AddSoftwareSystem("E-mail system", "The bank's Microsoft Exchange system.");

            financialRiskSystem.Uses(emailSystem, "Sends a notification that a report is ready to");
            emailSystem.Delivers(businessUser, "Sends a notification that a report is ready to", "E-mail message", InteractionStyle.Asynchronous);

            SoftwareSystem centralMonitoringService = model.AddSoftwareSystem("Central Monitoring Service", "The bank's central monitoring and alerting dashboard.");

            financialRiskSystem.Uses(centralMonitoringService, "Sends critical failure alerts to", "SNMP", InteractionStyle.Asynchronous).AddTags(AlertTag);

            SoftwareSystem activeDirectory = model.AddSoftwareSystem("Active Directory", "The bank's authentication and authorisation system.");

            financialRiskSystem.Uses(activeDirectory, "Uses for user authentication and authorisation");

            ViewSet           views       = workspace.Views;
            SystemContextView contextView = views.CreateSystemContextView(financialRiskSystem, "Context", "An example System Context diagram for the Financial Risk System architecture kata.");

            contextView.AddAllSoftwareSystems();
            contextView.AddAllPeople();

            Styles styles = views.Configuration.Styles;

            financialRiskSystem.AddTags("Risk System");

            styles.Add(new ElementStyle(Tags.Element)
            {
                Color = "#ffffff", FontSize = 34
            });
            styles.Add(new ElementStyle("Risk System")
            {
                Background = "#550000", Color = "#ffffff"
            });
            styles.Add(new ElementStyle(Tags.SoftwareSystem)
            {
                Width = 650, Height = 400, Background = "#801515", Shape = Shape.RoundedBox
            });
            styles.Add(new ElementStyle(Tags.Person)
            {
                Width = 550, Background = "#d46a6a", Shape = Shape.Person
            });

            styles.Add(new RelationshipStyle(Tags.Relationship)
            {
                Thickness = 4, Dashed = false, FontSize = 32, Width = 400
            });
            styles.Add(new RelationshipStyle(Tags.Synchronous)
            {
                Dashed = false
            });
            styles.Add(new RelationshipStyle(Tags.Asynchronous)
            {
                Dashed = true
            });
            styles.Add(new RelationshipStyle(AlertTag)
            {
                Color = "#ff0000"
            });

            styles.Add(new ElementStyle("Future State")
            {
                Opacity = 30, Border = Border.Dashed
            });
            styles.Add(new RelationshipStyle("Future State")
            {
                Opacity = 30, Dashed = true
            });

            StructurizrDocumentationTemplate template = new StructurizrDocumentationTemplate(workspace);
            DirectoryInfo documentationRoot           = new DirectoryInfo("FinancialRiskSystem");

            template.AddContextSection(financialRiskSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "context.adoc")));
            template.AddFunctionalOverviewSection(financialRiskSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "functional-overview.md")));
            template.AddQualityAttributesSection(financialRiskSystem, new FileInfo(Path.Combine(documentationRoot.FullName, "quality-attributes.md")));
            template.AddImages(documentationRoot);

            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, workspace);
        }
Ejemplo n.º 29
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");

            ComponentFinder componentFinder = new ComponentFinder(
                webApplication,
                typeof(ContosoUniversity.MvcApplication).Namespace, // doing this typeof forces the ContosoUniversity assembly to be loaded
                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")
                    )
                //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.Code)
                {
                    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("20e54135-adff-4bdf-b684-ff6c3ffc478f", "1c714777-3b06-4e2a-9eb4-35a3648b1592");

            structurizrClient.MergeWorkspace(32431, workspace);
        }
Ejemplo n.º 30
0
        static void Main()
        {
            StructurizrClient structurizrClient = new StructurizrClient(ApiKey, ApiSecret);

            structurizrClient.PutWorkspace(WorkspaceId, Create());
        }