Ejemplo n.º 1
0
 private static extern XSAPI_RESULT TitleStorageCreateBlobMetadata(
     IntPtr serviceConfigurationId,
     TitleStorageType storageType,
     IntPtr blobPath,
     TitleStorageBlobType blobType,
     IntPtr xboxUserId,
     IntPtr displayName,
     IntPtr etag,
     IntPtr ppBlobMetadata);
        /// <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;
        }
        public async Task DeleteBlob()
        {
            SetUpMockAuth();
            SetupMockBytes();

            var uri = new Uri(new Uri(ClientSettings.Singleton.TitleStorageEndpoint), $"global/scids/{DefaultScid}/data/{DefaultGlobalStoragePath},{DefaultFileType}");

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Delete, uri.ToString())
            .Respond("application/json", "{}");

            TestHook.MockHttpHandler = mockHttp;

            TitleStorageBlobType fileType = (TitleStorageBlobType)Enum.Parse(typeof(TitleStorageBlobType), DefaultFileType, true);
            await TitleStorage.DeleteGlobalStorageBlob(DefaultScid, DefaultSandbox, DefaultGlobalStoragePath, fileType);
        }
        /// <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;
        }
Ejemplo n.º 5
0
        public async Task UploadBlob()
        {
            this.SetUpMockAuth();
            this.SetupMockBytes();

            var uri = new Uri(new Uri(ClientSettings.Singleton.TitleStorageEndpoint), $"global/scids/{DefaultScid}/data/{DefaultGlobalStoragePath},{DefaultFileType}");

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Put, uri.ToString())
            .WithHeaders("Authorization", this.ExpectedToken(DefaultScid, DefaultSandbox))
            .Respond("application/json", "{}");

            TestHook.MockHttpHandler = mockHttp;

            TitleStorageBlobType fileType = (TitleStorageBlobType)Enum.Parse(typeof(TitleStorageBlobType), DefaultFileType, true);
            await TitleStorage.UploadGlobalStorageBlobAsync(DefaultScid, DefaultSandbox, DefaultGlobalStoragePath, fileType, this.defaultBytes);
        }
        public async Task DownloadBlob()
        {
            SetUpMockAuth();
            SetupMockBytes();

            var uri = new Uri(new Uri(ClientSettings.Singleton.TitleStorageEndpoint), $"global/scids/{DefaultScid}/data/{DefaultGlobalStoragePath},{DefaultFileType}");

            var mockHttp = new MockHttpMessageHandler();

            Stream stream = new MemoryStream(this.defaultBytes);

            mockHttp.Expect(HttpMethod.Get, uri.ToString())
            .Respond("application/json", stream);

            TestHook.MockHttpHandler = mockHttp;

            TitleStorageBlobType fileType = (TitleStorageBlobType)Enum.Parse(typeof(TitleStorageBlobType), DefaultFileType, true);

            byte[] bytes = await TitleStorage.DownloadGlobalStorageBlob(DefaultScid, DefaultSandbox, DefaultGlobalStoragePath, fileType);

            Assert.AreEqual(bytes.Length, this.defaultBytes.Length);
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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>
        static public async Task <byte[]> DownloadGlobalStorageBlob(string serviceConfigurationId, string sandbox, string pathAndFileName, TitleStorageBlobType blobType)
        {
            using (var request = new XboxLiveHttpRequest())
            {
                var requestMsg = new HttpRequestMessage(HttpMethod.Get, 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($"DownloadGlobalStorageBlob for scid: {serviceConfigurationId}, sandbox: {sandbox}");

                return(await response.Content.ReadAsByteArrayAsync());
            }
        }
Ejemplo n.º 10
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}");
            }
        }
Ejemplo n.º 11
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());
            }
        }
 public static TitleStorageBlobMetadata CreateTitleStorageBlobMetadataForSessionStorage(string serviceConfigurationId, string blobPath, TitleStorageBlobType blobType, string multiplayerSessionTemplateName, string multiplayerSessionName, string displayName, string eTag)
 {
     throw new NotImplementedException();
 }
 public TitleStorageBlobMetadata(string serviceConfigurationId, TitleStorageType storageType, string blobPath, TitleStorageBlobType blobType, string xboxUserId)
 {
 }
 public TitleStorageBlobMetadata(string serviceConfigurationId, TitleStorageType storageType, string blobPath, TitleStorageBlobType blobType, string xboxUserId, string displayName, string eTag, DateTimeOffset clientTimestamp)
 {
     var _clientTimestamp = clientTimestamp.ToUniversalTime().ToFileTime();
 }