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");
            }
        }
        public static void Main(string[] args)
        {
            if (4 != args.Length || "'".Equals(args[3]) || !args[3].StartsWith("'") || !args[3].EndsWith("'"))
            {
                Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpbasicauthstring> <realm> '<simplesearchexpression>'");
            }
            else
            {
                string apiDomain           = args[0];
                string httpBasicAuthString = args[1];
                string realm = args[2];
                string rawSearchExpression = args[3].Trim('\'');

                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:process-query";
                        Link         orchestrationProcessQueryLink = orchestrationRootResource.DiscoverLink(registeredLinkRelOrchestrationProcessQuery);
                        if (null != orchestrationProcessQueryLink)
                        {
                            UriTemplate orchestrationProcessQueryUriTemplate = new UriTemplate(orchestrationProcessQueryLink.Href);
                            orchestrationProcessQueryUriTemplate.SetParameter("offset", 0);
                            orchestrationProcessQueryUriTemplate.SetParameter("limit", 50);

                            string orchestrationProcessQueryUri = orchestrationProcessQueryUriTemplate.Resolve();

                            /// Create the process query:
                            string       queryExpression = $"<query version='1.0'><search><quick>{rawSearchExpression}</quick></search></query>";
                            JObject      query           = new JObject(new JProperty("query", queryExpression));
                            ProcessQuery result          = registryClient.SendHal <ProcessQuery>(HttpMethod.Post, new Uri(orchestrationProcessQueryUri), query);

                            int assetNo = 0;
                            int pageNo  = 0;
                            /// Page through the result:
                            StringBuilder sb = new StringBuilder();
                            do
                            {
                                sb.AppendLine($"Page#: {++pageNo}, search expression: '{rawSearchExpression}'");
                                foreach (Process processInstance in result.ResourceList)
                                {
                                    string id   = processInstance.Base.Id;
                                    string name = processInstance.Common.Name;

                                    sb.AppendLine($"ProcessItem#: {++assetNo}, id: {id}, name: '{name}'");
                                }

                                // If we have more results, follow the next link and get the next page:
                                result = registryClient.GetHalResource <ProcessQuery>(result.GetUri("next", Enumerable.Empty <EmbedResource>()));
                            }while (result != null);
                            Console.WriteLine(sb);
                        }
                        else
                        {
                            Console.WriteLine("ProcessQuery not supported.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Orchestration not supported.");
                    }
                }
                Console.WriteLine("End");
            }
        }