Esempio n. 1
0
 public static void Init(string manifestFile, int httpPort, int dsspPort)
 {
     if (bank == null)
     {
         Robot.httpPort = httpPort;
         Robot.dsspPort = dsspPort;
         FileAttributes att = File.GetAttributes(manifestFile);
         if ((att & (FileAttributes.Device | FileAttributes.Directory | FileAttributes.Offline)) != 0)
         {
             throw new IOException("Manifest file is not a normal file");
         }
         Console.Write("Starting DSS environment...");
         DssEnvironment.Initialize(httpPort, dsspPort, "file://" + manifestFile);
         Console.WriteLine("Done");
         bank = new AdapterBank(new List <IAdapterFactory>()
         {
             new Myro.Adapters.DriveAdapterFactory(),
             new Myro.Adapters.VectorAdapterFactory(),
             new Myro.Adapters.WebcamAdapterFactory(),
             new Myro.Adapters.CamControlAdapterFactory()
         });
         driveAdapter      = bank.GetAdapterSpec <DriveAdapter>("drive");
         soundAdapter      = bank.GetAdapterSpec <VectorAdapter>("tonegen");
         webcamAdapter     = bank.GetAdapterSpec <WebcamAdapter>("webcam");
         camcontrolAdapter = bank.GetAdapterSpec <CamControlAdapter>("camcontrol");
     }
     else
     {
         throw new Exception("Myro is already initialized");
     }
 }
Esempio n. 2
0
        private void ConductorSvr_Load(object sender, EventArgs e)
        {
            if (IsPortInUse(ProtocolType.Tcp, 50000) || IsPortInUse(ProtocolType.Tcp, 50001))
            {
                System.Windows.Forms.MessageBox.Show("Tcp port 50000 or 50001 is in use, please check it.", "URWPGSim2D Server");
                System.Diagnostics.Process.GetCurrentProcess().Kill(); // 没有数据需要保存直接结束当前进程
            }

            // 调试时在同一节点上启动Server服务和Client服务
            string[] strArrManifestFileNames = new string[2] {
                Application.StartupPath + "\\Sim2DSvr.manifest.xml",
                Application.StartupPath + "\\Sim2DClt.manifest.xml",
            };
            //DssEnvironment.Initialize(50000, 50001, strArrManifestFileNames);

            // 在50000/50001这组端口上启动一个DSS Node并初始化Server服务实例
            string strServerManifestFileName = Application.StartupPath + "\\Sim2DSvr.manifest.xml";

            DssEnvironment.Initialize(50000, 50001, strServerManifestFileName);

            // 等待当前Dss Node上的某Dss Service发生Drop事件执行DssEnvironment.Shutdown命令
            DssEnvironment.WaitForShutdown();

            // 退出客户端启动引导程序界面不再显示
            Application.Exit();
        }
Esempio n. 3
0
 public VectorAdapter(ServiceInfoType serviceRecord)
 {
     ServiceInfo = serviceRecord;
     opPort      = DssEnvironment.ServiceForwarder <vector.VectorOperations>(new Uri(serviceRecord.Service));
     //if (opPort == null)
     //    throw new AdapterCreationException("Service forwarder port was null");
 }
Esempio n. 4
0
        /// <summary>
        /// Overrides RobotBrain Bind function to implement addition LEDAdapter functions.
        /// </summary>
        protected override void Bind()
        {
            base.Bind();

            //Bind to scribbler specific sensors

            //Specialized LED array
            directory.Query dquery = new directory.Query(new directory.QueryRequestType(
                                                             new Microsoft.Dss.ServiceModel.Dssp.ServiceInfoType("http://www.roboteducation.org/scribblerledarray.html")));
            //Uri direcURI = DssEnvironment.FindService(directory.Contract.Identifier);
            //TODO: remove the line below once the above line works
            Uri direcURI = new Uri("http://localhost:" + httpPort + "/directory");

            directory.DirectoryPort dport = DssEnvironment.ServiceForwarder <directory.DirectoryPort>(direcURI);
            dport.Post(dquery);

            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Choice(dquery.ResponsePort,
                                            delegate(directory.QueryResponseType success)
            {
                sledadapter = new ScribblerLEDArrayAdapter(success.RecordList[0].Service);
            },
                                            delegate(Fault fault) { }
                                            )
                             );
        }
