Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the current user has a specific privilege
        /// </summary>
        /// <param name="user">XboxLiveUser that identifies the user to show the UI on behalf of.</param>
        /// <param name="privilege">The privilege to check.</param>
        /// <returns>
        /// A boolean which is true if the current user has the privilege.
        /// </returns>
        public static bool CheckGamingPrivilegeSilently(XboxLiveUser user, GamingPrivilege privilege)
        {
            var tcs = new TaskCompletionSource <bool>();

            Task.Run(() =>
            {
                int contextKey = XboxLiveCallbackContext <TitleCallableUI, bool> .CreateContext(null, tcs);

                XboxLive.Instance.Invoke <XsapiResult, TCUICheckGamingPrivilegeSilently>(
                    privilege,
                    (CheckGamingPrivilegeCompletionRoutine)CheckGamingPrivilegeSilentlyComplete,
                    (IntPtr)contextKey,
                    XboxLive.DefaultTaskGroupId
                    );
            });

            tcs.Task.Wait();
            return(tcs.Task.Result);
        }
Ejemplo n.º 2
0
        public Task <SignInResult> SignInImpl(bool showUI, bool forceRefresh)
        {
            var tcs = new TaskCompletionSource <SignInResult>();

            Task.Run(() =>
            {
                IntPtr coreDispatcherPtr = default(IntPtr);
                if (showUI)
                {
                    coreDispatcherPtr = Marshal.GetIUnknownForObject(Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher);
                }

                int contextKey = XboxLiveCallbackContext <UserImpl, SignInResult> .CreateContext(
                    this,
                    tcs,
                    showUI ? new List <IntPtr> {
                    coreDispatcherPtr
                } : null,
                    null);

                if (showUI)
                {
                    XboxLive.Instance.Invoke <XsapiResult, XboxLiveUserSignInWithCoreDispatcher>(
                        m_xboxLiveUser_c,
                        coreDispatcherPtr,
                        (SignInCompletionRoutine)SignInComplete,
                        (IntPtr)contextKey,
                        XboxLive.DefaultTaskGroupId
                        );
                }
                else
                {
                    XboxLive.Instance.Invoke <XsapiResult, XboxLiveUserSignInSilently>(
                        m_xboxLiveUser_c,
                        (SignInCompletionRoutine)SignInComplete,
                        (IntPtr)contextKey,
                        XboxLive.DefaultTaskGroupId
                        );
                }
            });

            return(tcs.Task);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Shows UI displaying the profile card for a specified user.
        /// </summary>
        /// <param name="user">XboxLiveUser that identifies the user to show the UI on behalf of.</param>
        /// <param name="targetXboxUserId">The Xbox User ID to show information about.</param>
        /// <returns>
        /// An interface for tracking the progress of the asynchronous call.
        /// The operation completes when the UI is closed.
        /// </returns>
        public static Task ShowProfileCardUIAsync(XboxLiveUser user, string targetXboxUserId)
        {
            var tcs = new TaskCompletionSource <bool>();

            Task.Run(() =>
            {
                var pTargetXboxUserId = MarshalingHelpers.StringToHGlobalUtf8(targetXboxUserId);
                int contextKey        = XboxLiveCallbackContext <TitleCallableUI, bool> .CreateContext(null, tcs, null, new List <IntPtr> {
                    pTargetXboxUserId
                });

                XboxLive.Instance.Invoke <XsapiResult, TCUIShowProfileCardUI>(
                    pTargetXboxUserId,
                    (ShowProfileCardUICompletionRoutine)ShowProfileCardUIComplete,
                    (IntPtr)contextKey,
                    XboxLive.DefaultTaskGroupId
                    );
            });

            return(tcs.Task);
        }
Ejemplo n.º 4
0
        public Task <TokenAndSignatureResult> InternalGetTokenAndSignatureAsync(string httpMethod, string url, string headers, byte[] body, bool promptForCredentialsIfNeeded, bool forceRefresh)
        {
            var tcs = new TaskCompletionSource <TokenAndSignatureResult>();

            Task.Run(() =>
            {
                IntPtr pHttpMethod = MarshalingHelpers.StringToHGlobalUtf8(httpMethod);
                IntPtr pUrl        = MarshalingHelpers.StringToHGlobalUtf8(url);
                IntPtr pHeaders    = MarshalingHelpers.StringToHGlobalUtf8(headers);

                IntPtr pBody = IntPtr.Zero;
                if (body != null)
                {
                    Marshal.AllocHGlobal(body.Length + 1);
                    Marshal.Copy(body, 0, pBody, body.Length);
                    Marshal.WriteByte(pBody, body.Length, 0);
                }

                int contextKey = XboxLiveCallbackContext <UserImpl, TokenAndSignatureResult> .CreateContext(
                    this,
                    tcs,
                    null,
                    new List <IntPtr> {
                    pHttpMethod, pUrl, pHeaders, pBody
                });

                XboxLive.Instance.Invoke <XsapiResult, XboxLiveUserGetTokenAndSignature>(
                    m_xboxLiveUser_c,
                    pHttpMethod,
                    pUrl,
                    pHeaders,
                    pBody,
                    (GetTokenAndSignatureCompletionRoutine)GetTokenAndSignatureComplete,
                    (IntPtr)contextKey,
                    XboxLive.DefaultTaskGroupId
                    );
            });

            return(tcs.Task);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks if the current user has a specific privilege and if it doesn't, it shows UI
        /// </summary>
        /// <param name="user">XboxLiveUser that identifies the user to show the UI on behalf of.</param>
        /// <param name="privilege">The privilege to check.</param>
        /// <param name="friendlyMessage">Text to display in addition to the stock text about the privilege</param>
        /// <returns>
        /// An interface for tracking the progress of the asynchronous call.
        /// The operation completes when the UI is closed.
        /// A boolean which is true if the current user has the privilege.
        /// </returns>
        public static Task <bool> CheckGamingPrivilegeWithUI(XboxLiveUser user, GamingPrivilege privilege, string friendlyMessage)
        {
            var tcs = new TaskCompletionSource <bool>();

            Task.Run(() =>
            {
                var pFriendlyMessage = MarshalingHelpers.StringToHGlobalUtf8(friendlyMessage);
                int contextKey       = XboxLiveCallbackContext <TitleCallableUI, bool> .CreateContext(null, tcs, null, new List <IntPtr> {
                    pFriendlyMessage
                });

                XboxLive.Instance.Invoke <XsapiResult, TCUICheckGamingPrivilegeWithUI>(
                    privilege,
                    pFriendlyMessage,
                    (CheckGamingPrivilegeCompletionRoutine)CheckGamingPrivilegeWithUIComplete,
                    (IntPtr)contextKey,
                    XboxLive.DefaultTaskGroupId
                    );
            });

            return(tcs.Task);
        }