public static ResourceShape LookupRequirementsInstanceShapes(string serviceProviderUrl, string oslcDomain, string oslcResourceType, OslcClient client, string requiredInstanceShape) { HttpResponseMessage response = client.GetResource(serviceProviderUrl, OSLCConstants.CT_RDF); ISet <MediaTypeFormatter> formatters = client.GetFormatters(); ServiceProvider serviceProvider = response.Content.ReadAsAsync <ServiceProvider>(formatters).Result; if (serviceProvider != null) { foreach (Service service in serviceProvider.GetServices()) { Uri domain = service.GetDomain(); if (domain != null && domain.ToString().Equals(oslcDomain)) { CreationFactory [] creationFactories = service.GetCreationFactories(); if (creationFactories != null && creationFactories.Length > 0) { foreach (CreationFactory creationFactory in creationFactories) { foreach (Uri resourceType in creationFactory.GetResourceTypes()) { if (resourceType.ToString() != null && resourceType.ToString().Equals(oslcResourceType)) { Uri[] instanceShapes = creationFactory.GetResourceShapes(); if (instanceShapes != null) { foreach (Uri typeURI in instanceShapes) { response = client.GetResource(typeURI.ToString(), OSLCConstants.CT_RDF); ResourceShape resourceShape = response.Content.ReadAsAsync <ResourceShape>(formatters).Result; string typeTitle = resourceShape.GetTitle(); if ((typeTitle != null) && (string.Compare(typeTitle, requiredInstanceShape, true) == 0)) { return(resourceShape); } } } } } } } } } } throw new ResourceNotFoundException(serviceProviderUrl, "InstanceShapes"); }
private static void ProcessCurrentPage(OslcQueryResult result, OslcClient client, bool asDotNetObjects) { foreach (String resultsUrl in result.GetMembersUrls()) { Console.WriteLine(resultsUrl); HttpResponseMessage response = null; try { //Get a single artifact by its URL response = client.GetResource(resultsUrl, OSLCConstants.CT_RDF); if (response != null) { //De-serialize it as a .NET object if (asDotNetObjects) { TestResult tr = response.Content.ReadAsAsync <TestResult>(client.GetFormatters()).Result; PrintTestResultInfo(tr); //print a few attributes } else { //Just print the raw RDF/XML (or process the XML as desired) ProcessRawResponse(response); } } } catch (Exception e) { logger.Error("Unable to process artifact at url: " + resultsUrl, e); } } }