IEnumerator <ITask> OnConnectHandler(OnConnect onConnect)
        {
            if (onConnect.DriveControl == _driveControl)
            {
                UriBuilder builder = new UriBuilder(onConnect.Service);
                builder.Scheme = new Uri(ServiceInfo.Service).Scheme;

                ds.DirectoryPort port = ServiceForwarder <ds.DirectoryPort>(builder.Uri);
                ds.Get           get  = new ds.Get();

                port.Post(get);
                ServiceInfoType[] list = null;

                yield return(Arbiter.Choice(get.ResponsePort,
                                            delegate(ds.GetResponseType response)
                {
                    list = response.RecordList;
                },
                                            delegate(Fault fault)
                {
                    list = new ServiceInfoType[0];
                    LogError(fault);
                }
                                            ));

                WinFormsServicePort.FormInvoke(
                    delegate()
                {
                    _driveControl.ReplaceDirectoryList(list);
                }
                    );
            }
        }
Example #2
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) { }
                                            )
                             );
        }
Example #3
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;
        }
Example #4
0
        private IEnumerator <ITask> OnStartup()
        {
            #region CODECLIP 02-3
            PartnerType      remote    = FindPartner("Remote");
            ds.DirectoryPort remoteDir = DirectoryPort;

            if (remote != null && !string.IsNullOrEmpty(remote.Service))
            {
                remoteDir = ServiceForwarder <ds.DirectoryPort>(remote.Service);
            }
            #endregion

            #region CODECLIP 02-4
            cs.ConstructorPort remoteConstructor = ConstructorPort;
            ds.Query           query             = new ds.Query(
                new ds.QueryRequestType(
                    new ServiceInfoType(cs.Contract.Identifier)
                    )
                );

            remoteDir.Post(query);
            yield return((Choice)query.ResponsePort);

            ds.QueryResponseType queryRsp = query.ResponsePort;
            if (queryRsp != null)
            {
                remoteConstructor = ServiceForwarder <cs.ConstructorPort>(queryRsp.RecordList[0].Service);
            }
            #endregion

            #region CODECLIP 02-5
            string    clockService = null;
            cs.Create create       = new cs.Create(new ServiceInfoType(rst4.Contract.Identifier));
            remoteConstructor.Post(create);
            yield return((Choice)create.ResponsePort);

            CreateResponse createRsp = create.ResponsePort;
            if (createRsp != null)
            {
                clockService = createRsp.Service;
            }
            else
            {
                LogError((Fault)create.ResponsePort);
                yield break;
            }

            _clockPort = ServiceForwarder <rst4.ServiceTutorial4Operations>(clockService);
            #endregion

            rst4.Get get;
            yield return(_clockPort.Get(GetRequestType.Instance, out get));

            rst4.ServiceTutorial4State state = get.ResponsePort;

            if (state != null)
            {
                ServiceTutorial7State initState = new ServiceTutorial7State();

                PartnerType partner = FindPartner("Local");
                if (partner != null)
                {
                    initState.Clocks.Add(partner.Service);
                }
                initState.Clocks.Add(clockService);

                Replace replace = new Replace();
                replace.Body = initState;

                _mainPort.Post(replace);
            }
            else
            {
                LogError("Unable to Get state from ServiceTutorial4", (Fault)get.ResponsePort);
                yield break;
            }

            rst4.Subscribe subscribe;
            yield return(_clockPort.Subscribe(_clockNotify, out subscribe));

            if ((Fault)subscribe.ResponsePort != null)
            {
                LogError("Unable to subscribe to remote ServiceTutorial4", (Fault)subscribe.ResponsePort);
            }

            yield return(_localClockPort.Subscribe(_localClockNotify, out subscribe));

            if ((Fault)subscribe.ResponsePort != null)
            {
                LogError("Unable to subscribe to local ServiceTutorial4", (Fault)subscribe.ResponsePort);
            }
        }