/// <summary> /// This method searches for a primary or alternate contract of the /// service that is present in the contracts list. Requires a /// taskQueue to activate tasks on. Throws NoContractFoundException /// in a Fault if one cannot be found. /// </summary> /// <param name="taskQueue"></param> /// <param name="service"></param> /// <param name="contracts"></param> /// <returns></returns> public static PortSet <ServiceInfoType, Fault> FindCompatibleContract(DispatcherQueue taskQueue, Uri service, List <string> contracts) { PortSet <ServiceInfoType, Fault> returnPort = new PortSet <ServiceInfoType, Fault>(); PortSet <LookupResponse, Fault> responsePort = new PortSet <LookupResponse, Fault>(); //Console.WriteLine("RSUtils: Querying " + service); DssEnvironment.ServiceForwarderUnknownType(service).PostUnknownType( new DsspDefaultLookup() { Body = new LookupRequestType(), ResponsePort = responsePort }); Arbiter.Activate(taskQueue, Arbiter.Choice <LookupResponse, Fault>( responsePort, delegate(LookupResponse resp) { try { //Console.WriteLine("RSUtils: Got response"); returnPort.Post(FindCompatibleContract(resp, contracts)); } catch (NoContractFoundException e) { returnPort.Post(FaultOfException(e)); } }, delegate(Fault failure) { returnPort.Post(failure); })); return(returnPort); }
private T tryCreateAdapter() { lock (this) { try { // Query the service initially PortSet <LookupResponse, Fault> responsePort = new PortSet <LookupResponse, Fault>(); DssEnvironment.ServiceForwarderUnknownType(new Uri("dssp.tcp://localhost/" + Name)).PostUnknownType( new DsspDefaultLookup() { Body = new LookupRequestType(), ResponsePort = responsePort }); ServiceInfoType responseRecord = RSUtils.ReceiveSync(responsePort, Myro.Utilities.Params.DefaultRecieveTimeout); // Try to find a working contract for each adapter foreach (var factory in adapterFactories) { try { ServiceInfoType serviceRecord = RSUtils.FindCompatibleContract(responseRecord, factory.SupportedContracts); T ret = (T)factory.Create(serviceRecord); Console.WriteLine("Attached to " + serviceRecord.Service + " as \"" + Name + "\""); return(ret); } catch (NoContractFoundException) { } } // If we haven't returned already in the loop, we didn't find // an adapter that works. throw new NoAdapterFoundException(responseRecord); } catch (NoAdapterFoundException) { throw; } catch (Exception e) { DssEnvironment.LogError("Error querying or attaching to " + "dssp.tcp://localhost/" + Name + ": " + e.ToString()); throw; } } }