コード例 #1
0
        internal string GetTitleStorageSubpath(XboxLiveUser user, TitleStorageType titleStorageType)
        {
            var pathBuilder = new StringBuilder();

            switch (titleStorageType)
            {
            case TitleStorageType.TrustedPlatform:
            case TitleStorageType.UniversalPlatform:
                pathBuilder.AppendFormat(
                    "{0}/users/xuid({1})/scids/{2}",
                    titleStorageType.ToString().ToLowerInvariant(),
                    user.XboxUserId,
                    XboxLive.Instance.AppConfig.PrimaryServiceConfigId);
                break;

            case TitleStorageType.GlobalStorage:
                pathBuilder.AppendFormat(
                    "global/scids/{0}",
                    XboxLive.Instance.AppConfig.PrimaryServiceConfigId);
                break;

            default:
                throw new ArgumentOutOfRangeException("titleStorageType");
            }

            return(pathBuilder.ToString());
        }
コード例 #2
0
 private static extern XSAPI_RESULT TitleStorageGetQuota(
     IntPtr xboxLiveContext,
     IntPtr serviceConfigurationId,
     TitleStorageType storageType,
     XSAPI_GET_QUOTA_COMPLETION_ROUTINE completionRoutine,
     IntPtr completionRoutineContext,
     Int64 taskGroupId);
コード例 #3
0
 private static extern XSAPI_RESULT TitleStorageCreateBlobMetadata(
     IntPtr serviceConfigurationId,
     TitleStorageType storageType,
     IntPtr blobPath,
     TitleStorageBlobType blobType,
     IntPtr xboxUserId,
     IntPtr displayName,
     IntPtr etag,
     IntPtr ppBlobMetadata);
コード例 #4
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(XboxLiveUser user, TitleStorageType storageType)
        {
            var subQuery    = this.GetTitleStorageSubpath(user, storageType);
            var httpRequest = XboxLiveHttpRequest.Create(HttpMethod.Get, TitleStorageBaseUri.ToString(), subQuery);

            httpRequest.ContractVersion = TitleStorageApiContract;

            return(httpRequest.GetResponseWithAuth(user).ContinueWith(
                       responseTask => this.HandleStorageQuoteResponse(responseTask, storageType)));
        }
コード例 #5
0
        internal TitleStorageQuota HandleStorageQuoteResponse(
            Task <XboxLiveHttpResponse> responseTask,
            TitleStorageType storageType)
        {
            var response = responseTask.Result;

            return(TitleStorageQuota.Deserialize(
                       response.ResponseBodyString,
                       storageType));
        }
コード例 #6
0
 private static extern XSAPI_RESULT TitleStorageGetBlobMetadata(
     IntPtr xboxLiveContext,
     IntPtr serviceConfigurationId,
     TitleStorageType storageType,
     IntPtr blobPath,
     IntPtr xboxUserId,
     UInt32 skipItems,
     UInt32 maxItems,
     XSAPI_GET_BLOB_METADATA_COMPLETION_ROUTINE completionRoutine,
     IntPtr completionRoutineContext,
     Int64 taskGroupId);
コード例 #7
0
 /// <summary>
 /// Deserializes the Title Storage Quota from JSON
 /// </summary>
 /// <param name="json">The JSON String to be deserialized</param>
 /// <param name="storageType">The Title Storage Type</param>
 /// <returns>Title storage quota with the amount of storage space allocated and used.</returns>
 public static TitleStorageQuota Deserialize(
     string json,
     TitleStorageType storageType)
 {
     if (!string.IsNullOrEmpty(json))
     {
         var quotaInfoResult = JsonSerialization.FromJson <QuotaInfoResult>(json);
         var quotaInfo       = quotaInfoResult.QuotaInfo;
         quotaInfo.StorageType = storageType;
         return(quotaInfo);
     }
     return(null);
 }
