public static SADIRegistry Instance() { if (instance == null) { instance = new SADIRegistry("http://biordf.net/sparql", "http://sadiframework.org/registry/"); } return(instance); }
private void FindServicesWorker_DoWork(object sender, DoWorkEventArgs e) { List <String> types = new List <String>(); foreach (IResource node in SelectedNodes) { if (node is IEntity) { if (!KE.HasType(node)) { Uri uri = (node as IEntity).Uri; if (!ReportProgressIfNotCancelled(0, String.Format("Resolving {0}...", uri))) { return; } try { SADIHelper.debug("ServiceSelection", "resolving URI", node); if (FindServicesWorker.CancellationPending) { return; } KE.Import(SemWebHelper.resolveURI(uri)); } catch (Exception err) { SADIHelper.error("ServiceSelection", "error resolving URI", node, err); } try { SADIHelper.debug("ServiceSelection", "resolving against SADI resolver", node); if (FindServicesWorker.CancellationPending) { return; } KE.Import(SADIHelper.resolve(uri)); } catch (Exception err) { SADIHelper.error("ServiceSelection", "error resolving against SADI resolver", node, err); } } foreach (IEntity type in KE.GetTypes(node as IEntity)) { types.Add(type.Uri.ToString()); } } } // find services by exact input class; quick, but misses a lot... if (!ReportProgressIfNotCancelled(0, "Finding services by direct type...")) { return; } ICollection <SADIService> services = SADIRegistry.Instance().findServicesByInputClass(types); int i = 0; int n = services.Count; foreach (SADIService service in services) { SADIRegistry.Instance().addPropertyRestrictions(service); if (!ReportProgressIfNotCancelled((++i * 100) / n, service)) { return; } } // reset progress bar if (!ReportProgressIfNotCancelled(0, "Finding services by input instance query...")) { return; } // find service by input instance SPARQL query; slow, but is complete modulo reasoning... i = 0; n = SADIRegistry.Instance().getServiceCount(); do { if (!ReportProgressIfNotCancelled((i * 100) / n, String.Format("Finding services by input instance query {0}-{1}/{2}", i, Math.Min(i + SERVICES_PER_QUERY, n), n))) { return; } services = SADIRegistry.Instance().getAllServices(i, SERVICES_PER_QUERY); foreach (SADIService service in services) { //SADIHelper.debug("ServiceDiscoveryDialog", String.Format("checking {0}", service.uri), null); Object rv = null; try { if (checkForInputInstances(service, SelectedNodes)) { SADIRegistry.Instance().addPropertyRestrictions(service); rv = service; } else { rv = String.Format("No match to {0}", service.uri); } } catch (Exception ex) { //rv = ex; rv = String.Format("Error executing input instance query for {0}: {1}", service.uri, ex.Message); } if (!ReportProgressIfNotCancelled((++i * 100) / n, rv)) { return; } } } while (services.Count == SERVICES_PER_QUERY); }