public static T FindInRegistry <T>(CtmsRegistryClient registryClient, string serviceType, string realm, string resourceName) where T : Representation { T searchesResource = default(T); if (registryClient.GetRegistryInfo().Resources.ContainsKey(resourceName)) { var candidateSystemIds = registryClient.GetRegistryInfo().Resources[resourceName] .SelectMany(it => it.Systems) .Select(it => it.SystemId); string effectiveRealm = realm; if (!candidateSystemIds.Contains(realm)) { effectiveRealm = candidateSystemIds.FirstOrDefault(); Console.WriteLine($"'{resourceName}' was not available on realm {realm}. Falling back to {effectiveRealm}."); } searchesResource = (null != effectiveRealm) ? registryClient.GetResourceForSystem <T>(resourceName, GetSystemType(serviceType), effectiveRealm) : default(T); } return(searchesResource); }
/// <summary> /// This example enumerates the entries in the service registry and writes the results to stdout using the registry. /// </summary> static void Main(string[] args) { if (2 != args.Length) { Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpbasicauthstring>"); } else { string apiDomain = args[0]; string httpBasicAuthString = args[1]; Uri upstreamServerUrl = new Uri($"https://{apiDomain}"); // openId connect: using (IPlatformConnection connection = new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString)) // client_credentials with extension This method creates a session for the given login name supporting "client credentials" login. //using (IPlatformConnection connection = new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString, username)) // Using credentials with platform extension: //using (IPlatformConnection connection = new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString, username, password)) // Using credentials with OAuth2 refresh_token: //using (IPlatformConnection connection = new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString, username, password, RefreshType.OAuth2)) using (CtmsRegistryClient registryClient = new CtmsRegistryClient(connection)) { CtmsRegistryInfo registryInfo = registryClient.GetRegistryInfo(); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, CtmsResourceInfo[]> resourceInfo in registryInfo.Resources) { sb.AppendLine($"Resource name: '{resourceInfo.Key}'"); int index = 0; foreach (CtmsResourceInfo resourceInfoSpecificSystem in resourceInfo.Value) { ++index; sb.AppendLine($"\t {index}. <{resourceInfoSpecificSystem.Href}>") .AppendLine($"\t\t Description: {resourceInfoSpecificSystem.Description}"); if (null != resourceInfoSpecificSystem.Properties) { sb.AppendLine($"\t\t Properties:"); foreach (var item in resourceInfoSpecificSystem.Properties) { sb.AppendLine($"\t\tName: {item.Key}, Value: {item.Value}"); } } if (null != resourceInfoSpecificSystem.TemplateParameters) { sb.AppendLine($"\t\t TemplateParameters:"); foreach (var item in resourceInfoSpecificSystem.TemplateParameters) { sb.AppendLine($"\t\t\tName: {item.Key}, Type: {item.Value?.Type}, Description: {item.Value?.Description}"); } } } } Console.WriteLine(sb); Console.WriteLine("End"); } } }
public static void Main(string[] args) { int serviceVersion; if (5 != args.Length || !int.TryParse(args[3], out serviceVersion)) { Console.WriteLine($"Usage: {System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name} <apidomain> <httpbasicauthstring> <servicetype> <serviceversion> <realm>"); } else { string apiDomain = args[0]; string httpBasicAuthString = args[1]; string serviceType = args[2]; string realm = args[4]; Uri upstreamServerUrl = new Uri($"https://{apiDomain}"); using (CtmsRegistryClient registryClient = new CtmsRegistryClient(new OAuth2AuthorizationConnection(upstreamServerUrl, httpBasicAuthString))) { IList <HierarchicalItem> results = new List <HierarchicalItem>(); Stopwatch watch = new Stopwatch(); watch.Start(); /// Get the root folder: // !! // The MAM Connectivity Toolkit Connector does always embed all items of a folder. // !! Item rootItem = PlatformTools.PlatformToolsSDK.FindInRegistry <Item>(registryClient, serviceType, realm, "loc:root-item"); /// Traverse the folder tree and collect the results in the passed list: Traverse(registryClient, rootItem, results, 0); StringBuilder sb = new StringBuilder(); foreach (HierarchicalItem item in results) { string text = $"{new string('\t', item.Item2)}{(item.Item1.DiscoverLinks("loc:collection").Any() ? "- (collection) " : string.Empty)}depth: {item.Item2} {item.Item1.Common.Name}"; sb.AppendLine(text); } Console.WriteLine(sb); watch.Stop(); Console.WriteLine($"elapsed: {watch.ElapsedMilliseconds}"); } Console.WriteLine("End"); } }
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 (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"); } }
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"); } }