コード例 #1
0
        internal override void HandleResourceEvent(EventContext eventcontext)
        {
            TPlatformResource resource = this.ConvertToPlatformServiceResource <TPlatformResource>(eventcontext);

            if (resource != null)
            {
                if (eventcontext.EventEntity.Relationship == ResourceModel.EventOperation.Completed)
                {
                    if (resource.State == InvitationState.Failed)
                    {
                        ResourceModel.ErrorInformation error = eventcontext.EventEntity.Error;
                        ErrorInformation errorInfo           = error == null ? null : new ErrorInformation(error);
                        string           errorMessage        = errorInfo?.ToString();
                        m_invitationCompleteTcs.TrySetException(new RemotePlatformServiceException("Invitation failed " + errorMessage, errorInfo));
                    }
                    else if (resource.State == InvitationState.Connected)
                    {
                        m_invitationCompleteTcs.TrySetResult(this.RelatedConversation);
                    }
                }
                else if (eventcontext.EventEntity.Relationship == ResourceModel.EventOperation.Started)
                {
                    var communication = this.Parent as Communication;
                    communication.HandleInviteStarted(resource.OperationContext, this);
                }

                base.HandleResourceEvent(eventcontext);
            }
        }
コード例 #2
0
        internal override bool ProcessAndDispatchEventsToChild(EventContext eventContext)
        {
            if (eventContext.EventEntity.Link.Token == ResourceModel.TokenMapper.GetTokenName(typeof(ToneResource)))
            {
                var toneResource       = ConvertToPlatformServiceResource <ToneResource>(eventContext);
                Uri audioVideoFlowLink = UriHelper.CreateAbsoluteUri(this.BaseUri, toneResource.AudioVideoFlowLink.Href);

                if (string.Equals(audioVideoFlowLink.ToString(), this.ResourceUri.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    var eventArgs = new ToneReceivedEventArgs(toneResource.ToneValue);
                    m_toneReceivedEvent?.Invoke(this, eventArgs);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            //No child to dispatch any more, need to dispatch to child , process locally for message type
            else if (string.Equals(eventContext.EventEntity.Link.Token, ResourceModel.TokenMapper.GetTokenName(typeof(PromptResource))))
            {
                PromptResource prompt = this.ConvertToPlatformServiceResource <PromptResource>(eventContext);
                if (prompt != null)
                {
                    if (eventContext.EventEntity.Relationship == ResourceModel.EventOperation.Completed)
                    {
                        TaskCompletionSource <Prompt> tcs = null;
                        Uri resourceAbsoluteUri           = UriHelper.CreateAbsoluteUri(this.BaseUri, eventContext.EventEntity.Link.Href);
                        m_onGoingPromptTcses.TryGetValue(resourceAbsoluteUri.ToString().ToLower(), out tcs);
                        if (tcs != null)
                        {
                            Prompt p = new Prompt(this.RestfulClient, prompt, this.BaseUri, resourceAbsoluteUri, this);

                            if (eventContext.EventEntity.Status == ResourceModel.EventStatus.Success)
                            {
                                tcs.TrySetResult(p);
                            }
                            else if (eventContext.EventEntity.Status == ResourceModel.EventStatus.Failure)
                            {
                                ResourceModel.ErrorInformation error = eventContext.EventEntity.Error;
                                ErrorInformation errorInfo           = error == null ? null : new ErrorInformation(error);
                                string           errorMessage        = errorInfo?.ToString();
                                tcs.TrySetException(new RemotePlatformServiceException("PlayPrompt failed with error " + errorMessage + eventContext.LoggingContext.ToString(), errorInfo));
                            }
                            else
                            {
                                Logger.Instance.Error("Received invalid status code for prompt completed event");
                                tcs.TrySetException(new RemotePlatformServiceException("PlayPrompt failed"));
                            }
                            m_onGoingPromptTcses.TryRemove(eventContext.EventEntity.Link.Href.ToLower(), out tcs);
                        }
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }