Esempio n. 1
0
 protected override IEnumerator <ITask> GetCallback(Myro.Services.Generic.Vector.GetRequestInfo request, PortSet <Myro.Services.Generic.Vector.CallbackResponseType, Fault> responsePort)
 {
     if (request is vector.GetAllRequestInfo)
     {
         PortSet <DefaultQueryResponseType, Fault> responses = new PortSet <DefaultQueryResponseType, Fault>();
         for (int i = 0; i < _state.Values.Count; i++)
         {
             int myI = i;
             Activate(Arbiter.Choice(_scribblerPort.GetObstacle(i),
                                     delegate(brick.UInt16Body r)
             {
                 _state.Set(myI, RSUtils.NormalizeUShort(r.Value), DateTime.Now);
                 responses.Post(DefaultQueryResponseType.Instance);
             },
                                     delegate(Fault f) { responses.Post(f); }));
         }
         yield return(Arbiter.MultipleItemReceive(responses, _state.Values.Count,
                                                  delegate(ICollection <DefaultQueryResponseType> ss, ICollection <Fault> fs)
         {
             if (fs.Count == 0)
             {
                 responsePort.Post(vector.CallbackResponseType.Instance);
             }
             else
             {
                 var reasons = new List <ReasonText>();
                 foreach (var f in fs)
                 {
                     reasons.AddRange(f.Reason.AsEnumerable());
                 }
                 responsePort.Post(new Fault()
                 {
                     Detail = new Detail()
                     {
                         Any = fs.ToArray()
                     }, Reason = reasons.ToArray()
                 });
             }
         }));
     }
     else
     {
         var info = (vector.GetElementRequestInfo)request;
         yield return(Arbiter.Choice(_scribblerPort.GetObstacle(info.Index),
                                     delegate(brick.UInt16Body r)
         {
             _state.Set(info.Index, RSUtils.NormalizeUShort(r.Value), DateTime.Now);
             responsePort.Post(vector.CallbackResponseType.Instance);
         },
                                     delegate(Fault f) { responsePort.Post(f); }));
     }
     yield break;
 }