Esempio n. 5
0
        private void startServices()
        {
            // Build a list of the "StartService"s and the "Adapter" services
            List <ServiceInfoType> allServices = new List <ServiceInfoType>(services);

            foreach (var adapter in adapterNames.Values)
            {
                if (adapter.ServiceConfig.Contract != null)
                {
                    allServices.Add(adapter.ServiceConfig);
                }
            }

            // Start them all
            foreach (var service in allServices)
            {
                if (service.Contract != null)
                {
                    Arbiter.Activate(DssEnvironment.TaskQueue,
                                     Arbiter.Choice <CreateResponse, Fault>(
                                         DssEnvironment.CreateService(service),
                                         delegate(CreateResponse success)
                    {
                        Console.WriteLine("* Created * " + success.Service);
                    },
                                         delegate(Fault failure)
                    {
                        Console.WriteLine("*** FAULT *** creating " + service.Service + ": " + failure.Reason);
                    }));
                }
            }
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
 public static void shutdown()
 {
     if (bank != null)
     {
         bank.Dispose();
         DssEnvironment.Shutdown();
         DssEnvironment.WaitForShutdown();
     }
 }
Esempio n. 8
0
        protected virtual void Initialize()
        {
            // Initialize the port and subscribe to the service to know when the motors are enabled
            motorsOn  = false;
            drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(new Uri(ServiceInfo.Service));
            drive.DriveOperations driveNotificationPort = new drive.DriveOperations();
            RSUtils.ReceiveSync(taskQueue, drivePort.Subscribe(driveNotificationPort), Params.DefaultRecieveTimeout);

            // Set up notifications
            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate));
        }
Esempio n. 9
0
        private void Initialize()
        {
            // Initialize Dss using the Scribbler base manifest
            DssEnvironment.Initialize(50000, 50001,
                                      @"C:\\Microsoft Robotics Studio (1.5)\\samples\\IPRE\\Scribbler\\Scribbler\\Batch Files\\IPRE.Scribbler.standard.manifest.xml"
                                      );

            Arbiter.Receive <DateTime>(true, _timerPort, ConnectToScribbler);
            _timerPort.Post(DateTime.Now);

            autolock.WaitOne();
        }
Esempio n. 10
0
        protected virtual void Initialize()
        {
            // Initialize the port and subscribe to the service
            motorsOn  = false;
            drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(new Uri(ServiceInfo.Service));
            drive.DriveOperations driveNotificationPort = new drive.DriveOperations();
            drivePort.Subscribe(driveNotificationPort);

            // Set up notifications
            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate));
        }
Esempio n. 11
0
        public Robot(string manifestFile)
        {
            Console.Write("Starting DSS environment...");
            DssEnvironment.Initialize(50000, 50001, "file://" + Path.GetFullPath(manifestFile));
            Console.WriteLine("Done");
            bank = new AdapterBank(new List <IAdapterFactory>()
            {
                new Myro.Adapters.DriveAdapterFactory(),
                new Myro.Adapters.VectorAdapterFactory()
            });

            Sensors  = new MyroSensors(bank);
            Movement = new MyroMovement(bank);
            Sound    = new MyroSound(bank);
        }
