/// <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; var context = XsapiCallbackContext <object, bool> .CreateContext(null, tcs, out contextKey); context.PointersToFree = new List <IntPtr> { pFriendlyMessage }; var result = TCUICheckGamingPrivilegeWithUI(privilege, pFriendlyMessage, CheckGamingPrivilegeComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId); if (result != XSAPI_RESULT.XSAPI_RESULT_OK) { tcs.SetException(new XboxException(result)); } }); return(tcs.Task); }
/// <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 = XsapiCallbackContext <object, bool> .CreateContext(null, tcs); var result = TCUICheckGamingPrivilegeSilently(privilege, CheckGamingPrivilegeComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId); if (result != XSAPI_RESULT.XSAPI_RESULT_OK) { tcs.SetException(new XboxException(result)); } }); tcs.Task.Wait(); return(tcs.Task.Result); }
public Task <GetTokenAndSignatureResult> InternalGetTokenAndSignatureAsync(string httpMethod, string url, string headers, byte[] body, bool promptForCredentialsIfNeeded, bool forceRefresh) { var tcs = new TaskCompletionSource <GetTokenAndSignatureResult>(); 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; var context = XsapiCallbackContext <UserImpl, GetTokenAndSignatureResult> .CreateContext(this, tcs, out contextKey); context.PointersToFree = new List <IntPtr> { pHttpMethod, pUrl, pHeaders, pBody }; var result = XboxLiveUserGetTokenAndSignature( XboxLiveUserPtr, pHttpMethod, pUrl, pHeaders, pBody, GetTokenAndSignatureComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId); if (result != XSAPI_RESULT.XSAPI_RESULT_OK) { throw new XboxException(result); } }); return(tcs.Task); }
public Task <SignInResult> SignInImpl(bool showUI, bool forceRefresh) { var tcs = new TaskCompletionSource <SignInResult>(); Task.Run(() => { int contextKey; var context = XsapiCallbackContext <UserImpl, SignInResult> .CreateContext(this, tcs, out contextKey); XSAPI_RESULT result = XSAPI_RESULT.XSAPI_RESULT_OK; if (showUI) { var coreDispatcherPtr = Marshal.GetIUnknownForObject(Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher); context.PointersToRelease = new List <IntPtr> { coreDispatcherPtr }; result = XboxLiveUserSignInWithCoreDispatcher( XboxLiveUserPtr, coreDispatcherPtr, SignInComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId); } else { result = XboxLiveUserSignInSilently( XboxLiveUserPtr, SignInComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId); } if (result != XSAPI_RESULT.XSAPI_RESULT_OK) { throw new XboxException(result); } }); return(tcs.Task); }
/// <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 <object>(); Task.Run(() => { var pTargetXboxUserId = MarshalingHelpers.StringToHGlobalUtf8(targetXboxUserId); int contextKey; var context = XsapiCallbackContext <object, object> .CreateContext(null, tcs, out contextKey); context.PointersToFree = new List <IntPtr> { pTargetXboxUserId }; var result = TCUIShowProfileCardUI(pTargetXboxUserId, ShowProfileCardUIComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId); if (result != XSAPI_RESULT.XSAPI_RESULT_OK) { tcs.SetException(new XboxException(result)); } }); return(tcs.Task); }