コード例 #1
0
    public static async Task Main(string[] args)
    {
        var options   = Common.ParseCommandLine(args);
        var transitId = options.TransitIds.Length > 0
            ? options.TransitIds[0]
            : Common.AskTransitId();

        Console.WriteLine($"Project ID: {options.ProjectId}");
        Console.WriteLine($"Project API key: {options.ProjectApiKey}");
        Console.WriteLine($"Transit ID: {transitId}");

        // Create a client and set to authenticate using the API key
        var client = Common.CreateClient(options);

        // Get the transit first, so that we can compare fill rate before and after the update.
        // Also, while the update API supports patching (sending partial data), we must send
        // all cables rather than only new ones.
        var documentBefore = await client.GetTransitLayoutAsync(options.ProjectId, transitId);

        // Take existing cables, then add 4 new ones
        var cables    = documentBefore.Data.Attributes.Cables;
        var newCables = cables.Concat(GenerateAdditionalCables(cables, 4));

        // Build a document with transit update data.
        // Attributes only need to contain top-level properties to update, in this case Cables.
        var createDocument = new SingleTransitLayoutCreateUpdateDocument
        {
            Data = new TransitLayoutCreateUpdateResource
            {
                Id         = transitId.ToString(), // needed for update
                Type       = Common.TransitLayoutsType,
                Attributes = new Attributes
                {
                    Cables = newCables.ToArray()
                },
                Relationships = new Relationships
                {
                    Project = Common.CreateProjectRelationship(options.ProjectId)
                }
            }
        };

        var resultDocument = await client.UpdateTransitLayoutAsync(options.ProjectId, transitId,
                                                                   createDocument);

        Console.WriteLine("");
        Console.WriteLine("The transit was successfully updated!");
        Console.WriteLine($"Fill rate before : {fillRatePct(documentBefore)}");
        Console.WriteLine($"Fill rate after  : {fillRatePct(resultDocument)}");
コード例 #2
0
    public static async Task Main(string[] args)
    {
        var options = Common.ParseCommandLine(args);

        Console.WriteLine("Please enter a transit name:");
        var transitName = Console.ReadLine();

        Console.WriteLine($"Project ID: {options.ProjectId}");
        Console.WriteLine($"Project API key: {options.ProjectApiKey}");
        Console.WriteLine($"Transit name: {transitName}");

        // Create a client and set to authenticate using the API key
        var client = Common.CreateClient(options);

        // Build a document with settings for the new transit
        var createDocument = new SingleTransitLayoutCreateUpdateDocument
        {
            Data = new TransitLayoutCreateUpdateResource
            {
                Type       = Common.TransitLayoutsType,
                Attributes = new Attributes
                {
                    Name   = transitName,
                    Cables = new[]
                    {
                        new Cable {
                            Diameter = 20, Id = "a"
                        },
                        new Cable {
                            Diameter = 20, Id = "b"
                        },
                        new Cable {
                            Diameter = 20, Id = "c"
                        },
                        new Cable {
                            Diameter = 20, Id = "d"
                        }
                    },
                    Frame = new Frame
                    {
                        PartNumber = "S006000000121" // S 6x1 AISI316
                    },
                    Drawing = new Drawing
                    {
                        Revision = "A"
                    },
                    Modules = new ModuleSpecification
                    {
                        EmcSystem = new EmcSystem
                        {
                            Center = true,
                            Type   = "PE"
                        }
                    }
                },
                Relationships = new Relationships
                {
                    Project = Common.CreateProjectRelationship(options.ProjectId)
                }
            }
        };

        // Send the transit create request to the Transit Designer server
        var resultDocument = await client.CreateTransitLayoutAsync(options.ProjectId, createDocument, default);

        Console.WriteLine("");
        Console.WriteLine($"The transit was successfully created! It has transit ID {resultDocument.Data.Id}");

        Console.WriteLine("");
        Console.WriteLine("The complete server response was:");
        Console.WriteLine(JsonConvert.SerializeObject(resultDocument, Formatting.Indented));
    }
コード例 #3
0
        static async Task Main(string[] args)
        {
            var browserWrapperExePath = FindBrowserWrapperExe();

            var options = Common.ParseCommandLine(args);

            var rand        = new Random().Next(1000, 100000);
            var transitName = $"Visit RTD test transit {rand}";

            Console.WriteLine($"Project ID: {options.ProjectId}");
            Console.WriteLine($"Project API key: {options.ProjectApiKey}");
            Console.WriteLine($"Transit name: {transitName}");

            // Create a client and set to authenticate using the API key
            var client = Common.CreateClient(options);

            // Create a transit with 6 cables with diameter 33 mm.
            // This should give 6 RM 60 modules by default (though it depends on project settings),
            // which with a S 6x1 frame works fine but gives no spare capacity.
            var cables = Enumerable
                         .Range(1, 6)
                         .Select(i => new Cable {
                Id = $"a-{i}", Diameter = 33
            })
                         .ToList();

            var createDocument = new SingleTransitLayoutCreateUpdateDocument
            {
                Data = new TransitLayoutCreateUpdateResource
                {
                    Type       = Common.TransitLayoutsType,
                    Attributes = new Attributes
                    {
                        Name   = transitName,
                        Cables = cables,
                        Frame  = new Frame
                        {
                            PartNumber = "S006000000121" // S 6x1 AISI316
                        }
                    },
                    Relationships = new Relationships
                    {
                        Project = Common.CreateProjectRelationship(options.ProjectId)
                    }
                }
            };

            Console.WriteLine("");
            Console.WriteLine("Creating transit ...");
            var transitBefore = await client.CreateTransitLayoutAsync(options.ProjectId, createDocument);

            var transitId = Guid.Parse(transitBefore.Data.Id);

            Console.WriteLine("");
            Console.WriteLine($"The transit is {completeness(transitBefore)} with a fill rate of {fillRatePct(transitBefore)}");

            // Extract the URL of the Transit Designer packing page for the transit.
            var packingPageUrl = transitBefore.Data.Relationships.PackingPage.Links.Related;

            // With the browser open, the user can modify the transit. For this sample, it is
            // recommended to change RM 60 to RM 40 for all cables and then let Transit Designer
            // autopack the result.
            Console.WriteLine("");
            Console.WriteLine($"Starting {browserWrapperExePath} with URL {packingPageUrl}, and waiting for it to exit ...");
            await StartBrowserWrapperAndWaitForExit(browserWrapperExePath, packingPageUrl);

            Console.WriteLine("");
            Console.WriteLine("Fetching transit layout again...");
            var transitAfter = await client.GetTransitLayoutAsync(options.ProjectId, transitId);

            Console.WriteLine("");
            Console.WriteLine($"The transit is {completeness(transitAfter)} with a fill rate of {fillRatePct(transitAfter)}");

            Console.WriteLine("");
            Console.WriteLine("Exiting.");
コード例 #4
0
    public static async Task Main(string[] args)
    {
        var options = Common.ParseCommandLine(args);

        Console.WriteLine($"Project ID: {options.ProjectId}");
        Console.WriteLine($"Project API key: {options.ProjectApiKey}");

        // Create a client and set to authenticate using the API key
        var client = Common.CreateClient(options);

        // Build a document with settings for the new transit
        // There are 2 errors here:
        // 1. We have a duplicate cable ID (id-a).
        // 2. The frame part number is not valid.
        var createDocument = new SingleTransitLayoutCreateUpdateDocument
        {
            Data = new TransitLayoutCreateUpdateResource
            {
                Type       = Common.TransitLayoutsType,
                Attributes = new Attributes
                {
                    Name   = "TestError",
                    Cables = new[]
                    {
                        new Cable {
                            Id = "id-a", Diameter = 20
                        },
                        new Cable {
                            Id = "id-a", Diameter = 20
                        },
                    },
                    Frame = new Frame
                    {
                        PartNumber = "unknown"
                    }
                },
                Relationships = new Relationships
                {
                    Project = Common.CreateProjectRelationship(options.ProjectId)
                }
            }
        };

        try
        {
            // Send the transit create request to the Transit Designer server.
            // We expect it to fail.
            var resultDocument = await client.CreateTransitLayoutAsync(options.ProjectId, createDocument, default);

            Console.WriteLine($"Unexpected! The create request did not fail (resulting transit ID is {resultDocument.Data.Id}).");
            Environment.Exit(1);
        }
        catch (ApiException <ErrorList> ex)
        {
            Console.WriteLine("Errors");
            Console.WriteLine("------");
            foreach (var error in ex.Result.Errors)
            {
                Console.WriteLine($"* {error.Title}: {error.Detail}");
            }
        }
    }
コード例 #5
0
    public static async Task Main(string[] args)
    {
        var options = Common.ParseCommandLine(args);

        Console.WriteLine("Please enter a transit name:");
        var transitName = Console.ReadLine();

        Console.WriteLine($"Project ID: {options.ProjectId}");
        Console.WriteLine($"Project API key: {options.ProjectApiKey}");
        Console.WriteLine($"Transit name: {transitName}");

        // Create a client and set to authenticate using the API key
        var client = Common.CreateClient(options);

        // Build a document with settings for the new transit
        var createDocument = new SingleTransitLayoutCreateUpdateDocument
        {
            Data = new TransitLayoutCreateUpdateResource
            {
                Type       = Common.TransitLayoutsType,
                Attributes = new Attributes
                {
                    Name  = transitName,
                    Frame = new Frame
                    {
                        PartNumber = S6X2Aisi316PartNumber
                    },
                    Drawing = new Drawing
                    {
                        Revision = "A"
                    },

                    // The cables have two different categories. With Levelout pack algorithm,
                    // they will be packed in the same frame opening. With LeveloutByCategory,
                    // they will be packed in different openings.
                    Cables = new[]
                    {
                        new Cable {
                            Diameter = 20, Id = "a", Category = "CatA"
                        },
                        new Cable {
                            Diameter = 20, Id = "b", Category = "CatA"
                        },
                        new Cable {
                            Diameter = 20, Id = "c", Category = "CatB"
                        },
                        new Cable {
                            Diameter = 20, Id = "d", Category = "CatB"
                        }
                    },

                    PackingParameters = new PackingParameters
                    {
                        Algorithm = LeveloutPackAlgorithm
                    }
                },
                Relationships = new Relationships
                {
                    Project = Common.CreateProjectRelationship(options.ProjectId)
                }
            }
        };

        // Send the transit create request to the Transit Designer server
        var resultDocument = await client.CreateTransitLayoutAsync(options.ProjectId, createDocument, default);

        Console.WriteLine("");
        Console.WriteLine($"The transit was successfully created! It has transit ID {resultDocument.Data.Id}");

        Console.WriteLine("");
        Console.WriteLine("The complete server response was:");
        Console.WriteLine(JsonConvert.SerializeObject(resultDocument, Formatting.Indented));
    }