private static void GetTokenAndSignatureComplete(TokenAndSignatureResult_c result, IntPtr context) { int contextKey = context.ToInt32(); XboxLiveCallbackContext <UserImpl, TokenAndSignatureResult> contextObject; if (XboxLiveCallbackContext <UserImpl, TokenAndSignatureResult> .TryRemove(contextKey, out contextObject)) { if (result.result.errorCode == 0) { contextObject.TaskCompletionSource.SetResult(new TokenAndSignatureResult { WebAccountId = result.payload.WebAccountId, Privileges = result.payload.Privileges, AgeGroup = result.payload.AgeGroup, Gamertag = result.payload.Gamertag, XboxUserId = result.payload.XboxUserId, Signature = result.payload.Signature, Token = result.payload.Token //TokenRequestResultStatus = tokenResult.ResponseStatus }); } else { contextObject.TaskCompletionSource.SetException(new Exception(result.result.errorMessage)); } contextObject.Dispose(); } }
private static void CheckGamingPrivilegeWithUIComplete(CheckGamingPrivilegeResult result, IntPtr completionRoutineContext) { int contextKey = completionRoutineContext.ToInt32(); XboxLiveCallbackContext <TitleCallableUI, bool> context; if (XboxLiveCallbackContext <TitleCallableUI, bool> .TryRemove(contextKey, out context)) { context.TaskCompletionSource.SetResult(result.hasPrivilege); context.Dispose(); } }
private static void ShowProfileCardUIComplete(XboxLiveResult result, IntPtr completionRoutineContext) { int contextKey = completionRoutineContext.ToInt32(); XboxLiveCallbackContext <TitleCallableUI, bool> context; if (XboxLiveCallbackContext <TitleCallableUI, bool> .TryRemove(contextKey, out context)) { context.TaskCompletionSource.SetResult(true); context.Dispose(); } }
public static bool TryRemove(int contextKey, out XboxLiveCallbackContext <T, T2> context) { IDisposable genericContext; if (s_contextsMap.TryRemove(contextKey, out genericContext)) { context = genericContext as XboxLiveCallbackContext <T, T2>; return(context != null); } else { context = null; return(false); } }
public static int CreateContext(T context, TaskCompletionSource <T2> taskCompletionSource, List <IntPtr> pointersToRelease = null, List <IntPtr> pointersToFree = null) { var xboxLiveCallbackContext = new XboxLiveCallbackContext <T, T2> { Context = context, TaskCompletionSource = taskCompletionSource, PointersToRelease = pointersToRelease, PointersToFree = pointersToFree }; int contextKey = Interlocked.Increment(ref s_contextKey); s_contextsMap.TryAdd(contextKey, xboxLiveCallbackContext); return(contextKey); }
/// <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); }
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); }
/// <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); }
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); }
/// <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); }
private static void SignInComplete(SignInResult_c result, IntPtr context) { int contextKey = context.ToInt32(); XboxLiveCallbackContext <UserImpl, SignInResult> contextObject; if (XboxLiveCallbackContext <UserImpl, SignInResult> .TryRemove(contextKey, out contextObject)) { UserImpl @this = contextObject.Context; if (result.result.errorCode == 0) { @this.UpdatePropertiesFromXboxLiveUser_c(); @this.SignInCompleted(@this, new EventArgs()); contextObject.TaskCompletionSource.SetResult(new SignInResult(result.payload.status)); } else { contextObject.TaskCompletionSource.SetException(new Exception(result.result.errorMessage)); } contextObject.Dispose(); } }