Beispiel #1
0
 internal static void trace(String prefix, String message, Object arg)
 {
     Trace.WriteLine(message, prefix);
     if (arg != null)
     {
         Trace.Indent();
         if (arg is string)
         {
             Trace.WriteLine(arg);
         }
         else if (arg is Store)
         {
             Trace.WriteLine(SemWebHelper.storeToString(arg as Store));
         }
         else if (arg is IEnumerable)
         {
             foreach (Object o in arg as IEnumerable)
             {
                 Trace.WriteLine(o.ToString());
             }
         }
         else if (arg != null)
         {
             Trace.WriteLine(arg.ToString());
         }
         Trace.Unindent();
     }
     Trace.Flush();
 }
        private void InvokeServicesWorker_DoWork(object threadContext)
        {
            ServiceCallStatus call    = threadContext as ServiceCallStatus;
            SADIService       service = call.Data as SADIService;

            try
            {
                call.Status = "Assembling input";
                MasterWorker.ReportProgress(1, call);
                MemoryStore input = assembleInput(SelectedNodes, service);

                call.Status = "Calling service";
                call.Data   = "Assembled input:\r\n" + SemWebHelper.storeToString(input);
                MasterWorker.ReportProgress(33, call);
                Store output = service.invokeService(input);

                call.Status = "Storing output";
                call.Data   = "Received output:\r\n" + SemWebHelper.storeToString(output);
                MasterWorker.ReportProgress(66, call);
                ICollection <IStatement> statements = KE.Import(output);
                showNewStatements(statements);

                call.Status = "Done";
                call.Data   = service;
                MasterWorker.ReportProgress(100, call);
            }
            catch (Exception err)
            {
                SADIHelper.error("ServiceCall", "error calling service", service, err);
                call.Status = "Error";
                call.Data   = "Error:\r\n" + err.Message;
                MasterWorker.ReportProgress(100, call);
            }
            finally
            {
                Interlocked.Decrement(ref NumWorkers);
            }
        }
Beispiel #3
0
        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);
        }