public IEnumerator <ITask> SayTextHandler(SayText sayText)
        {
            _state.SpeechText = sayText.Body.SpeechText;
            _state.Synthesizer.SpeakAsync(_state.SpeechText);

            sayText.ResponsePort.Post(DefaultUpdateResponseType.Instance);
            yield break;
        }
        public IEnumerator <ITask> ReplaceHandler(Replace replace)
        {
            // Use try/catch to respond with meaningful error in case of an exception
            try
            {
                SetRate(replace.Body.Rate);
                SetVolume(replace.Body.Volume);
                SetVoice(replace.Body.Voice);
            }
            catch (ArgumentException e)
            {
                replace.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        W3C.Soap.FaultCodes.Receiver,
                        DsspFaultCodes.OperationFailed,
                        e.Message
                        )
                    );
                yield break;
            }

            DisableAudioOutput(replace.Body.DisableAudioOutput);

            SayText say = new SayText();

            say.Body.SpeechText = replace.Body.SpeechText;
            SpawnIterator(say, SayTextHandler);

            yield return((Choice)say.ResponsePort);

            Fault fault = (Fault)say.ResponsePort;

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

            SaveState(_state);

            // Notify subscribers of state change
            Replace subscriberReplace = new Replace();

            subscriberReplace.Body = _state;
            SendNotification <Replace>(_subMgrPort, subscriberReplace);

            replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
        }
        public IEnumerator <ITask> HttpPostHandler(HttpPost httpPost)
        {
            ReadFormData readForm = new ReadFormData(httpPost);

            _utilities.Post(readForm);

            PortSet <NameValueCollection, Exception> readFormResponsePort = readForm.ResultPort;

            yield return((Choice)readFormResponsePort);

            Exception exception = (Exception)readFormResponsePort;

            if (exception != null)
            {
                LogError(exception);
                httpPost.ResponsePort.Post(Fault.FromException(exception));
                yield break;
            }

            NameValueCollection collection = (NameValueCollection)readFormResponsePort;
            string voice      = collection["Voice"];
            string rate       = collection["Rate"];
            string volume     = collection["Volume"];
            string speechText = collection["SpeechText"];

            PortSet <DefaultUpdateResponseType, Fault> responsePort = null;

            if (!string.IsNullOrEmpty(voice))
            {
                SetVoice setVoice = new SetVoice(new SetVoiceRequest(voice));
                SpawnIterator(setVoice, SetVoiceHandler);

                responsePort = setVoice.ResponsePort;
            }
            else if (!string.IsNullOrEmpty(rate))
            {
                int rateInt;
                if (int.TryParse(rate, out rateInt))
                {
                    SetRate setRate = new SetRate();
                    setRate.Body.Rate = rateInt;
                    SpawnIterator(setRate, SetRateHandler);

                    responsePort = setRate.ResponsePort;
                }
            }
            else if (!string.IsNullOrEmpty(volume))
            {
                int volumeInt;

                if (int.TryParse(volume, out volumeInt))
                {
                    SetVolume setVolume = new SetVolume();
                    setVolume.Body.Volume = volumeInt;
                    SpawnIterator(setVolume, SetVolumeHandler);

                    responsePort = setVolume.ResponsePort;
                }
            }
            else if (!string.IsNullOrEmpty(speechText))
            {
                SayText sayText = new SayText(new SayTextRequest(speechText));
                SpawnIterator(sayText, SayTextHandler);

                responsePort = sayText.ResponsePort;
            }

            if (responsePort != null)
            {
                yield return((Choice)responsePort);

                Fault fault = (Fault)responsePort;
                if (fault != null)
                {
                    LogError("Unable to perform post operation", fault);
                    httpPost.ResponsePort.Post(fault);
                    yield break;
                }
            }

            httpPost.ResponsePort.Post(new HttpResponseType(
                                           HttpStatusCode.OK,
                                           _state,
                                           base.StateTransformPath // Use the transform declared on the State
                                           ));
            yield break;
        }