Exemple #1
0
        public AdventureSampleProcessor(ILogger <AdventureSampleProcessor> logger,
                                        IAdventureRepository adventureRep,
                                        ICurrentNodeRepository curNodeRep,
                                        IMediaLinkProcessor linkProcessor)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger is not set");
            }

            if (adventureRep == null)
            {
                throw new ArgumentNullException("adventureRep is not set");
            }

            if (curNodeRep == null)
            {
                throw new ArgumentNullException("curNodeRep is not set");
            }

            if (linkProcessor == null)
            {
                throw new ArgumentNullException("linkProcessor is not set");
            }


            _logger = logger;


            //  _adventureConfig = adventureConfig.Value;
            _adventureRep  = adventureRep;
            _curNodeRep    = curNodeRep;
            _linkProcessor = linkProcessor;
        }
Exemple #2
0
        internal AlexaResponse ToAlexaResponse(IMediaLinkProcessor linkProcessor, string voiceId)
        {
            AlexaResponse resp = new AlexaResponse()
            {
                Version  = "1.0",
                Response = new AlexaResponseAttributes()
                {
                    OutputSpeech = new OutputSpeechAttributes()
                }
            };

            resp.Response.OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(GetSpeechText(this.OutputSpeech, linkProcessor, voiceId));

            string repromptText = GetSpeechText(this.Reprompt, linkProcessor, voiceId);

            if (!string.IsNullOrWhiteSpace(repromptText))
            {
                resp.Response.Reprompt = new RepromptAttributes()
                {
                    OutputSpeech = OutputSpeechBuilder.GetSsmlSpeech(repromptText)
                };
            }


            if (this.Card != null)
            {
                if (!string.IsNullOrWhiteSpace(this.Card.LargeImage) || !string.IsNullOrWhiteSpace(this.Card.SmallImage))
                {
                    resp.Response.Card = CardBuilder.GetStandardCardResponse(this.Card.Title, this.Card.Text,
                                                                             linkProcessor.GetImageUrl(this.Card.SmallImage),
                                                                             linkProcessor.GetImageUrl(this.Card.LargeImage));
                }
                else
                {
                    resp.Response.Card = CardBuilder.GetSimpleCardResponse(this.Card.Title, this.Card.Text);
                }
            }

            if ((NodeRoutes?.Any()).GetValueOrDefault(false))
            {
                resp.Response.ShouldEndSession = false;
            }
            else
            {
                // there are no choices available. End the session.
                resp.Response.ShouldEndSession = true;
            }


            return(resp);
        }
        private IServiceProvider GetTestProvider(string imageRoot)
        {
            AdventureSampleConfig checkerConfig = new AdventureSampleConfig();

            var serviceProvider = new Mock <IServiceProvider>();


            IOptions <AdventureSampleConfig> mockConfig = Options.Create(new AdventureSampleConfig());


            serviceProvider
            .Setup(x => x.GetService(typeof(IOptions <AdventureSampleConfig>)))
            .Returns(mockConfig);

            ILogger <AdventureSampleProcessor> adventureLogger = Mock.Of <ILogger <AdventureSampleProcessor> >();

            serviceProvider
            .Setup(x => x.GetService(typeof(ILogger <AdventureSampleProcessor>)))
            .Returns(adventureLogger);


            //ISqsService sqsService = Mock.Of<ISqsService>();
            //serviceProvider
            //    .Setup(x => x.GetService(typeof(ISqsService)))
            //    .Returns(sqsService);


            IAdventureRepository advRep = Mock.Of <IAdventureRepository>();

            ICurrentNodeRepository curRep = Mock.Of <ICurrentNodeRepository>();

            IMediaLinkProcessor mediaLinker = Mock.Of <IMediaLinkProcessor>();

            // IAdventureSampleProcessor adventureProcessor = new AdventureSampleProcessor(mockConfig, emailLogger, userManager, progMan, sqsService);

            IAdventureSampleProcessor adventureProcessor = new AdventureSampleProcessor(adventureLogger, advRep, curRep, mediaLinker);

            serviceProvider
            .Setup(x => x.GetService(typeof(IAdventureSampleProcessor)))
            .Returns(adventureProcessor);

            return(serviceProvider.Object);

            //public EmailProcessor(IOptions<EmailCheckerConfig> emailCheckerConfig,
            //                        ILogger<EmailProcessor> logger,
            //                        IAlexaUserDataManager userDataManager,
            //                        IProgressiveResponseManager progMan,
            //                        ISqsService sqsService
            //                      )
        }
Exemple #4
0
        internal static string GetSpeechText(List <SpeechFragement> speechFrags, IMediaLinkProcessor linkProcessor, string voiceId)
        {
            string outputSpeech = null;

            if ((speechFrags?.Any()).GetValueOrDefault(false))
            {
                StringBuilder speechBuilder = new StringBuilder();
                foreach (SpeechFragement speechFrag in speechFrags)
                {
                    switch (speechFrag.FragmentType)
                    {
                    case SpeechFramgementType.Text:

                        string appliedVoiceId = string.IsNullOrWhiteSpace(speechFrag.VoiceId) ? voiceId : speechFrag.VoiceId;

                        if (!string.IsNullOrWhiteSpace(appliedVoiceId))
                        {
                            speechBuilder.Append($"<voice name=\"{appliedVoiceId}\">{speechFrag.Text}</voice>");
                        }
                        else
                        {
                            speechBuilder.Append(speechFrag.Text);
                        }

                        break;

                    case SpeechFramgementType.AudioFile:
                        string linkPath = linkProcessor.GetAudioUrl(speechFrag.AudioFileName);

                        speechBuilder.Append(string.Format(AUDIOTAG, linkPath));
                        break;

                    case SpeechFramgementType.AudioLibrary:
                        speechBuilder.Append(speechFrag.AudioLibraryTag);

                        break;
                    }
                }

                outputSpeech = $"<speak>{speechBuilder.ToString()}</speak>";
            }

            return(outputSpeech);
        }