Exemplo n.º 1
0
        IEnumerator <ITask> DoStart()
        {
            try
            {
                _utilities = DsspHttpUtilitiesService.Create(Environment);

                RunForm runForm = new RunForm(CreateForm);

                WinFormsServicePort.Post(runForm);
                yield return(Arbiter.Choice(
                                 runForm.pResult,
                                 EmptyHandler,
                                 EmptyHandler
                                 ));

                FormInvoke invoke = new FormInvoke(
                    delegate
                {
                    _form.Initialize(_state);
                }
                    );

                WinFormsServicePort.Post(invoke);
                yield return(Arbiter.Choice(
                                 invoke.ResultPort,
                                 EmptyHandler,
                                 EmptyHandler
                                 ));
            }
            finally
            {
                FinishStarting();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle the Form Closed event for the Dashboard Form
        /// </summary>
        /// <param name="onClosed">The closed message</param>
        private void OnClosedHandler(OnClosed onClosed)
        {
            if (onClosed.DashboardForm == this.dashboardForm)
            {
                LogInfo("Form Closed");

                this.mainPort.Post(new DsspDefaultDrop(DropRequestType.Instance));
                ControlPanelPort.Post(new DsspDefaultDrop(DropRequestType.Instance));

                if (this.cameraForm != null)
                {
                    var closeWebcam = new FormInvoke(
                        delegate
                    {
                        this.cameraForm.Close();
                        this.cameraForm = null;
                    });

                    WinFormsServicePort.Post(closeWebcam);
                }

                if (this.depthCameraForm != null)
                {
                    var closeDepthcam = new FormInvoke(
                        delegate
                    {
                        this.depthCameraForm.Close();
                        this.depthCameraForm = null;
                    });

                    WinFormsServicePort.Post(closeDepthcam);
                }
            }
        }
Exemplo n.º 3
0
        public IEnumerator <ITask> OnUpdateButton(UpdateButton update)
        {
            int index = _state.Buttons.FindIndex(update.Body.CompareId);

            if (index < 0)
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "A button with the requested ID does not exist: " + update.Body.Id
                        )
                    );
            }
            else
            {
                bool isInternal = update.GetHeader <InternalUpdate>() != null;

                if (!isInternal)
                {
                    Fault      fault  = null;
                    FormInvoke invoke = new FormInvoke(
                        delegate
                    {
                        _form.UpdateButton(update.Body);
                    }
                        );

                    WinFormsServicePort.Post(invoke);
                    yield return(Arbiter.Choice(
                                     invoke.ResultPort,
                                     EmptyHandler,
                                     delegate(Exception e)
                    {
                        fault = Fault.FromException(e);
                    }
                                     ));

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

                _state.Buttons[index] = update.Body;
                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                DoSendNotification(update);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called on a rotate single axis.
        /// </summary>
        /// <param name="rotate">The rotation.</param>
        private void OnRotateSingleAxis(pantilt.Rotate rotate)
        {
            var degrees = rotate.Body.RotateTiltRequest.TargetRotationAngleInRadians * 180 / Math.PI;

            this.state.TiltAngle = Math.Round(degrees);

            var angle  = (int)this.state.TiltAngle;
            var update = new FormInvoke(() =>
            {
                this.dashboardForm.TiltTextbox.Text = angle.ToString();
            });

            WinFormsServicePort.Post(update);
        }
Exemplo n.º 5
0
        public void OnSetTitle(SetTitle setTitle)
        {
            FormInvoke invoke = new FormInvoke(
                delegate
            {
                _form.SetTitle(setTitle.Body.Title);
            }
                );

            WinFormsServicePort.Post(invoke);

            _state.Title = setTitle.Body.Title;
            setTitle.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            DoSendNotification(setTitle);
        }
Exemplo n.º 6
0
        public void OnShow(Show show)
        {
            FormInvoke invoke = new FormInvoke(
                delegate
            {
                _form.SetVisibility(show.Body.Show);
            }
                );

            WinFormsServicePort.Post(invoke);

            _state.Visible = show.Body.Show;
            show.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            DoSendNotification(show);
        }
Exemplo n.º 7
0
        public IEnumerator <ITask> OnDeleteButton(DeleteButton delete)
        {
            FlexButton existing = _state.Buttons.Find(delete.Body.CompareId);

            if (existing == null)
            {
                delete.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "A button with the requested ID does not exist: " + delete.Body.Id
                        )
                    );
            }
            else
            {
                Fault      fault  = null;
                FormInvoke invoke = new FormInvoke(
                    delegate
                {
                    _form.DeleteButton(delete.Body);
                }
                    );

                WinFormsServicePort.Post(invoke);
                yield return(Arbiter.Choice(
                                 invoke.ResultPort,
                                 EmptyHandler,
                                 delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
                                 ));

                if (fault != null)
                {
                    delete.ResponsePort.Post(fault);
                }
                else
                {
                    _state.Buttons.Remove(existing);
                    delete.ResponsePort.Post(DefaultDeleteResponseType.Instance);
                    DoSendNotification(delete);
                }
            }
        }
