Exemplo n.º 1
0
 public IEnumerator <ITask> SetByKeyHandler(SetByKey set)
 {
     try
     {
         if (set.Body.Keys.Count != set.Body.Values.Count)
         {
             throw new ArgumentException("Lengths of indices and values lists must match");
         }
         var indices = new List <int>(set.Body.Keys.Count);
         for (int i = 0; i < set.Body.Keys.Count; i++)
         {
             int index = _state.indexCache[set.Body.Keys[i]];
             _state.Values[index] = set.Body.Values[i];
             indices.Add(index);
         }
         SetCallback(new SetElementsRequestInfo()
         {
             RequestType = RequestType.ByKey,
             Indices     = indices,
             Keys        = set.Body.Keys,
             Timestamp   = set.Body.Timestamp,
             Values      = set.Body.Values
         });
         set.ResponsePort.Post(DefaultUpdateResponseType.Instance);
         SendNotification <SetByKey>(set);
     }
     catch (Exception e)
     {
         set.ResponsePort.Post(RSUtils.FaultOfException(e));
     }
     yield break;
 }
Exemplo n.º 2
0
 public IEnumerator <ITask> SetByIndexHandler(SetByIndex set)
 {
     try
     {
         if (set.Body.Indices.Count != set.Body.Values.Count)
         {
             throw new ArgumentException("Lengths of indices and values lists must match");
         }
         for (int i = 0; i < set.Body.Indices.Count; i++)
         {
             _state.Values[set.Body.Indices[i]] = set.Body.Values[i];
         }
         _state.Timestamp = set.Body.Timestamp;
         SetCallback(new SetElementsRequestInfo()
         {
             RequestType = RequestType.ByIndex,
             Indices     = set.Body.Indices,
             Keys        = new List <string>(
                 from i in set.Body.Indices
                 select(i < _state.Keys.Count ? _state.Keys[i] : "")),
             Timestamp = set.Body.Timestamp,
             Values    = set.Body.Values
         });
         set.ResponsePort.Post(DefaultUpdateResponseType.Instance);
         SendNotification <SetByIndex>(set);
     }
     catch (Exception e)
     {
         set.ResponsePort.Post(RSUtils.FaultOfException(e));
     }
     yield break;
 }
Exemplo n.º 3
0
        public IEnumerator <ITask> HttpGetHandler(HttpGet get)
        {
            VectorState response = _state;

            try
            {
                GetCallback(new GetAllRequestInfo());
                get.ResponsePort.Post(new HttpResponseType(_state));
            }
            catch (Exception e)
            {
                get.ResponsePort.Post(RSUtils.FaultOfException(e));
            }
            yield break;
        }
Exemplo n.º 4
0
        public IEnumerator <ITask> QueryFrameHandler(webcam.QueryFrame req)
        {
            yield return(Arbiter.Choice(_scribblerPort.GetImage(req.Body.Format),
                                        delegate(brick.ImageResponse r)
            {
                try
                {
                    var resp = new webcam.QueryFrameResponse()
                    {
                        Format = req.Body.Format,
                        Size = new System.Drawing.Size(r.Width, r.Height),
                        TimeStamp = r.Timestamp,
                    };
                    if (req.Body.Format.Equals(MyroImageType.Color.Guid))
                    {
                        resp.Frame = convertColorToRGB(r.Data, r.Width, r.Height);
                    }
                    else if (req.Body.Format.Equals(MyroImageType.Gray.Guid))
                    {
                        resp.Frame = r.Data;
                    }
                    else if (req.Body.Format.Equals(MyroImageType.JpegColor.Guid) ||
                             req.Body.Format.Equals(MyroImageType.JpegColorFast.Guid))
                    {
                        resp.Frame = r.Data;
                    }
                    else if (req.Body.Format.Equals(MyroImageType.JpegGray.Guid) ||
                             req.Body.Format.Equals(MyroImageType.JpegGrayFast.Guid))
                    {
                        resp.Frame = r.Data;
                    }
                    else
                    {
                        throw new Exception("FlukeCam does not know how to convert this image type");
                    }

                    req.ResponsePort.Post(resp);
                }
                catch (Exception e)
                {
                    req.ResponsePort.Post(RSUtils.FaultOfException(e));
                }
            },
                                        delegate(Fault f)
            {
                req.ResponsePort.Post(f);
            }));
        }
Exemplo n.º 5
0
 public IEnumerator <ITask> ReplaceHandler(Replace replace)
 {
     _state = replace.Body;
     try
     {
         SetCallback(new SetAllRequestInfo()
         {
             Timestamp = replace.Body.Timestamp,
             Values    = replace.Body.Values
         });
         replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
         SendNotification <Replace>(replace);
     }
     catch (Exception e)
     {
         replace.ResponsePort.Post(RSUtils.FaultOfException(e));
     }
     yield break;
 }
Exemplo n.º 6
0
        private DsspResponsePort <vector.CallbackResponseType> playTone()
        {
            var responsePort = new DsspResponsePort <vector.CallbackResponseType>();

            brick.PlayToneBody play = new brick.PlayToneBody()
            {
                Frequency1 = (int)Math.Round(_state.Values[0]),
                Frequency2 = (int)Math.Round(_state.Values[1]),
                Duration   = (int)Math.Round(_state.Values[2])
            };
            if (play.Frequency1 < 0 || play.Frequency2 < 0 || play.Duration < 0)
            {
                responsePort.Post(RSUtils.FaultOfException(new ArgumentOutOfRangeException()));
            }
            else
            {
                Activate(Arbiter.Choice(_scribblerPort.PlayTone(play),
                                        delegate(DefaultUpdateResponseType success) { responsePort.Post(vector.CallbackResponseType.Instance); },
                                        delegate(Fault failure) { responsePort.Post(failure); }));
            }
            return(responsePort);
        }
Exemplo n.º 7
0
 public IEnumerator <ITask> GetByKeyHandler(GetByKey get)
 {
     try
     {
         GetElementResponseType response = new GetElementResponseType()
         {
             Value     = _state.Get(get.Body.Key),
             Timestamp = _state.Timestamp
         };
         GetCallback(new GetElementRequestInfo()
         {
             RequestType = RequestType.ByKey,
             Index       = _state.indexCache[get.Body.Key],
             Key         = get.Body.Key
         });
         get.ResponsePort.Post(response);
     }
     catch (Exception e)
     {
         get.ResponsePort.Post(RSUtils.FaultOfException(e));
     }
     yield break;
 }
Exemplo n.º 8
0
 public IEnumerator <ITask> GetByIndexHandler(GetByIndex get)
 {
     try
     {
         GetElementResponseType response = new GetElementResponseType()
         {
             Value     = _state.Get(get.Body.Index),
             Timestamp = _state.Timestamp
         };
         GetCallback(new GetElementRequestInfo()
         {
             RequestType = RequestType.ByIndex,
             Index       = get.Body.Index,
             Key         = ((_state.Keys.Count >= (get.Body.Index + 1)) ? _state.Keys[get.Body.Index] : "")
         });
         get.ResponsePort.Post(response);
     }
     catch (Exception e)
     {
         get.ResponsePort.Post(RSUtils.FaultOfException(e));
     }
     yield break;
 }