Esempio n. 12
0
        protected void updateAdapters()
        {
            var dirPort = DssEnvironment.ServiceForwarder <dirProxy.DirectoryPort>(new Uri("http://localhost:50000/directory"));

            //Console.WriteLine("Querying directory");
            //dirProxy.QueryRequest request = new dirProxy.QueryRequest();
            //request.QueryRecord = new ServiceInfoType();
            Arbiter.ExecuteToCompletion(DssEnvironment.TaskQueue,
                                        Arbiter.Choice <dirProxy.GetResponse, Fault>(
                                            dirPort.Get(),
                                            delegate(dirProxy.GetResponse success)
            {
                // See if each service matches a known one from the config file, if so, make an adapter
                //Console.WriteLine("Checking " + success.RecordList.Length + " services");
                foreach (var rec in success.RecordList)
                {
                    //Uri foundUri = new Uri(rec.Service);
                    AdapterSpec adapterSpec = null;
                    //Console.WriteLine("Checking " + rec.Service);
                    foreach (var adapter in adapterNames.Values)
                    {
                        //Console.WriteLine("Comparing " + rec.Service + " to " + adapter.ServiceInfo.Service);
                        //Uri testUri = new Uri(adapter.ServiceInfo.Service);
                        //if (Uri.Compare(foundUri, testUri, UriComponents.Path, UriFormat.UriEscaped, StringComparison.InvariantCultureIgnoreCase) == 0)
                        if (rec.Service.EndsWith(adapter.ServiceConfig.Service))
                        {
                            //Console.WriteLine("* Assigned * " + rec.Service + " to " + adapter.ServiceInfo.Service);
                            if (adapterSpec == null)
                            {
                                adapterSpec = adapter;
                            }
                            else
                            {
                                Console.WriteLine("WARNING: duplicate service: " + rec.Service + " (already had one for " + adapter.ServiceConfig.Service + ")");
                            }
                        }
                    }
                    if (adapterSpec != null)
                    {
                        AdapterFactory.CreateAdapterIfNeeded(adapterSpec, rec);
                    }
                }
            },
                                            delegate(Fault fault)
            {
                Console.WriteLine("AdapterBank: Fault querying directory: " + fault.Reason);
            }));
        }
Esempio n. 13
0
        private void ConductorClt_Load(object sender, EventArgs e)
        {
            DssRuntimeConfiguration dssConfig = new DssRuntimeConfiguration();

            dssConfig.PublicHttpPort = 0;
            dssConfig.PublicTcpPort  = 0;

            int port = 40000;

            do // 从TCP端口40000起查找尚未被占用的端口
            {
                while (IsPortInUse(ProtocolType.Tcp, port))
                {
                    port++;
                }
                if (dssConfig.PublicHttpPort == 0)
                {
                    dssConfig.PublicHttpPort = port;
                    port++;
                }
                else
                {
                    dssConfig.PublicTcpPort = port;
                }
            } while (dssConfig.PublicHttpPort == 0 || dssConfig.PublicTcpPort == 0);

            // 调试时在同一节点上启动Server服务和Client服务
            string[] strArrManifestFileNames = new string[2] {
                Application.StartupPath + "\\Sim2DSvr.manifest.xml",
                Application.StartupPath + "\\Sim2DClt.manifest.xml",
            };
            //DssEnvironment.Initialize(dssConfig, strArrManifestFileNames);

            // 在50000/50001这组端口上启动一个DSS Node并初始化Server服务实例
            string strServerManifestFileName = Application.StartupPath + "\\Sim2DSvr.manifest.xml";
            //DssEnvironment.Initialize(dssConfig, strServerManifestFileName);

            // 在40000/40001这组端口上启动一个DSS Node并初始化Client服务实例
            string strClientManifestFileName = Application.StartupPath + "\\Sim2DClt.manifest.xml";

            DssEnvironment.Initialize(dssConfig, strClientManifestFileName);

            // 等待当前Dss Node上的某Dss Service发生Drop事件执行DssEnvironment.Shutdown命令
            DssEnvironment.WaitForShutdown();

            // 退出客户端启动引导程序界面不再显示
            Application.Exit();
        }
