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

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

                var requestMsg = new HttpRequestMessage(HttpMethod.Get, uriBuilder.Uri);

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

                AddRequestHeaders(ref requestMsg, eToken);

                XboxLiveHttpContent response;
                try
                {
                    response = await request.SendAsync(requestMsg);
                }
                catch (XboxLiveException ex)
                {
                    // Return empty list on 404
                    if (ex.ErrorStatus == XboxLiveErrorStatus.NotFound)
                    {
                        return(new TitleStorageBlobMetadataResult());
                    }
                    else
                    {
                        throw ex;
                    }
                }


                Log.WriteLog($"GetGlobalStorageBlobMetaData 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>();
                    UInt64 size              = o["size"].Value <UInt64>();
                    var filePathAndTypeArray = fileName.Split(',');
                    if (filePathAndTypeArray.Length != 2)
                    {
                        throw new XboxLiveException("Invalid file name format in TitleStorageBlobMetadata response");
                    }
                    TitleStorageBlobType type;
                    if (!Enum.TryParse(filePathAndTypeArray[1], true, out type))
                    {
                        throw new XboxLiveException("Invalid file type in TitleStorageBlobMetadata response");
                    }

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

                result.Items = metadataArray;

                return(result);
            }
        }