コード例 #8
0
        internal TitleStorageBlobMetadataResult HandleBlobMetadataResult(
            XboxLiveUser user,
            Task <XboxLiveHttpResponse> responseTask,
            TitleStorageType storageType,
            string blobPath)
        {
            var response = responseTask.Result;

            return(TitleStorageBlobMetadataResult.Deserialize(
                       response.ResponseBodyString,
                       storageType,
                       user,
                       blobPath));
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TitleStorageBlobMetadata"/> class.
        /// </summary>
        /// <param name="storageType">Type of storage.</param>
        /// <param name="blobPath">Blob path is a unique string that conforms to a SubPath\file format (example: "foo\bar\blob.txt").</param>
        /// <param name="blobType">Type of blob data. Possible values are: Binary, Json, and Config.</param>
        public TitleStorageBlobMetadata(
            TitleStorageType storageType,
            string blobPath,
            TitleStorageBlobType blobType)
        {
            if (string.IsNullOrEmpty(blobPath))
            {
                throw new ArgumentNullException("blobPath");
            }

            this.StorageType = storageType;
            this.BlobType    = blobType;
            this.BlobPath    = blobPath;
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TitleStorageBlobMetadata"/> class.
        /// </summary>
        /// <param name="serviceConfigurationId">The service configuration ID (SCID) of the title</param>
        /// <param name="storageType">Type of storage.</param>
        /// <param name="blobPath">Blob path is a unique string that conforms to a SubPath\file format (example: "foo\bar\blob.txt").</param>
        /// <param name="blobType">Type of blob data. Possible values are: Binary, Json, and Config.</param>
        /// <param name="xboxUserId">The Xbox User ID of the title storage to enumerate. Ignored when dealing with GlobalStorage, so passing nullptr is acceptable in that case. (Optional)</param>
        public TitleStorageBlobMetadata(string serviceConfigurationId, TitleStorageType storageType, string blobPath, TitleStorageBlobType blobType, string xboxUserId)
        {
            if (string.IsNullOrEmpty(blobPath))
            {
                throw new ArgumentNullException("blobPath");
            }

            this.ServiceConfigurationId = serviceConfigurationId;
            this.StorageType            = storageType;
            this.BlobType   = blobType;
            this.BlobPath   = blobPath;
            this.XboxUserId = xboxUserId;

            CreateCMetadata();
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TitleStorageBlobMetadata"/> class.
        /// </summary>
        /// <param name="storageType">Type of storage.</param>
        /// <param name="blobPath">Blob path is a unique string that conforms to a SubPath\file format (example: "foo\bar\blob.txt").</param>
        /// <param name="blobType">Type of blob data. Possible values are: Binary, Json, and Config.</param>
        /// <param name="displayName">[optional] Friendly display name to show in app UI.</param>
        /// <param name="eTag">ETag for the file used in read and write requests.</param>
        public TitleStorageBlobMetadata(
            TitleStorageType storageType,
            string blobPath,
            TitleStorageBlobType blobType,
            string displayName,
            string eTag)
        {
            if (string.IsNullOrEmpty(blobPath))
            {
                throw new ArgumentNullException("blobPath");
            }

            this.StorageType = storageType;
            this.BlobType    = blobType;
            this.BlobPath    = blobPath;
            this.DisplayName = displayName;
            this.ETag        = eTag;
        }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TitleStorageBlobMetadata"/> class.
        /// </summary>
        /// <param name="serviceConfigurationId">The service configuration ID (SCID) of the title</param>
        /// <param name="storageType">Type of storage.</param>
        /// <param name="blobPath">Blob path is a unique string that conforms to a SubPath\file format (example: "foo\bar\blob.txt").</param>
        /// <param name="blobType">Type of blob data. Possible values are: Binary, Json, and Config.</param>
        /// <param name="xboxUserId">The Xbox User ID of the title storage to enumerate. Ignored when dealing with GlobalStorage, so passing nullptr is acceptable in that case. (Optional)</param>
        /// <param name="displayName">[optional] Friendly display name to show in app UI.</param>
        /// <param name="eTag">ETag for the file used in read and write requests.</param>
        /// <param name="length">Length of the content of the blob</param>
        public TitleStorageBlobMetadata(string serviceConfigurationId, TitleStorageType storageType, string blobPath, TitleStorageBlobType blobType, string xboxUserId, string displayName, string eTag, ulong length)
        {
            if (string.IsNullOrEmpty(blobPath))
            {
                throw new ArgumentNullException("blobPath");
            }

            this.ServiceConfigurationId = serviceConfigurationId;
            this.StorageType            = storageType;
            this.BlobType    = blobType;
            this.BlobPath    = blobPath;
            this.DisplayName = displayName;
            this.ETag        = eTag;
            this.Length      = length;
            this.XboxUserId  = xboxUserId;

            CreateCMetadata();
        }
コード例 #13
0
        /// <summary>
        /// Deserializes the TitleStorageBlobMetadataResult from JSON
        /// </summary>
        /// <param name="json">JSON string</param>
        /// <param name="storageType">Type of title storage </param>
        /// <param name="xboxUser">The Xbox User of the player the files belongs to.</param>
        /// <param name="blobPath">The full path to to the blob.  examples: "gameconfig.json" and "user/settings/playerconfiguration.json".</param>
        /// <returns></returns>
        public static TitleStorageBlobMetadataResult Deserialize(
            string json,
            TitleStorageType storageType,
            XboxLiveUser xboxUser,
            string blobPath
            )
        {
            var titleStorageBlobMetadataResultInfo = JsonSerialization.FromJson <TitleStorageBlobMetadataResultInfo>(json);

            TitleStorageBlobMetadataResult.User = xboxUser;
            var titleMetadataResult = new TitleStorageBlobMetadataResult
            {
                Items       = new List <TitleStorageBlobMetadata>(),
                storageType = storageType,
                blobPath    = blobPath
            };

            foreach (var blob in titleStorageBlobMetadataResultInfo.Blobs)
            {
                var blobFileName = blob.BlobPath;

                // Since the blobPath returned from the service contains the type of the blob
                // such as (foo\bar\blob.txt,json)
                // It needs to be split out so the blobPath is only the first part and the
                // blob type is JSON.
                var nameParts = blobFileName.Split(',');
                blobFileName = nameParts[0];
                var blobFileType = (TitleStorageBlobType)Enum.Parse(typeof(TitleStorageBlobType), nameParts[1], true);

                var newTitleStorageBlobMetadata = new TitleStorageBlobMetadata(storageType, blobFileName, blobFileType, blob.DisplayName, blob.ETag);
                titleMetadataResult.Items.Add(newTitleStorageBlobMetadata);
            }

            if (titleStorageBlobMetadataResultInfo.PagingInfo != null)
            {
                titleMetadataResult.continuationToken = titleStorageBlobMetadataResultInfo.PagingInfo.ContinuationToken;
            }

            return(titleMetadataResult);
        }
コード例 #14
0
        internal Task <TitleStorageBlobMetadataResult> InternalGetBlobMetadata(
            XboxLiveUser user,
            TitleStorageType storageType,
            string blobPath,
            uint skipItems,
            uint maxItems,
            string continuationToken = "")
        {
            string subPathAndQueryResult = this.GetTitleStorageBlobMetadataSubpath(
                user,
                storageType,
                blobPath,
                skipItems,
                maxItems,
                continuationToken);

            var httpRequest = XboxLiveHttpRequest.Create(HttpMethod.Get, TitleStorageBaseUri.ToString(), subPathAndQueryResult);

            httpRequest.ContractVersion = TitleStorageApiContract;
            return(httpRequest.GetResponseWithAuth(user)
                   .ContinueWith(
                       responseTask => this.HandleBlobMetadataResult(user, responseTask, storageType, blobPath)));
        }
コード例 #15
0
        internal string GetTitleStorageBlobMetadataSubpath(
            XboxLiveUser user,
            TitleStorageType storageType,
            string blobPath,
            uint skipItems,
            uint maxItems,
            string continuationToken)
        {
            var subPathBuilder = new StringBuilder();
            var path           = this.GetTitleStorageSubpath(user, storageType);

            subPathBuilder.Append(path);

            subPathBuilder.Append("/data");
            if (!string.IsNullOrEmpty(blobPath))
            {
                subPathBuilder.Append("/");
                subPathBuilder.Append(Uri.EscapeUriString(blobPath));
            }

            AppendPagingInfo(subPathBuilder, skipItems, maxItems, continuationToken);

            return(subPathBuilder.ToString());
        }
コード例 #16
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);
        }
コード例 #17
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="user">The Xbox User of the title storage to enumerate. Ignored when enumerating GlobalStorage.</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="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(XboxLiveUser user, TitleStorageType storageType, string blobPath, uint skipItems = 0, uint maxItems = 0)
        {
            if (storageType == TitleStorageType.GlobalStorage && (user == null || !string.IsNullOrEmpty(user.XboxUserId)))
            {
                throw new Exception("Global Storage Type with a non-empty xbox user id");
            }

            return(this.InternalGetBlobMetadata(user, storageType, blobPath, skipItems, maxItems));
        }
コード例 #18
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);
        }
