Пример #1
0
        public async Task <Answer <T> > AskAsync <T>(string question, List <QuestionAnswerAlternative <T> > alternatives, int millisecondsTimeout = 3000)
        {
            if (_settingAgent.GetSetting("Muted", false))
            {
                //TODO: Show dialog where the anser can be entered. The dialog should have the same timeout as the default answer.
                //There should be one answer for each alternative, up to a limit, where there will be a drop down.
                //If there are no set alternatives, there should be a text input box for answers.
                //Also look at the other question functions: AskYesNoAsync, AskFolderAsync and AskStringAsync. And align them as well.
                return(GetDefaultAnswer(alternatives));
            }

            try
            {
                using (var listenerAgent = new ListenerAgent <T>(_eventHub, alternatives))
                {
                    listenerAgent.HeardSomethingEvent += EventHub_HeardSomethingEvent;

                    var listenId = Guid.NewGuid();
                    _eventHub.InvokeStartListeningEvent(listenId);

                    await _talkAgent.SayAsync(question);

                    listenerAgent.StartListening();

                    var r = await Task.Factory.StartNew(() =>
                    {
                        if (!_responseEvent.WaitOne(millisecondsTimeout))
                        {
                            return(GetDefaultAnswer(alternatives));
                        }

                        var selectedAlternative = alternatives.First(x => x.Phrases.Any(y => y == _responsePhrase));
                        return(new Answer <T>(selectedAlternative.Response));
                    });

                    _eventHub.InvokeDoneListeningEvent(listenId);

                    return(r);
                }
            }
            catch (InvalidOperationException exception)
            {
                CompositeRoot.Instance.TalkAgent.SayAsync("Oups, now we have problems! " + exception.Message);
                _settingAgent.SetSetting("Muted", true);
            }

            return(GetDefaultAnswer(alternatives));
        }
Пример #2
0
        protected GitBitchCommand(ISettingAgent settingAgent, string name, string[] phrases = null)
        {
            _settingAgent = settingAgent;
            _name         = name;
            var greetingName    = settingAgent.GetSetting(Constants.Greeting, Constants.DefaultGreeting);
            var requireGreeting = settingAgent.GetSetting(Constants.RequireGreeting, false);

            _greeting = new Tuple <string, bool>(greetingName, requireGreeting);

            var bitchName        = settingAgent.GetSetting(Constants.BitchName, Constants.DefaultBitchName);
            var requireBitchName = settingAgent.GetSetting(Constants.RequireBitchName, true);

            _bitchName = new Tuple <string, bool>(bitchName, requireBitchName);

            AddPhrases(string.Empty, phrases ?? new string[] { });
        }
Пример #3
0
        private async Task DoSay(string actualPhrase)
        {
            var bitchName = _settingAgent.GetSetting("BitchName", Constants.DefaultBitchName);
            var newGuid   = Guid.NewGuid();

            _eventHub.InvokeStartTalkingEvent(newGuid, bitchName, actualPhrase);

            var task = new Task(() =>
            {
                var builder = new PromptBuilder();
                builder.StartSentence();
                builder.AppendText(actualPhrase);
                builder.EndSentence();

                using (var synthesizer = new SpeechSynthesizer())
                {
                    var voices = synthesizer.GetInstalledVoices();
                    var voice  = voices.LastOrDefault(x => x.VoiceInfo.Gender == VoiceGender.Female);
                    if (voice == null)
                    {
                        voice = voices.FirstOrDefault();
                    }
                    if (voice == null)
                    {
                        throw new InvalidOperationException("Cannot find any installed voices.");
                    }

                    //synthesizer.SelectVoice("Microsoft David Desktop");
                    //synthesizer.SelectVoice("Microsoft Hazel Desktop");
                    //synthesizer.SelectVoice("Microsoft Zira Desktop");

                    synthesizer.SelectVoice(voice.VoiceInfo.Name);
                    synthesizer.Speak(builder);
                }
            });

            task.Start();
            await task;

            _eventHub.InvokeDoneTalkingEvent(newGuid);
        }
Пример #4
0
        public string GetSelectedPath()
        {
            var path = _settingAgent.GetSetting <string>("Repositories", _selectedRepositoryName, null);

            return(path);
        }
Пример #5
0
 public RepositoryBusines(IDataRepository dataRepository, ISettingAgent settingAgent)
 {
     _dataRepository         = dataRepository;
     _settingAgent           = settingAgent;
     _selectedRepositoryName = _settingAgent.GetSetting <string>("LastSelected", null);
 }