Exemplo n.º 1
0
        public virtual IEnumerator <ITask> QueryFilesHandler(QueryFiles queryFiles)
        {
            ResponseFiles response = new ResponseFiles();

            response.Files = new List <LegoFile>();
            bool done   = false;
            int  handle = 0;

            nxtcmd.LegoCommand cmd = new nxtcmd.LegoFindFirst(queryFiles.Body.Filespec);
            yield return(Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                                        delegate(nxtcmd.LegoResponse ok)
            {
                nxtcmd.LegoResponseFindFirst ffResponse = nxtcmd.LegoResponse.Upcast <nxtcmd.LegoResponseFindFirst>(ok);
                if (ffResponse.Success)
                {
                    response.Files.Add(new LegoFile(ffResponse.FileName, (int)ffResponse.FileSize));
                    handle = ffResponse.Handle;
                }
                else
                {
                    done = true;
                }
            },
                                        delegate(Fault fault)
            {
                done = true;
            }));

            while (!done)
            {
                cmd = new nxtcmd.LegoFindNext(handle);
                yield return(Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                                            delegate(nxtcmd.LegoResponse ok)
                {
                    nxtcmd.LegoResponseFindNext fnResponse = nxtcmd.LegoResponse.Upcast <nxtcmd.LegoResponseFindNext>(ok);
                    if (fnResponse.Success)
                    {
                        response.Files.Add(new LegoFile(fnResponse.FileName, (int)fnResponse.FileSize));
                        handle = fnResponse.Handle;
                    }
                    else
                    {
                        done = true;
                    }
                },
                                            delegate(Fault fault)
                {
                    done = true;
                }));
            }

            _state.ResponseFiles = response;
            queryFiles.ResponsePort.Post(response);
            yield break;
        }
        public virtual IEnumerator<ITask> QueryFilesHandler(QueryFiles queryFiles)
        {
            ResponseFiles response = new ResponseFiles();
            response.Files = new List<LegoFile>();
            bool done = false;
            int handle = 0;

            nxtcmd.LegoCommand cmd = new nxtcmd.LegoFindFirst(queryFiles.Body.Filespec);
            yield return Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                delegate(nxtcmd.LegoResponse ok)
                {
                    nxtcmd.LegoResponseFindFirst ffResponse = nxtcmd.LegoResponse.Upcast<nxtcmd.LegoResponseFindFirst>(ok);
                    if (ffResponse.Success)
                    {
                        response.Files.Add(new LegoFile(ffResponse.FileName, (int)ffResponse.FileSize));
                        handle = ffResponse.Handle;
                    }
                    else
                        done = true;
                },
                delegate(Fault fault)
                {
                    done = true;
                });

            while (!done)
            {
                cmd = new nxtcmd.LegoFindNext(handle);
                yield return Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd),
                    delegate(nxtcmd.LegoResponse ok)
                    {
                        nxtcmd.LegoResponseFindNext fnResponse = nxtcmd.LegoResponse.Upcast<nxtcmd.LegoResponseFindNext>(ok);
                        if (fnResponse.Success)
                        {
                            response.Files.Add(new LegoFile(fnResponse.FileName, (int)fnResponse.FileSize));
                            handle = fnResponse.Handle;
                        }
                        else
                            done = true;
                    },
                    delegate(Fault fault)
                    {
                        done = true;
                    });
            }

            _state.ResponseFiles = response;
            queryFiles.ResponsePort.Post(response);
            yield break;
        }