Esempio n. 14
0
        /// <summary>
        /// This is an internal helper method that starts the DSS environment,
        /// using the manifest file specified in the MyroConfigFiles argument.
        /// </summary>
        /// <param name="config"></param>
        private static void startDSS(MyroConfigFiles config)
        {
            string manifestFile = Path.Combine(Path.Combine(Params.ConfigPath, config.BaseName + ".manifest"), config.BaseName + ".manifest.xml");

            Robot.httpPort = config.MyroConfiguration.HttpPort;
            Robot.dsspPort = config.MyroConfiguration.DsspPort;
            FileAttributes att = File.GetAttributes(manifestFile);

            if ((att & (FileAttributes.Device | FileAttributes.Directory | FileAttributes.Offline)) != 0)
            {
                throw new IOException("Manifest file is not a normal file");
            }
            Console.Write("Starting DSS environment...");
            DssEnvironment.Initialize(httpPort, dsspPort, "file://" + manifestFile);
            Console.WriteLine("Done");
        }
Esempio n. 15
0
        /// <summary>
        /// Intialization Routine. Called by constructor.
        /// </summary>
        protected virtual void Initialize()
        {
            XPathDocument  xpdoc = new XPathDocument(configFile);
            XPathNavigator xpnav = xpdoc.CreateNavigator();

            manifestFile = xpnav.SelectSingleNode("//ManifestFile/URI").Value;
            httpPort     = int.Parse(xpnav.SelectSingleNode("//DssEnvironment/HttpPort").Value);
            soapPort     = int.Parse(xpnav.SelectSingleNode("//DssEnvironment/SoapPort").Value);
            verbosity    = int.Parse(xpnav.SelectSingleNode("//Verbosity/Level").Value);

            // Initialize Dss manifest
            DssEnvironment.Initialize(httpPort, soapPort, manifestFile);

            // Wait for 30 seconds for the DssEnvironment to completely load all services
            // TODO: utilize config file to remove the sleep
            Thread.Sleep(10000);
        }
Esempio n. 16
0
        /// <summary>
        /// This is a helper mehtod that connects the Scribbler on the specified
        /// COM port.  It waits for the connection to complete, and re-throws any
        /// exceptions generated by the Scribbler service.
        /// </summary>
        /// <param name="comPort"></param>
        private static void connectWaitForScribbler(string comPort)
        {
            ManualResetEvent evt = new ManualResetEvent(false);

            waitForService(new ServiceInfoType(scribbler.Contract.Identifier),
                           delegate(ServiceInfoType info) { brickService = info; evt.Set(); });
            evt.WaitOne(Params.DefaultRecieveTimeout, false);
            if (brickService == null)
            {
                throw new MyroInitException("Could not find Scribbler service");
            }
            var             scribPort = DssEnvironment.ServiceForwarder <scribbler.ScribblerOperations>(new Uri(brickService.Service));
            DispatcherQueue queue     = new DispatcherQueue("init", new Dispatcher());

            try
            {
                if (comPort != null)
                {
                    int comNumber;
                    if (comPort.ToLower().StartsWith("com"))
                    {
                        comNumber = Int32.Parse(comPort.Substring(3));
                    }
                    else
                    {
                        throw new MyroInitException("COM port string must be of the format com2, com5, etc.");
                    }
                    RSUtils.ReceiveSync(queue, scribPort.Replace(new scribbler.ScribblerState()
                    {
                        ComPort = comNumber
                    }), Params.DefaultRecieveTimeout);
                }
                DssEnvironment.LogInfo("calling reconnect...");
                RSUtils.ReceiveSync(queue, scribPort.Reconnect(), Params.DefaultRecieveTimeout);
                DssEnvironment.LogInfo("reconnect returned");
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                queue.Dispose();
            }
        }
Esempio n. 17
0
        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;
                }
            }
        }
