Beispiel #1
0
        /// <summary>
        /// Gets a list of blob metadata objects under a given path for the specified service configuration, storage type and storage ID.
        /// </summary>
        /// <param name="serviceConfigurationId">The service configuration ID (SCID) of the title</param>
        /// <param name="storageType">The storage type to get blob metadata objects for.</param>
        /// <param name="blobPath">(Optional) The root path to enumerate.  Results will be for blobs contained in this path and all subpaths.</param>
        /// <param name="xboxUserId">The Xbox User ID of the title storage to enumerate. Pass nullptr when searching for GlobalStorage type data. (Optional)</param>
        /// <param name="skipItems">(Optional) The number of items to skip before returning results. (Optional)</param>
        /// <param name="maxItems">(Optional) The maximum number of items to return.</param>
        /// <returns>An instance of the <see cref="TitleStorageBlobMetadataResult"/> class containing the list of enumerated blob metadata objects.</returns>
        public Task <TitleStorageBlobMetadataResult> GetBlobMetadataAsync(string serviceConfigurationId, TitleStorageType storageType, string blobPath, string xboxUserId, uint skipItems = 0, uint maxItems = 0)
        {
            var tcs = new TaskCompletionSource <TitleStorageBlobMetadataResult>();

            Task.Run(() =>
            {
                var scid        = MarshalingHelpers.StringToHGlobalUtf8(serviceConfigurationId);
                var blobPathPtr = MarshalingHelpers.StringToHGlobalUtf8(blobPath);
                var xuidPtr     = MarshalingHelpers.StringToHGlobalUtf8(xboxUserId);

                int contextKey;
                var context            = XsapiCallbackContext <object, TitleStorageBlobMetadataResult> .CreateContext(null, tcs, out contextKey);
                context.PointersToFree = new List <IntPtr> {
                    scid, blobPathPtr, xuidPtr
                };

                var xsapiResult = TitleStorageGetBlobMetadata(
                    this.pCXboxLiveContext, scid, storageType, blobPathPtr, xuidPtr, skipItems, maxItems,
                    GetBlobMetadataComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId);

                if (xsapiResult != XSAPI_RESULT.XSAPI_RESULT_OK)
                {
                    tcs.SetException(new XboxException(xsapiResult));
                }
            });
            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;
                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);
        }
Beispiel #3
0
        public StatisticValue GetStatistic(XboxLiveUser user, string statName)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // Allocates memory for returned objects
            IntPtr cStatValue;
            IntPtr cErrMessage;
            IntPtr cStatName = MarshalingHelpers.StringToHGlobalUtf8(statName);

            // Invokes the c method
            XSAPI_RESULT errCode = StatsManagerGetStat(user.Impl.XboxLiveUserPtr, cStatName, out cStatValue, out cErrMessage);

            Marshal.FreeHGlobal(cStatName);
            if (errCode != XSAPI_RESULT.XSAPI_RESULT_OK)
            {
                throw new XboxException(errCode, cErrMessage);
            }

            // Does local work
            StatisticValue statValue = new StatisticValue(cStatValue);

            return(statValue);
        }
Beispiel #4
0
        public Task <PermissionCheckResult> CheckPermissionWithTargetUserAsync(string permissionId, string targetXboxUserId)
        {
            var tcs = new TaskCompletionSource <PermissionCheckResult>();

            Task.Run(() =>
            {
                var permissionIdPtr = MarshalingHelpers.StringToHGlobalUtf8(permissionId);
                var xuidPtr         = MarshalingHelpers.StringToHGlobalUtf8(targetXboxUserId);

                int contextKey;
                var context            = XsapiCallbackContext <object, PermissionCheckResult> .CreateContext(null, tcs, out contextKey);
                context.PointersToFree = new List <IntPtr> {
                    permissionIdPtr, xuidPtr
                };

                var xsapiResult = PrivacyCheckPermissionWithTargetUser(
                    this.pCXboxLiveContext, permissionIdPtr, xuidPtr, CheckPermissionWithTargetUserComplete,
                    (IntPtr)contextKey, XboxLive.DefaultTaskGroupId);

                if (xsapiResult != XSAPI_RESULT.XSAPI_RESULT_OK)
                {
                    tcs.SetException(new XboxException(xsapiResult));
                }
            });
            return(tcs.Task);
        }