Exemplo n.º 8
0
        public IEnumerator <ITask> OnInsertButton(InsertButton insert)
        {
            if (_state.Buttons.Exists(insert.Body.CompareId) ||
                _state.Controls.Exists(insert.Body.CompareId))
            {
                insert.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.DuplicateEntry,
                        "A button with the same ID already exists: " + insert.Body.Id
                        )
                    );
            }
            else
            {
                Fault      fault  = null;
                FormInvoke invoke = new FormInvoke(
                    delegate
                {
                    _form.InsertButton(insert.Body);
                }
                    );

                WinFormsServicePort.Post(invoke);
                yield return(Arbiter.Choice(
                                 invoke.ResultPort,
                                 EmptyHandler,
                                 delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
                                 ));

                if (fault != null)
                {
                    insert.ResponsePort.Post(fault);
                }
                else
                {
                    _state.Buttons.Add(insert.Body);
                    insert.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                    DoSendNotification(insert);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Display an image in the WebCam Form
        /// </summary>
        /// <param name="bmp">
        /// The bitmap to display
        /// </param>
        private void DisplayImage(Bitmap bmp)
        {
            Fault fault = null;

            var setImage = new FormInvoke(() => this.cameraForm.CameraImage = bmp);

            WinFormsServicePort.Post(setImage);

            Arbiter.Choice(setImage.ResultPort, EmptyHandler, e => fault = Fault.FromException(e));

            if (fault == null)
            {
                // LogInfo("New camera frame");
                return;
            }

            this.LogError(null, "Unable to set camera image on form", fault);
            return;
        }
Exemplo n.º 10
0
        IEnumerator <ITask> DoBlobTrackerImageProcessedHandler(bt.ImageProcessed processed)
        {
            try
            {
                Fault fault = null;

                FormInvoke setTracking = new FormInvoke(
                    delegate
                {
                    if (!_form.IsDisposed)
                    {
                        _form.Tracking = processed.Body.Results;
                    }
                }
                    );

                WinFormsServicePort.Post(setTracking);

                yield return(Arbiter.Choice(
                                 setTracking.ResultPort,
                                 delegate(EmptyValue success) { },
                                 delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
                                 ));

                if (fault != null)
                {
                    LogError(null, "Unable to set tracking information", fault);
                    yield break;
                }
            }
            finally
            {
                _mainPort.Post(new UpdateProcessing(false));
            }
        }
Exemplo n.º 11
0
        // Display an image in the WebCam Form
        bool DisplayImage(Bitmap bmp)
        {
            Fault fault = null;
            
            FormInvoke setImage = new FormInvoke(
                delegate()
                {
                    _driveControl.CameraImage = bmp;
                }
            );

            WinFormsServicePort.Post(setImage);

            Arbiter.Choice(
                setImage.ResultPort,
                delegate(EmptyValue success) { },
                delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
            );

            if (fault != null)
            {
                LogError(null, "Unable to set camera image on form", fault);
                return false;
            }
            else
            {
                // LogInfo("New camera frame");
                return true;
            }
        }
        /// <summary>
        /// Update depth profile image on form
        /// </summary>
        private void UpdateDepthProfileImage()
        {
            // Update depth profile image
            Bitmap image = null;

            if (!this.TryCreateDepthImage(out image))
            {
                throw new InvalidOperationException("Unable to create depth profile image since depth sample is not available");
            }

            var setImage = new FormInvoke(() => this.obstacleAvoidanceForm.DepthProfileImage = image);

            WinFormsServicePort.Post(setImage);

            Arbiter.Choice(setImage.ResultPort, EmptyHandler, e => LogError(null, "Unable to set depth profile image on form", Fault.FromException(e)));
        }
Exemplo n.º 13
0
        IEnumerator <ITask> DoCameraUpdateFrameHandler(cam.UpdateFrame update)
        {
            try
            {
                cam.QueryFrameResponse frame = null;
                Fault fault = null;

                yield return(Arbiter.Choice(
                                 _webCamPort.QueryFrame(new cam.QueryFrameRequest()),
                                 delegate(cam.QueryFrameResponse success)
                {
                    frame = success;
                },
                                 delegate(Fault f)
                {
                    fault = f;
                }
                                 ));

                if (fault != null)
                {
                    LogError(null, "Failed to get frame from camera", fault);
                    yield break;
                }

                Bitmap bmp = new Bitmap(
                    frame.Size.Width,
                    frame.Size.Height,
                    PixelFormat.Format24bppRgb
                    );

                BitmapData data = bmp.LockBits(
                    new Rectangle(0, 0, bmp.Width, bmp.Height),
                    ImageLockMode.WriteOnly,
                    PixelFormat.Format24bppRgb
                    );

                Marshal.Copy(frame.Frame, 0, data.Scan0, frame.Frame.Length);

                bmp.UnlockBits(data);

                FormInvoke setImage = new FormInvoke(
                    delegate()
                {
                    if (!_form.IsDisposed)
                    {
                        _form.CameraImage = bmp;
                    }
                }
                    );

                WinFormsServicePort.Post(setImage);

                Arbiter.Choice(
                    setImage.ResultPort,
                    delegate(EmptyValue success) { },
                    delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
                    );

                if (fault != null)
                {
                    LogError(null, "Unable to set camera image on form", fault);
                    yield break;
                }
            }
            finally
            {
                _mainPort.Post(new UpdateProcessing(false));
            }
        }