示例#1
0
        public virtual IEnumerator <ITask> QueryRunningLegoProgramHandler(QueryRunningProgram query)
        {
            RunningProgramResponse response = new RunningProgramResponse();

            nxtcmd.LegoGetCurrentProgramName cmd = new nxtcmd.LegoGetCurrentProgramName();
            yield return(Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                                        delegate(nxtcmd.LegoResponse ok)
            {
                nxtcmd.LegoResponseGetCurrentProgramName queryResponse = nxtcmd.LegoResponse.Upcast <nxtcmd.LegoResponseGetCurrentProgramName>(ok);
                if (queryResponse.Success)
                {
                    response.Program = queryResponse.FileName;
                    query.ResponsePort.Post(response);
                }
                else
                {
                    query.ResponsePort.Post(Fault.FromException(new System.IO.FileNotFoundException(queryResponse.ErrorCode.ToString())));
                }
            },
                                        delegate(Fault fault)
            {
                query.ResponsePort.Post(fault);
            }));

            yield break;
        }
        public virtual IEnumerator<ITask> QueryRunningLegoProgramHandler(QueryRunningProgram query)
        {
            RunningProgramResponse response = new RunningProgramResponse();

            nxtcmd.LegoGetCurrentProgramName cmd = new nxtcmd.LegoGetCurrentProgramName();
            yield return Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                delegate(nxtcmd.LegoResponse ok)
                {
                    nxtcmd.LegoResponseGetCurrentProgramName queryResponse = nxtcmd.LegoResponse.Upcast<nxtcmd.LegoResponseGetCurrentProgramName>(ok);
                    if (queryResponse.Success)
                    {
                        response.Program = queryResponse.FileName;
                        query.ResponsePort.Post(response);
                    }
                    else
                    {
                        query.ResponsePort.Post(Fault.FromException(new System.IO.FileNotFoundException(queryResponse.ErrorCode.ToString())));
                    }
                },
                delegate(Fault fault)
                {
                    query.ResponsePort.Post(fault);
                });

            yield break;
        }