public void Can_generate_a_fully_qualified_path()
        {
            string expected = _baseUrl + "foo/1";
            const string routeName = "foo.show";
            const string routeTemplate = "foo/{id}";

            string template = TestHelper.CreateATemplateGenerator(_baseUrl, routeName, routeTemplate)
                .Generate(routeName);
            var uriTemplate = new UriTemplate(template);
            uriTemplate.AddParameter("id", 1);

            string actual = uriTemplate.Resolve();
            Assert.Equal(expected, actual);
        }
        public void Can_generate_two_optional_path_items_template()
        {
            string expected = _baseUrl + "foo/2";
            const string routeName = "foo.one.two";
            const string routeTemplate = "foo/{one}/{two}";

            string template = TestHelper.CreateATemplateGenerator(_baseUrl, routeName, routeTemplate,
                routeDefaults: new { one = RouteParameter.Optional, two = RouteParameter.Optional })
                .Generate(routeName, new { two = 2 });
            var uriTemplate = new UriTemplate(template);

            uriTemplate.AddParameter("two", "2");

            string actual = uriTemplate.Resolve();
            Assert.Equal(expected, actual);
        }
        public void Can_generate_a_path_with_anonymous_complex_route_properties()
        {
            string expected = _baseUrl + "foo/1?bar.abc=abc&bar.def=def";
            const string routeName = "foo.show";
            const string routeTemplate = "foo/{id}";

            string template = TestHelper.CreateATemplateGenerator(_baseUrl, routeName, routeTemplate)
                .Generate(routeName, new { Id = 1, Bar = new { Abc = "abc", Def = "def" } });
            var uriTemplate = new UriTemplate(template);

            uriTemplate.AddParameters(new { id = 1 });
            uriTemplate.AddParameter("bar.abc", "abc");
            uriTemplate.AddParameter("bar.def", "def");

            string actual = uriTemplate.Resolve();
            Assert.Equal(expected, actual);
        }
        public ResourceOptions BuildInstance()
        {
            var metadata = _metadataProvider.BuildInstance();
            var resources = metadata.Resources;
            var supportedParameters = new Dictionary<string, object>{ {"hash", metadata.Hash} };

            var browserAgentScriptTemplate = new UriTemplate(resources.GetValueOrDefault("agent", string.Empty), true);
            var httpMessageTemplate = new UriTemplate(resources.GetValueOrDefault("message-ingress", string.Empty), true);
            var hudScriptTemplate = new UriTemplate(resources.GetValueOrDefault("hud", string.Empty), true);
            var contextTemplate = new UriTemplate(resources.GetValueOrDefault("context", string.Empty), true);
            var metadataTemplate = new UriTemplate(resources.GetValueOrDefault("metadata", string.Empty), true);
            var clientScriptTemplate = new UriTemplate(resources.GetValueOrDefault("client", string.Empty), true);

            return new ResourceOptions
            {
                BrowserAgentScriptTemplate = browserAgentScriptTemplate.ResolveWith(supportedParameters),
                MessageIngressTemplate = httpMessageTemplate.ResolveWith(supportedParameters),
                HudScriptTemplate = hudScriptTemplate.ResolveWith(supportedParameters),
                ContextTemplate = contextTemplate.ResolveWith(supportedParameters),
                MetadataTemplate = metadataTemplate.ResolveWith(supportedParameters),
                ClientScriptTemplate = clientScriptTemplate.ResolveWith(supportedParameters)
            };
        }
        public static UriTemplate AddParameter(this UriTemplate template, string name, object value)
        {
            template.SetParameter(name, value);

            return(template);
        }
 public void Add(string key, UriTemplate template)
 {
     _Templates.Add(key, template);
 }
        public static void Main(string[] args)
        {
            if (3 != args.Length)
            {
                Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpbasicauthstring> <realm>");
            }
            else
            {
                string apiDomain           = args[0];
                string httpBasicAuthString = args[1];
                string realm = args[2];

                Uri upstreamServerUrl = new Uri($"https://{apiDomain}");
                using (CtmsRegistryClient registryClient = new CtmsRegistryClient(new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString)))
                {
                    const string      registeredLinkRelOrchestrationRoot = "orchestration:orchestration";
                    const string      orchestrationServiceType           = "avid.orchestration.ctc";
                    OrchestrationRoot orchestrationRootResource          = PlatformTools.PlatformToolsSDK.FindInRegistry <OrchestrationRoot>(registryClient, orchestrationServiceType, realm, registeredLinkRelOrchestrationRoot);

                    if (null != orchestrationRootResource)
                    {
                        const string registeredLinkRelOrchestrationProcessQuery = "orchestration:start-process";
                        Link         orchestrationProcessQueryLink = orchestrationRootResource.DiscoverLink(registeredLinkRelOrchestrationProcessQuery);
                        if (null != orchestrationProcessQueryLink)
                        {
                            Tavis.UriTemplates.UriTemplate orchestrationProcessQueryUriTemplate = new Tavis.UriTemplates.UriTemplate(orchestrationProcessQueryLink.Href);
                            orchestrationProcessQueryUriTemplate.SetParameter("offset", 0);
                            orchestrationProcessQueryUriTemplate.SetParameter("limit", 50);

                            string orchestrationProcessQueryUri = orchestrationProcessQueryUriTemplate.Resolve();

                            /// Create and start an export process with attachments:
                            string       now            = DateTime.Now.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK");
                            const string itemToExport   = "2016050410152760101291561460050569B02260000003692B00000D0D000005";
                            string       newProcessName = $"New process as to {DateTime.Now}".Replace(" ", "_").Replace(":", "_").Replace("-", "_");
                            string       newProcessId   = Guid.NewGuid().ToString();
                            JObject      processDescription
                                = new JObject(
                                      new JProperty("base",
                                                    new JObject(
                                                        new JProperty("id", newProcessId)
                                                        , new JProperty("type", "MAM_EXPORT_FILE")
                                                        , new JProperty("systemType", "interplay-mam")
                                                        , new JProperty("systemID", realm)
                                                        )
                                                    )
                                      , new JProperty("common",
                                                      new JObject(
                                                          new JProperty("name", newProcessName)
                                                          , new JProperty("creator", ".NET_Example")
                                                          , new JProperty("created", now)
                                                          , new JProperty("modifier", "Service-WorkflowEngine")
                                                          , new JProperty("modified", now)
                                                          )
                                                      )
                                      , new JProperty("attachments",
                                                      new JArray(
                                                          new JObject(
                                                              new JProperty("base",
                                                                            new JObject(
                                                                                new JProperty("id", itemToExport)
                                                                                , new JProperty("type", "Asset")
                                                                                , new JProperty("systemType", "interplay-mam")
                                                                                , new JProperty("systemID", realm)
                                                                                )
                                                                            )
                                                              )
                                                          )
                                                      )
                                      );

                            Process process = registryClient.SendHal <Process>(HttpMethod.Post, new Uri(orchestrationProcessQueryUri), processDescription);
                            Console.WriteLine($"Process: '{newProcessName}' - start initiated");
                            Console.WriteLine($"Lifecycle: {process.LifeCycle}");
                            /// Monitor the running process:
                            while ("running".Equals(process.LifeCycle) || "pending".Equals(process.LifeCycle))
                            {
                                Thread.Sleep(500);
                                // Directly get the process instance via its id:
                                const string registeredLinkRelOrchestrationGetProcess = "orchestration:process-by-id";
                                Link         orchestrationGetProcessLink = orchestrationRootResource.DiscoverLink(registeredLinkRelOrchestrationGetProcess);
                                Tavis.UriTemplates.UriTemplate orchestrationGetProcessUriTemplate = new Tavis.UriTemplates.UriTemplate(orchestrationGetProcessLink.Href);
                                orchestrationGetProcessUriTemplate.SetParameter("id", newProcessId);
                                process = registryClient.GetHalResource <Process>(new Uri(orchestrationGetProcessUriTemplate.Resolve()));
                                Console.WriteLine($"Lifecycle: {process.LifeCycle}");
                            }
                        }
                    }
                }
                Console.WriteLine("End");
            }
        }