Пример #1
0
        IEnumerator <ITask> HttpPostHandler(HttpPost post)
        {
            Fault fault = null;
            NameValueCollection collection = null;

            ReadFormData readForm = new ReadFormData(post.Body.Context);

            _utilitiesPort.Post(readForm);

            yield return(Arbiter.Choice(
                             readForm.ResultPort,
                             delegate(NameValueCollection col)
            {
                collection = col;
            },
                             delegate(Exception e)
            {
                fault = Fault.FromException(e);
                LogError(null, "Error processing form data", fault);
            }
                             ));

            if (fault != null)
            {
                post.ResponsePort.Post(fault);
                yield break;
            }

            if (!string.IsNullOrEmpty(collection["ChangeCamera"]))
            {
                string device = string.Empty;
                try
                {
                    device = collection["Camera"];
                }
                catch (Exception e)
                {
                    fault = Fault.FromException(e);
                    LogError(null, "Error reading form data", fault);
                }

                if (fault != null)
                {
                    post.ResponsePort.Post(fault);
                    yield break;
                }

                UpdateDeviceRequest request = new UpdateDeviceRequest();
                request.Selected.DevicePath = device;

                UpdateDevice update = new UpdateDevice();
                update.Body = request;

                UpdateDeviceInternal(update);

                yield return(Arbiter.Choice(
                                 update.ResponsePort,
                                 delegate(DefaultUpdateResponseType success) { },
                                 delegate(Fault f)
                {
                    fault = f;
                    LogError(null, "Unable to change camera", fault);
                }
                                 ));
            }
            else if (!string.IsNullOrEmpty(collection["ChangeFormat"]))
            {
                int    formatIndex = 0;
                Format format      = null;
                try
                {
                    formatIndex = int.Parse(collection["CaptureFormat"]);
                    format      = _state.Selected.SupportedFormats[formatIndex - 1];
                }
                catch (Exception e)
                {
                    fault = Fault.FromException(e);
                    LogError(null, "Error parsing form data", fault);
                }

                if (fault != null)
                {
                    post.ResponsePort.Post(fault);
                    yield break;
                }

                UpdateFormat update = new UpdateFormat();
                update.Body = format;

                UpdateFormatInternal(update);

                yield return(Arbiter.Choice(
                                 update.ResponsePort,
                                 delegate(DefaultUpdateResponseType success) { },
                                 delegate(Fault f)
                {
                    fault = f;
                    LogError(null, "Unable to change format", fault);
                }
                                 ));
            }

            if (fault != null)
            {
                post.ResponsePort.Post(fault);
                yield break;
            }

            post.ResponsePort.Post(new HttpResponseType(HttpStatusCode.OK, _state, _transform));
            yield break;
        }
Пример #2
0
        IEnumerator <ITask> GetInitialState(Srv1CameraState initialState)
        {
            Srv1CameraState state = new Srv1CameraState();

            state.CaptureFile = initialState.CaptureFile;
            state.Quality     = initialState.Quality;

            yield return(InitializeInternalService());

            foreach (object obj in new vision.CameraCollection())
            {
                using (vision.Camera camera = obj as vision.Camera)
                {
                    CameraInstance instance = new CameraInstance();
                    instance.FriendlyName     = camera.Name;
                    instance.DevicePath       = camera.Path;
                    instance.SupportedFormats = ConvertFormats(camera.Formats);

                    state.Cameras.Add(instance);
                }
            }

            state.Image = null;

            Replace replace = new Replace();

            replace.Body = state;
            _fwdPort.Post(replace);

            yield return(Arbiter.Choice(
                             replace.ResponsePort,
                             delegate(DefaultReplaceResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to set camera list", fault);
            }
                             ));

            UpdateDeviceRequest request = new UpdateDeviceRequest();

            if (initialState.Selected != null)
            {
                request.Selected = initialState.Selected;
            }
            else if (state.Cameras.Count > 0)
            {
                request.Selected = state.Cameras[0];
            }
            else
            {
                yield break;
            }
            UpdateDevice update = new UpdateDevice();

            update.Body = request;
            _fwdPort.Post(update);

            yield return(Arbiter.Choice(
                             update.ResponsePort,
                             delegate(DefaultUpdateResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to select camera", fault);
            }
                             ));

            if (initialState.Selected == null ||
                initialState.Selected.Format == null)
            {
                yield break;
            }

            UpdateFormat updateFormat = new UpdateFormat();

            updateFormat.Body = initialState.Selected.Format;

            _fwdPort.Post(updateFormat);

            yield return(Arbiter.Choice(
                             updateFormat.ResponsePort,
                             delegate(DefaultUpdateResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to select format", fault);
            }
                             ));
        }