Ejemplo n.º 1
0
        public IEnumerator <ITask> OnUpdateControl(UpdateControl update)
        {
            int index = _state.Controls.FindIndex(update.Body.CompareId);

            if (index < 0)
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "A control 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.UpdateControl(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.Controls[index] = update.Body;
                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);
                DoSendNotification(update);
            }
        }
Ejemplo n.º 2
0
        public IEnumerator <ITask> OnHttpPost(HttpPost post)
        {
            Fault fault = null;

            NameValueCollection parameters = null;

            ReadFormData readForm = new ReadFormData(post);

            _utilities.Post(readForm);
            yield return(Arbiter.Choice(
                             readForm.ResultPort,
                             delegate(NameValueCollection success)
            {
                parameters = success;
            },
                             delegate(Exception e)
            {
                fault = Fault.FromException(e);
            }
                             ));

            string operation = parameters["Operation"];

            if (operation == "UpdateControl")
            {
                UpdateControl message = new UpdateControl();
                FlexControl   update  = message.Body;
                update.Id    = parameters["ID"];
                update.Value = parameters["Value"];
                update.Text  = parameters["Text"];

                FlexControl control = _state.Controls.Find(update.CompareId);

                if (control == null)
                {
                    post.ResponsePort.Post(Fault.FromCodeSubcodeReason(
                                               FaultCodes.Receiver,
                                               DsspFaultCodes.UnknownEntry,
                                               "Cannot find control with ID: " + update.Id
                                               ));
                    yield break;
                }
                update.ControlType = control.ControlType;

                yield return(Arbiter.ExecuteToCompletion(
                                 TaskQueue,
                                 new IterativeTask <UpdateControl>(message, OnUpdateControl)
                                 ));

                post.ResponsePort.Post(new HttpResponseType(DefaultUpdateResponseType.Instance));
            }
            else if (operation == "ButtonPress")
            {
                ButtonPress        message = new ButtonPress();
                ButtonPressRequest request = message.Body;
                request.Id      = parameters["ID"];
                request.Pressed = bool.Parse(parameters["Pressed"]);

                OnButtonPress(message);

                post.ResponsePort.Post(new HttpResponseType(DefaultUpdateResponseType.Instance));
            }
            else
            {
                fault = Fault.FromCodeSubcodeReason(
                    FaultCodes.Receiver,
                    DsspFaultCodes.MessageNotSupported,
                    "Unknown operation: " + operation
                    );
            }

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