コード例 #19
0
 public TitleStorageBlobMetadata(string serviceConfigurationId, TitleStorageType storageType, string blobPath, TitleStorageBlobType blobType, string xboxUserId, string displayName, string eTag, DateTimeOffset clientTimestamp)
 {
     var _clientTimestamp = clientTimestamp.ToUniversalTime().ToFileTime();
 }
コード例 #20
0
 /// <summary>
 /// Initialze a TitleStorageQuota from the corresponding C object
 /// </summary>
 internal TitleStorageQuota(XSAPI_TITLE_STORAGE_QUOTA quotaStruct)
 {
     QuotaBytes  = quotaStruct.QuotaBytes;
     UsedBytes   = quotaStruct.UsedBytes;
     StorageType = quotaStruct.storageType;
 }
コード例 #21
0
 public TitleStorageBlobMetadata(string serviceConfigurationId, TitleStorageType storageType, string blobPath, TitleStorageBlobType blobType, string xboxUserId)
 {
 }
コード例 #22
0
 public Task <TitleStorageQuota> GetQuotaAsync(string serviceConfigurationId, TitleStorageType storageType)
 {
     throw new NotImplementedException();
 }
コード例 #23
0
 public Task <TitleStorageBlobMetadataResult> GetBlobMetadataAsync(string serviceConfigurationId, TitleStorageType storageType, string blobPath, string xboxUserId, uint skipItems, uint maxItems)
 {
     throw new NotImplementedException();
 }