internal static async Task GetGlobalStorageBlobMetaDataAsync()

in Microsoft.Xbox.Service.DevTools/TitleStorage/TitleStorage.cs [144:212]


        internal static async Task<TitleStorageBlobMetadataResult> GetGlobalStorageBlobMetaDataAsync(string serviceConfigurationId, string sandbox, string path, uint maxItems,
            uint skipItems, string continuationToken)
        {
            using (var request = new XboxLiveHttpRequest(true, serviceConfigurationId, sandbox))
            {
                var uriBuilder = new UriBuilder(baseUri)
                { 
                    Path = $"/global/scids/{serviceConfigurationId}/data/{path}"
                };

                AppendPagingInfo(ref uriBuilder, maxItems, skipItems, continuationToken);

                HttpResponseMessage response = (await request.SendAsync(()=>
                {
                    var requestMsg = new HttpRequestMessage(HttpMethod.Get, uriBuilder.Uri);
                    requestMsg.Headers.Add("x-xbl-contract-version", "1");

                    return requestMsg;
                })).Response;

                // Return empty list on 404
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    return new TitleStorageBlobMetadataResult();
                }

                response.EnsureSuccessStatusCode();

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

                string stringContent = await response.Content.ReadAsStringAsync();
                JObject storageMetadata = JObject.Parse(stringContent);
                var result = new TitleStorageBlobMetadataResult
                {
                    TotalItems = storageMetadata["pagingInfo"]["totalItems"].Value<uint>(),
                    ContinuationToken = storageMetadata["pagingInfo"]["continuationToken"].Value<string>(),
                    ServiceConfigurationId = serviceConfigurationId,
                    Sandbox = sandbox,
                    Path = path
                };

                var array = (JArray)storageMetadata["blobs"];
                var metadataArray = array.Select((o) =>
                {
                    string fileName = o["fileName"].Value<string>();
                    ulong size = o["size"].Value<ulong>();
                    var filePathAndTypeArray = fileName.Split(',');
                    if (filePathAndTypeArray.Length != 2)
                    {
                        throw new FormatException("Invalid file name format in TitleStorageBlobMetadata response");
                    }
                    if (!Enum.TryParse(filePathAndTypeArray[1], true, out TitleStorageBlobType type))
                    {
                        throw new FormatException("Invalid file type in TitleStorageBlobMetadata response");
                    }

                    return new TitleStorageBlobMetadata
                    {
                        Path = filePathAndTypeArray[0],
                        Size = size,
                        Type = type
                    };
                }).ToArray();

                result.Items = metadataArray;

                return result;
            }
        }