Esempio n. 18
0
        protected void subscribeDirectory()
        {
            var dirPort = DssEnvironment.ServiceForwarder <dirProxy.DirectoryPort>(new Uri("http://localhost:50000/directory"));
            var resPort = new dirProxy.DirectoryPort();

            Arbiter.ExecuteToCompletion(DssEnvironment.TaskQueue,
                                        Arbiter.Choice <SubscribeResponseType, Fault>(
                                            dirPort.Subscribe(resPort, null),
                                            delegate(SubscribeResponseType success)
            {
                Console.WriteLine("AdapterBank subscribed to directory service");
            },
                                            delegate(Fault failure)
            {
                throw new Exception("Could not subscribe to directory service: " + failure.Reason);
            }));
            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Receive <dirProxy.Insert>(true, resPort, directoryInsertHandler));
        }
Esempio n. 19
0
        void ConnectToScribbler(DateTime dt)
        {
            Uri driveUri = null;

            // Look for any active generic drive contract service running
            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Choice(DssEnvironment.DirectoryQuery(drive.Contract.Identifier),
                                            delegate(ServiceInfoType success)
            {
                driveUri = new Uri(success.Service);
                Console.WriteLine("================\n" + driveUri);

                // Initialize the port and subscribe to the service
                motorsOn  = false;
                drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(driveUri);
                drive.DriveOperations driveNotificationPort = new drive.DriveOperations();
                drivePort.Subscribe(driveNotificationPort);

                // Set up notifications
                Arbiter.Activate(DssEnvironment.TaskQueue,
                                 Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate)
                                 );

                autolock.Set();
            },
                                            delegate(W3C.Soap.Fault failure)
            {
                // Request failed. Sleep for 1 sec and look for 30 times.
                if (++attemptCount >= 30)
                {
                    DssEnvironment.LogError("Unable to find Drive Service, aborting - Press <Enter>");
                    Console.ReadLine();
                    DssEnvironment.Shutdown();
                }
                else
                {
                    // Post a timer message that expires in 30 seconds
                    TimeSpan timeout = new TimeSpan(0, 0, 30);
                    DssEnvironment.TaskQueue.EnqueueTimer(timeout, _timerPort);
                }
            }
                                            ));
        }
Esempio n. 20
0
        /// <summary>
        /// Intialization Routine. Called by constructor.
        /// </summary>
        protected virtual void Initialize()
        {
            XPathDocument  xpdoc = new XPathDocument(configFile);
            XPathNavigator xpnav = xpdoc.CreateNavigator();

            manifestFile = xpnav.SelectSingleNode("//ManifestFile/URI").Value;
            httpPort     = int.Parse(xpnav.SelectSingleNode("//DssEnvironment/HttpPort").Value);
            soapPort     = int.Parse(xpnav.SelectSingleNode("//DssEnvironment/SoapPort").Value);
            verbosity    = int.Parse(xpnav.SelectSingleNode("//Verbosity/Level").Value);

            // Initialize Dss manifest
            String manifestFileFull = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(configFile)), manifestFile);

            Console.WriteLine("Starting DSS environment with manifest: " + manifestFileFull);
            DssEnvironment.Initialize(httpPort, soapPort, manifestFileFull);
            //Console.WriteLine("Done");

            // Wait for 30 seconds for the DssEnvironment to completely load all services
            // TODO: utilize config file to remove the sleep
            Thread.Sleep(10000);
        }
Esempio n. 21
0
        /// <summary>
        /// Shut down the DSS node and MSRDS services.  This method waits
        /// for everything to shut down before returning.
        /// </summary>
        public static void Shutdown()
        {
            LastStateChange = RobotStateChange.SHUTDOWN;

            try
            {
                if (bank != null)
                {
                    bank.Dispose();
                }
            }
            catch (Exception) { }

            try
            {
                DssEnvironment.Shutdown();
                DssEnvironment.WaitForShutdown();
            }
            catch (Exception) { }

            LastStateChange = RobotStateChange.SHUTDOWN_COMPLETE;
        }
Esempio n. 22
0
 protected virtual void Initialize()
 {
     // Initialize the port
     sensorPort = DssEnvironment.ServiceForwarder <analogArray.AnalogSensorOperations>(new Uri(serviceUri));
     Console.WriteLine("Analog sensor array adapter: " + serviceUri);
 }
