public static void Main(string[] args) { if (5 != args.Length) { Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpbasicauthstring> <servicetype> <realm> <advancedsearchdescriptionfilename>"); } else { string apiDomain = args[0]; string httpBasicAuthString = args[1]; string serviceType = args[2]; string realm = args[3]; string advancedSearchDescriptionFileName = args[4]; if (File.Exists(advancedSearchDescriptionFileName)) { Uri upstreamServerUrl = new Uri($"https://{apiDomain}"); using (CtmsRegistryClient registryClient = new CtmsRegistryClient(new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString))) { const string registeredLinkRelSearches = "search:searches"; Searches searchesResource = PlatformTools.PlatformToolsSDK.FindInRegistry <Searches>(registryClient, serviceType, realm, registeredLinkRelSearches); if (null != searchesResource) { const string registeredLinkRelAdvancedSearch = "search:advanced-search"; Link advancedSearchLink = searchesResource.DiscoverLink(registeredLinkRelAdvancedSearch); /// Check, whether simple search is supported: if (null != advancedSearchLink) { UriTemplate advancedSearchUriTemplate = new UriTemplate(advancedSearchLink.Href); advancedSearchUriTemplate.SetParameter("offset", 0); advancedSearchUriTemplate.SetParameter("limit", 50); string advancedSearchUri = advancedSearchUriTemplate.Resolve(); string advancedSearchDescription = File.ReadAllText(advancedSearchDescriptionFileName); /// Doing the search and write the results to stdout: // The search description must be passed as content type "application/json": using (HttpContent content = new StringContent(advancedSearchDescription, Encoding.UTF8, "application/json")) { using (HttpResponseMessage response = registryClient.HttpClient.PostAsync(advancedSearchUri, content).Result) { AdvancedSearch searchResult = response.Content.ReadAsAsyncHal <AdvancedSearch>().Result; int assetNo = 0; int pageNo = 0; // Page through the result: StringBuilder sb = new StringBuilder(); sb.AppendLine(DateTime.Now.ToString()); do { if (searchResult.AssetList.Any()) { sb.AppendLine($"Page#: {++pageNo}, search description from file '{advancedSearchDescriptionFileName}'"); foreach (Asset asset in searchResult.AssetList) { BaseInfo baseInfo = asset.Base; CommonAttributes commonAttributes = asset.Common; sb.AppendLine($"Asset#: {++assetNo}, id: {asset.Base.Id}, name: '{asset.Common.Name}'"); } } // If we have more results, follow the next link and get the next page: searchResult = registryClient.GetHalResource <SimpleSearch>(searchResult.GetUri("next", Enumerable.Empty <EmbedResource>())); }while (searchResult != null); Console.WriteLine(sb); } } } else { Console.WriteLine("Advanced search not supported."); } } else { Console.WriteLine("Advanced search not supported."); } 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"); } }
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 (5 != args.Length || "'".Equals(args[4]) || !args[4].StartsWith("'") || !args[4].EndsWith("'")) { Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpBasicAuthString> <servicetype> <realm> '<simplesearchexpression>'"); } else { string apiDomain = args[0]; string httpBasicAuthString = args[1]; string serviceType = args[2]; string realm = args[3]; string rawSearchExpression = args[4].Trim('\''); Uri upstreamServerUrl = new Uri($"https://{apiDomain}"); using (CtmsRegistryClient registryClient = new CtmsRegistryClient(new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString))) { const string registeredLinkRelSearches = "search:searches"; Searches searchesResource = PlatformTools.PlatformToolsSDK.FindInRegistry <Searches>(registryClient, serviceType, realm, registeredLinkRelSearches); if (null != searchesResource) { const string registeredLinkRelSimpleSearch = "search:simple-search"; Link simpleSearchLink = searchesResource.DiscoverLink(registeredLinkRelSimpleSearch); /// Check, whether simple search is supported: if (null != simpleSearchLink) { UriTemplate simpleSearchUrlTemplate = new UriTemplate(simpleSearchLink.Href); simpleSearchUrlTemplate.SetParameter("search", rawSearchExpression); Uri simpleSearchResultPageUrl = new Uri(simpleSearchUrlTemplate.Resolve()); /// Doing the search and write the results to stdout: SimpleSearch searchResult = registryClient.GetHalResource <SimpleSearch>(simpleSearchResultPageUrl); int assetNo = 0; int pageNo = 0; // Page through the result: StringBuilder sb = new StringBuilder(); do { if (searchResult.AssetList.Any()) { sb.AppendLine($"Page#: {++pageNo}, search expression: '{rawSearchExpression}'"); foreach (Asset asset in searchResult.AssetList) { BaseInfo baseInfo = asset.Base; CommonAttributes commonAttributes = asset.Common; sb.AppendLine($"Asset#: {++assetNo}, id: {asset.Base.Id}, name: '{asset.Common.Name}'"); } } // If we have more results, follow the next link and get the next page: searchResult = registryClient.GetHalResource <SimpleSearch>(searchResult.GetUri("next", Enumerable.Empty <EmbedResource>())); }while (searchResult != null); Console.WriteLine(sb); } } } Console.WriteLine("End"); } }