示例#1
0
        /// <summary>
        /// Show a Sign In dialog if the remote endpoint demands a UserNameIdentity token.
        /// </summary>
        /// <param name="endpoint">The remote endpoint.</param>
        /// <returns>A UserIdentity</returns>
        public Task <IUserIdentity> ProvideUserIdentity(EndpointDescription endpoint)
        {
            if (endpoint.UserIdentityTokens.Any(p => p.TokenType == UserTokenType.Anonymous))
            {
                return(Task.FromResult <IUserIdentity>(new AnonymousIdentity()));
            }

            if (endpoint.UserIdentityTokens.Any(p => p.TokenType == UserTokenType.UserName))
            {
                var tcs = new TaskCompletionSource <IUserIdentity>();

                this.NavigationService.Dispatcher.DispatchIdleAsync(async() =>
                {
                    var d      = new UserIdentityDialog(endpoint);
                    var result = await d.ShowAsync();
                    if (result == ContentDialogResult.Primary)
                    {
                        tcs.TrySetResult(d.UserIdentity);
                    }
                    tcs.TrySetResult(new AnonymousIdentity());
                });
                return(tcs.Task);
            }

            throw new NotImplementedException("ProvideUserIdentity supports only UserName and Anonymous identity, for now.");
        }
示例#2
0
        /// <summary>
        /// Show a Sign In dialog if the remote endpoint demands a UserNameIdentity token.
        /// </summary>
        /// <param name="endpoint">The remote endpoint.</param>
        /// <returns>A UserIdentity</returns>
        private async Task <IUserIdentity> ShowSignInDialog(EndpointDescription endpoint)
        {
            if (endpoint.UserIdentityTokens.Any(p => p.TokenType == UserTokenType.Anonymous))
            {
                return(new AnonymousIdentity());
            }

            if (endpoint.UserIdentityTokens.Any(p => p.TokenType == UserTokenType.UserName))
            {
                var tcs = new TaskCompletionSource <IUserIdentity>();

                var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
                if (dispatcher != null)
                {
                    await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                    {
                        var d      = new UserIdentityDialog(endpoint);
                        var result = await d.ShowAsync();
                        if (result == ContentDialogResult.Primary)
                        {
                            tcs.TrySetResult(d.UserIdentity);
                        }
                        tcs.TrySetResult(new AnonymousIdentity());
                    });
                }
                return(await tcs.Task);
            }

            throw new NotImplementedException("SignInDialog supports only UserName and Anonymous identity, for now.");
        }