コード例 #1
0
        public async Task <IPrompt> PlayPromptAsync(Uri promptUri, LoggingContext loggingContext)
        {
            if (promptUri == null)
            {
                throw new ArgumentNullException(nameof(promptUri));
            }

            string href = PlatformResource?.PlayPromptLink?.Href;

            if (string.IsNullOrWhiteSpace(href))
            {
                throw new CapabilityNotAvailableException("Link to play prompt is not available.");
            }

            var input = new PlayPromptInput()
            {
                PromptUrl = promptUri.ToString(), Loop = false
            };

            var playPromptLink = UriHelper.CreateAbsoluteUri(BaseUri, href);

            TaskCompletionSource <Prompt> tcs = new TaskCompletionSource <Prompt>();
            var response = await PostRelatedPlatformResourceAsync(playPromptLink, input, new ResourceJsonMediaTypeFormatter(), loggingContext).ConfigureAwait(false);

            if (response?.Headers?.Location != null)
            {
                m_onGoingPromptTcses.TryAdd(UriHelper.CreateAbsoluteUri(this.BaseUri, response.Headers.Location.ToString()).ToString().ToLower(), tcs);
            }

            // Return task to wait for the prompt completed event
            return(await tcs.Task.ConfigureAwait(false));
        }
コード例 #2
0
        public async Task StopPromptsShouldReturnOnlyOnAllPromptsCompletedEvent()
        {
            // Given
            TestHelper.RaiseEventsFromFile(m_mockEventChannel, "Event_AudioVideoFlowConnected.json");
            TaskCompletionSource <bool> requestReceived = new TaskCompletionSource <bool>();

            m_restfulClient.HandleRequestProcessed += (sender, args) =>
            {
                if (args.Uri == new Uri(DataUrls.StopPrompts) && args.Method == HttpMethod.Post)
                {
                    requestReceived.SetResult(true);
                }
            };

            const string prompt2Url = "https://example.com/prompt2";

            m_restfulClient.HandleRequestReceived += (sender, args) =>
            {
                PlayPromptInput input = args.Input as PlayPromptInput;
                if (input?.PromptUrl == prompt2Url)
                {
                    args.Response = new HttpResponseMessage(HttpStatusCode.Created);
                    args.Response.Headers.Add("Location",
                                              "https://webpoolbl20r04.infra.lync.com/platformservice/tgt-8c81281c925a5c2ea02ec14ac1b492c6/v1/applications/1393347000/communication/conversations/869ce4f6-0076-483a-a7c1-968f6b935afe/audioVideo/audioVideoFlow/prompts/08b7bd6e-0e79-4961-8981-116ac9ddd152?endpointId=sip:[email protected]");
                }
            };

            // When
            #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            m_audioVideoFlow.PlayPromptAsync(new Uri("https://example.com/prompt"), m_loggingContext);
            m_audioVideoFlow.PlayPromptAsync(new Uri("https://example.com/prompt2"), m_loggingContext);
            #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            TestHelper.RaiseEventsFromFile(m_mockEventChannel, "Event_PromptStarted.json");
            TestHelper.RaiseEventsFromFile(m_mockEventChannel, "Event_Prompt2Started.json");

            Task stopTask = m_audioVideoFlow.StopPromptsAsync(m_loggingContext);
            await requestReceived.Task.TimeoutAfterAsync(TimeSpan.FromMilliseconds(200)).ConfigureAwait(false);

            // none of the prompt tasks is stopped yet
            Assert.IsFalse(stopTask.IsCompleted);

            // receiving stopped event for promptTask
            TestHelper.RaiseEventsFromFile(m_mockEventChannel, "Event_PromptStopped.json");

            // yet to receiving stopped event for promptTask2
            Assert.IsFalse(stopTask.IsCompleted);

            // receiving stopped event for promptTask2
            TestHelper.RaiseEventsFromFile(m_mockEventChannel, "Event_Prompt2Stopped.json");

            // stop task must be completed
            await stopTask.TimeoutAfterAsync(TimeSpan.FromMilliseconds(200)).ConfigureAwait(false);

            Assert.IsTrue(stopTask.IsCompleted);
        }