/// <summary>
        /// Creates an instance of the service associated with this contract
        /// </summary>
        /// <param name="contructorServicePort">Contractor Service that will create the instance</param>
        /// <param name="partners">Optional list of service partners for new service instance</param>
        /// <returns>Result PortSet for retrieving service creation response</returns>
        public static DsspResponsePort<CreateResponse> CreateService(constructor.ConstructorPort contructorServicePort, params PartnerType[] partners)
        {
            DsspResponsePort<CreateResponse> result = new DsspResponsePort<CreateResponse>();
            ServiceInfoType si = new ServiceInfoType(Contract.Identifier, null);
            if (partners != null)
            {
                si.PartnerList = new List<PartnerType>(partners);
            }
            Microsoft.Dss.Services.Constructor.Create create =
                new Microsoft.Dss.Services.Constructor.Create(si, result);
            contructorServicePort.Post(create);
            return result;

        }
Пример #2
0
        IEnumerator <ITask> OnStartServiceHandler(OnStartService onStartService)
        {
            if (onStartService.DriveControl == _driveControl &&
                onStartService.Constructor != null)
            {
                cs.ConstructorPort port = ServiceForwarder <cs.ConstructorPort>(onStartService.Constructor);

                ServiceInfoType request = new ServiceInfoType(onStartService.Contract);
                cs.Create       create  = new cs.Create(request);

                port.Post(create);

                string service = null;

                yield return(Arbiter.Choice(
                                 create.ResponsePort,
                                 delegate(CreateResponse response)
                {
                    service = response.Service;
                },
                                 delegate(Fault fault)
                {
                    LogError(fault);
                }
                                 ));


                if (service == null)
                {
                    yield break;
                }

                WinFormsServicePort.FormInvoke(
                    delegate()
                {
                    _driveControl.StartedSickLRF();
                }
                    );
            }
        }
Пример #3
0
        public void HttpPostHandler(HttpPost httpPost)
        {
            HttpPostRequestData formData = httpPost.GetHeader <HttpPostRequestData>();

            try
            {
                DsspOperation operation = formData.TranslatedOperation;

                if (operation is DriveDistance)
                {
                    _mainPort.Post((DriveDistance)operation);
                }
                else if (operation is SetDrivePower)
                {
                    _mainPort.Post((SetDrivePower)operation);
                }
                else if (operation is RotateDegrees)
                {
                    _mainPort.Post((RotateDegrees)operation);
                }
                else if (operation is EnableDrive)
                {
                    _mainPort.Post((EnableDrive)operation);
                }
                else if (operation is AllStop)
                {
                    _mainPort.Post((AllStop)operation);
                }
                else if (operation is ResetEncoders)
                {
                    _mainPort.Post((ResetEncoders)operation);
                }
                else
                {
                    NameValueCollection parameters = formData.Parameters;

                    if (parameters["StartDashboard"] != null)
                    {
                        string          Dashboardcontract = "http://schemas.microsoft.com/robotics/2006/01/simpledashboard.user.html";
                        ServiceInfoType info   = new ServiceInfoType(Dashboardcontract);
                        cons.Create     create = new cons.Create(info);
                        create.TimeSpan = DsspOperation.DefaultShortTimeSpan;

                        ConstructorPort.Post(create);
                        Activate(Arbiter.Choice(
                                     create.ResponsePort,
                                     delegate(CreateResponse createResponse) { },
                                     delegate(Fault f) { LogError(f); }
                                     ));
                    }
                    else if (parameters["DrivePower"] != null)
                    {
                        double power = double.Parse(parameters["Power"]);
                        SetDrivePowerRequest drivepower = new SetDrivePowerRequest();
                        drivepower.LeftWheelPower  = power;
                        drivepower.RightWheelPower = power;
                        _mainPort.Post(new SetDrivePower(drivepower));
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                HttpPostSuccess(httpPost);
            }
            catch
            {
                HttpPostFailure(httpPost);
            }
        }
Пример #4
0
        public void HttpPostHandler(HttpPost httpPost)
        {
            HttpPostRequestData formData = httpPost.GetHeader<HttpPostRequestData>();

            try
            {
                DsspOperation operation = formData.TranslatedOperation;

                if (operation is DriveDistance)
                {
                    _mainPort.Post((DriveDistance)operation);
                }
                else if (operation is SetDrivePower)
                {
                    _mainPort.Post((SetDrivePower)operation);
                }
                else if (operation is RotateDegrees)
                {
                    _mainPort.Post((RotateDegrees)operation);
                }
                else if (operation is EnableDrive)
                {
                    _mainPort.Post((EnableDrive)operation);
                }
                else if (operation is AllStop)
                {
                    _mainPort.Post((AllStop)operation);
                }
                else
                {
                    NameValueCollection parameters = formData.Parameters;

                    if (parameters["StartDashboard"] != null)
                    {
                        string Dashboardcontract = "http://schemas.microsoft.com/robotics/2006/01/simpledashboard.html";
                        ServiceInfoType info = new ServiceInfoType(Dashboardcontract);
                        cons.Create create = new cons.Create(info);
                        create.TimeSpan = DsspOperation.DefaultShortTimeSpan;

                        ConstructorPort.Post(create);
                        Arbiter.Choice(
                            create.ResponsePort,
                            delegate(CreateResponse createResponse) { },
                            delegate(Fault f) { LogError(f); }
                        );
                    }
                    else if (parameters["DrivePower"] != null)
                    {
                        double power = double.Parse(parameters["Power"]);
                        SetDrivePowerRequest drivepower = new SetDrivePowerRequest();
                        drivepower.LeftWheelPower = power;
                        drivepower.RightWheelPower = power;
                        _mainPort.Post(new SetDrivePower(drivepower));
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                HttpPostSuccess(httpPost);
            }
            catch
            {
                HttpPostFailure(httpPost);
            }
        }
Пример #5
0
        IEnumerator<ITask> OnStartServiceHandler(OnStartService onStartService)
        {
            if (onStartService.DriveControl == _driveControl &&
                onStartService.Constructor != null)
            {
                cs.ConstructorPort port = ServiceForwarder<cs.ConstructorPort>(onStartService.Constructor);

                ServiceInfoType request = new ServiceInfoType(onStartService.Contract);
                cs.Create create = new cs.Create(request);

                port.Post(create);

                string service = null;

                yield return Arbiter.Choice(
                    create.ResponsePort,
                    delegate(CreateResponse response)
                    {
                        service = response.Service;
                    },
                    delegate(Fault fault)
                    {
                        LogError(fault);
                    }
                );


                if (service == null)
                {
                    yield break;
                }

                WinFormsServicePort.FormInvoke(
                    delegate()
                    {
                        _driveControl.StartedSickLRF();
                    }
                );
            }
        }
        /// <summary>
        /// Creates an instance of the LEGO NXT Communications service.
        /// </summary>
        /// <returns>Result PortSet for retrieving service creation response</returns>
        private DsspResponsePort<CreateResponse> CreateNxtCommunicationService()
        {
            DsspResponsePort<CreateResponse> createResponsePort = new DsspResponsePort<CreateResponse>();
            ServiceInfoType si = new ServiceInfoType(comm.Contract.Identifier, null);

            Microsoft.Dss.Services.Constructor.Create create =
                new Microsoft.Dss.Services.Constructor.Create(si, createResponsePort);

            base.ConstructorPort.Post(create);

            return createResponsePort;
        }
Пример #7
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);
            }
        }