Beispiel #5
0
        /// <summary>
        /// Downloads blob data from title storage.
        /// </summary>
        /// <param name="blobMetadata">The blob metadata for the title storage blob to download.</param>
        /// <param name="etagMatchCondition">The ETag match condition used to determine if the blob should be downloaded.</param>
        /// <param name="selectQuery">A query string that contains a ConfigStorage filter string or JSONStorage json property name string to filter. (Optional)</param>
        /// <param name="preferredDownloadBlockSize">The preferred download block size in bytes for binary blobs. </param>
        /// <returns>An instance of the <see cref="TitleStorageBlobResult"/> containing the blob content and an updated
        /// <see cref="TitleStorageBlobMetadata"/> object.</returns>
        public Task <TitleStorageBlobResult> DownloadBlobAsync(TitleStorageBlobMetadata blobMetadata, TitleStorageETagMatchCondition etagMatchCondition, string selectQuery, uint preferredDownloadBlockSize)
        {
            var tcs = new TaskCompletionSource <TitleStorageBlobResult>();

            Task.Run(() =>
            {
                int contextKey;
                var context = XsapiCallbackContext <TitleStorageBlobMetadata, TitleStorageBlobResult> .CreateContext(blobMetadata, tcs, out contextKey);

                var buffer = Marshal.AllocHGlobal((int)blobMetadata.Length);
                var select = MarshalingHelpers.StringToHGlobalUtf8(selectQuery);
                var pPreferredDownloadBlockSize = GCHandle.Alloc(preferredDownloadBlockSize, GCHandleType.Pinned);

                context.PointersToFree = new List <IntPtr> {
                    buffer, select
                };
                context.GCHandlesToFree = new List <GCHandle> {
                    pPreferredDownloadBlockSize
                };

                var xsapiResult = TitleStorageDownloadBlob(
                    this.pCXboxLiveContext, blobMetadata.metadataPtr, buffer, (UInt32)blobMetadata.Length, etagMatchCondition, select, GCHandle.ToIntPtr(pPreferredDownloadBlockSize),
                    DownloadBlobComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId);

                if (xsapiResult != XSAPI_RESULT.XSAPI_RESULT_OK)
                {
                    tcs.SetException(new XboxException(xsapiResult));
                }
            });
            return(tcs.Task);
        }
        private void CreateCMetadata()
        {
            var scid        = MarshalingHelpers.StringToHGlobalUtf8(this.ServiceConfigurationId);
            var path        = MarshalingHelpers.StringToHGlobalUtf8(this.BlobPath);
            var xuid        = MarshalingHelpers.StringToHGlobalUtf8(this.XboxUserId);
            var displayName = MarshalingHelpers.StringToHGlobalUtf8(this.DisplayName);
            var etag        = MarshalingHelpers.StringToHGlobalUtf8(this.ETag);

            IntPtr clientTimePtr = IntPtr.Zero;

            if (this.ClientTimeStamp != null)
            {
                var clientTime = this.ClientTimeStamp.ToUnixTimeSeconds();
                clientTimePtr = Marshal.AllocHGlobal(MarshalingHelpers.SizeOf <UInt64>());
                Marshal.WriteInt64(clientTimePtr, clientTime);
            }

            TitleStorageCreateBlobMetadata(scid, StorageType, path, BlobType, xuid, displayName, etag, clientTimePtr, out metadataPtr);

            Marshal.FreeHGlobal(scid);
            Marshal.FreeHGlobal(path);
            Marshal.FreeHGlobal(xuid);
            Marshal.FreeHGlobal(displayName);
            Marshal.FreeHGlobal(etag);
            Marshal.FreeHGlobal(clientTimePtr);
        }
Beispiel #7
0
        private void CreateCMetadata()
        {
            var scid        = MarshalingHelpers.StringToHGlobalUtf8(this.ServiceConfigurationId);
            var path        = MarshalingHelpers.StringToHGlobalUtf8(this.BlobPath);
            var xuid        = MarshalingHelpers.StringToHGlobalUtf8(this.XboxUserId);
            var displayName = MarshalingHelpers.StringToHGlobalUtf8(this.DisplayName);
            var etag        = MarshalingHelpers.StringToHGlobalUtf8(this.ETag);

            TitleStorageCreateBlobMetadata(scid, StorageType, path, BlobType, xuid, displayName, etag, IntPtr.Zero, /*TODO client timestamp*/ out metadataPtr);

            Marshal.FreeHGlobal(scid);
            Marshal.FreeHGlobal(path);
            Marshal.FreeHGlobal(xuid);
            Marshal.FreeHGlobal(displayName);
            Marshal.FreeHGlobal(etag);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
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);
        }
        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);
        }
Beispiel #11
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);
        }
        /// <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);
        }
Beispiel #13
0
        /// <summary>
        /// Gets title storage quota information for the specified service configuration and storage type.
        /// For user storage types (TrustedPlatform and Json) the request will be made for the calling user's
        /// Xbox user Id.
        /// </summary>
        /// <param name="user">The Xbox User of the title storage to enumerate. Ignored when enumerating GlobalStorage.</param>
        /// <param name="storageType">Type of the storage type</param>
        /// <returns>An instance of the <see cref="TitleStorageQuota"/> class with the amount of storage space allocated and used.</returns>
        public Task <TitleStorageQuota> GetQuotaAsync(string serviceConfigurationId, TitleStorageType storageType)
        {
            var tcs = new TaskCompletionSource <TitleStorageQuota>();

            Task.Run(() =>
            {
                var scid = MarshalingHelpers.StringToHGlobalUtf8(XboxLive.Instance.AppConfig.ServiceConfigurationId);

                int contextKey;
                var context            = XsapiCallbackContext <object, TitleStorageQuota> .CreateContext(null, tcs, out contextKey);
                context.PointersToFree = new List <IntPtr> {
                    scid
                };

                var xsapiResult = TitleStorageGetQuota(
                    this.pCXboxLiveContext, scid, storageType, GetQuotaComplete, (IntPtr)contextKey, XboxLive.DefaultTaskGroupId);

                if (xsapiResult != XSAPI_RESULT.XSAPI_RESULT_OK)
                {
                    tcs.SetException(new XboxException(xsapiResult));
                }
            });
            return(tcs.Task);
        }