Example #1
0
        /// <summary>
        /// Downloads blob data from title storage.
        /// </summary>
        /// <param name="serviceConfigurationId">The service configuration ID (SCID) of the title</param>
        /// <param name="sandbox">The target sandbox id for title storage</param>
        /// <param name="pathAndFileName">Blob path and file name to store on XboxLive service.(example: "foo\bar\blob.txt")</param>
        /// <param name="blobType">Title storage blob type</param>
        /// <returns>The byte array contains downloaded blob data</returns>
        public static async Task <byte[]> DownloadGlobalStorageBlobAsync(string serviceConfigurationId, string sandbox, string pathAndFileName, TitleStorageBlobType blobType)
        {
            using (var request = new XboxLiveHttpRequest(true, serviceConfigurationId, sandbox))
            {
                HttpResponseMessage response = (await request.SendAsync(() =>
                {
                    var requestMsg = new HttpRequestMessage(HttpMethod.Get, new Uri(baseUri, $"/global/scids/{serviceConfigurationId}/data/{pathAndFileName},{blobType.ToString().ToLower()}"));
                    requestMsg.Headers.Add("x-xbl-contract-version", "1");

                    return(requestMsg);
                })).Response;
                response.EnsureSuccessStatusCode();

                Log.WriteLog($"DownloadGlobalStorageBlobAsync for scid: {serviceConfigurationId}, sandbox: {sandbox}");

                return(await response.Content.ReadAsByteArrayAsync());
            }
        }
Example #2
0
        /// <summary>
        /// Uploads blob data to title storage.
        /// </summary>
        /// <param name="serviceConfigurationId">The service configuration ID (SCID) of the title</param>
        /// <param name="sandbox">The target sandbox id for title storage</param>
        /// <param name="pathAndFileName">Blob path and file name to store on XboxLive service.(example: "foo\bar\blob.txt")</param>
        /// <param name="blobType">Title storage blob type</param>
        /// <param name="blobBytes">The byte array contains the blob data to upload.</param>
        public static async Task UploadGlobalStorageBlobAsync(string serviceConfigurationId, string sandbox, string pathAndFileName, TitleStorageBlobType blobType, byte[] blobBytes)
        {
            using (var request = new XboxLiveHttpRequest(true, serviceConfigurationId, sandbox))
            {
                var response = await request.SendAsync(() =>
                {
                    var requestMsg = new HttpRequestMessage(HttpMethod.Put, new Uri(baseUri, $"/global/scids/{serviceConfigurationId}/data/{pathAndFileName},{blobType.ToString().ToLower()}"));
                    requestMsg.Headers.Add("x-xbl-contract-version", "1");
                    requestMsg.Content = new ByteArrayContent(blobBytes);

                    return(requestMsg);
                });

                Log.WriteLog($"UploadGlobalStorageBlobAsync for scid: {serviceConfigurationId}, sandbox: {sandbox}");
            }
        }
        static public async Task DeleteGlobalStorageBlob(string serviceConfigurationId, string sandbox, string pathAndFileName, TitleStorageBlobType blobType)
        {
            using (var request = new XboxLiveHttpRequest())
            {
                var requestMsg = new HttpRequestMessage(HttpMethod.Delete, new Uri(baseUri, $"/global/scids/{serviceConfigurationId}/data/{pathAndFileName},{blobType.ToString().ToLower()}"));

                string eToken = await Auth.GetETokenSilentlyAsync(serviceConfigurationId, sandbox);

                AddRequestHeaders(ref requestMsg, eToken);

                var response = await request.SendAsync(requestMsg);

                Log.WriteLog($"DeleteGlobalStorageBlob for scid: {serviceConfigurationId}, sandbox: {sandbox}");
            }
        }