Esempio n. 23
0
 protected virtual void Initialize()
 {
     // Initialize the port and subscribe to the service
     ledPort = DssEnvironment.ServiceForwarder <ledarray.LedarrayOperations>(new Uri(serviceUri));
 }
Esempio n. 24
0
 protected virtual void Initialize()
 {
     // Initialize the port and subscribe to the service
     tonePort = DssEnvironment.ServiceForwarder <tonegen.ToneGeneratorOperations>(new Uri(serviceUri));
 }
Esempio n. 25
0
 public WebcamAdapter(ServiceInfoType serviceInfo)
 {
     ServiceInfo = serviceInfo;
     opPort      = DssEnvironment.ServiceForwarder <webcam.WebCamOperations>(new Uri(serviceInfo.Service));
 }
Esempio n. 26
0
 public void DropHandler(DsspDefaultDrop drop)
 {
     DssEnvironment.ControlPanelPort.Shutdown();
     DssEnvironment.Shutdown();
 }
Esempio n. 27
0
 protected virtual void Initialize()
 {
     // Initialize the port and subscribe to the service
     ttsPort = DssEnvironment.ServiceForwarder <tts.SpeechTextOperations>(new Uri(serviceUri));
 }
Esempio n. 28
0
        /// <summary>
        /// Searches service directory for a service with the specified contract. On success binds it to an Adapter object and inserts it in the
        /// adapters lookup dictionary.
        /// </summary>
        /// <param name="contract">The contract of the service</param>
        /// <returns>Nothing</returns>
        protected virtual IEnumerator <ITask> DirectorySearch(string contract)
        {
            directory.Query dquery = new directory.Query(new directory.QueryRequestType(
                                                             new Microsoft.Dss.ServiceModel.Dssp.ServiceInfoType(contract)));

            //Uri direcURI = DssEnvironment.FindService(directory.Contract.Identifier);
            //TODO: remove the line below once the above line works
            Uri direcURI = new Uri("http://localhost:" + httpPort + "/directory");

            directory.DirectoryPort dport = DssEnvironment.ServiceForwarder <directory.DirectoryPort>(direcURI);
            dport.Post(dquery);

            yield return(Arbiter.Choice(
                             dquery.ResponsePort,
                             delegate(directory.QueryResponseType success)
            {
                switch (contract)
                {
                case drive.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new DriveAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.DriveAdapter, list);
                        break;
                    }

                case analog.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new AnalogSensorAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.AnalogSensorAdapter, list);
                        break;
                    }

                case contact.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new ContactSensorArrayAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.ContactSensorArrayAdapter, list);
                        break;
                    }

                case analogArray.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new AnalogSensorArrayAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.AnalogSensorArrayAdapter, list);
                        break;
                    }

                case tonegen.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new ToneGeneratorAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.ToneGeneratorAdapter, list);
                        break;
                    }

                case ledarray.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new LEDArrayAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.LEDArrayAdapter, list);
                        break;
                    }

                case sonar.Contract.Identifier:
                    {
                        ArrayList list = new ArrayList();
                        for (int i = 0; i < success.RecordList.Length; i++)
                        {
                            if (verbosity >= 2)
                            {
                                Console.WriteLine(contract + ":" + success.RecordList[i].Service);
                            }
                            list.Add(new SonarAdapter(success.RecordList[i].Service));
                        }
                        AdaptersDictionary.Add(AdapterTypes.SonarAdapter, list);
                        break;
                    }
                }
            },
                             delegate(Fault fault) { }
                             ));

            yield break;
        }
Esempio n. 29
0
 protected virtual void Initialize()
 {
     // Initialize the port
     sensorPort = DssEnvironment.ServiceForwarder <sonar.SonarOperations>(new Uri(serviceUri));
 }
Esempio n. 30
0
 protected virtual void Initialize()
 {
     // Initialize the port
     sensorPort = DssEnvironment.ServiceForwarder <contact.ContactSensorArrayOperations>(new Uri(serviceUri));
 }