private static async Task <JobStatusResponse> CheckJobStatus(JobSubmitResponse job)
        {
            using (var submitRequest = new XboxLiveHttpRequest())
            {
                var requestMsg = new HttpRequestMessage(HttpMethod.Get, new Uri(baseUri, "jobs/" + job.JobId));
                if (!string.IsNullOrEmpty(job.CorrelationId))
                {
                    requestMsg.Headers.Add("X-XblCorrelationId", job.CorrelationId);
                }

                string eToken = await Auth.GetETokenSilentlyAsync(string.Empty, string.Empty);

                AddRequestHeaders(ref requestMsg, eToken);

                var response = await submitRequest.SendAsync(requestMsg);

                string responseConent = await response.Content.ReadAsStringAsync();

                var jobstatus = JsonConvert.DeserializeObject <JobStatusResponse>(responseConent);

                Log.WriteLog($"Checking {job.JobId} job stauts: {jobstatus.Status}");

                return(jobstatus);
            }
        }
        private static async Task <JobSubmitResponse> SubmitJobAsync(string sandbox, string scid, string xuid)
        {
            var job = new JobSubmitResponse();

            using (var submitRequest = new XboxLiveHttpRequest())
            {
                var requestMsg = new HttpRequestMessage(HttpMethod.Post, new Uri(baseUri, "submitJob"));

                var requestContent = JsonConvert.SerializeObject(new JobSubmitReqeust(scid, xuid));
                requestMsg.Content = new StringContent(requestContent);

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

                AddRequestHeaders(ref requestMsg, eToken);

                var responseContent = await submitRequest.SendAsync(requestMsg);

                // remove "" if found one.
                job.JobId         = responseContent.Content.Trim(new char[] { '\\', '\"' });
                job.CorrelationId = responseContent.CollrelationId;

                Log.WriteLog($"Submitting delete job for scid:{scid}, user:{xuid}, sandbox:{sandbox} succeeded. Jobid: {job.JobId}");
            }

            return(job);
        }
        /// <summary>
        /// Reset one player's data in test sandboxes, includes: achievements, leaderboards, player stats and title history.
        /// </summary>
        /// <param name="serviceConfigurationId">The service configuration ID (SCID) of the title for player data resetting</param>
        /// <param name="sandbox">The target sandbox id for player resetting</param>
        /// <param name="xboxUserId">The xbox user id of the player to be reset</param>
        /// <returns></returns>
        static public async Task <UserResetResult> ResetPlayerDataAsync(string serviceConfigurationId, string sandbox, string xboxUserId)
        {
            // Pre-fetch the product/sandbox etoken before getting into the loop, so that we can
            // populate the auth error up-front.
            await Auth.GetETokenSilentlyAsync(serviceConfigurationId, sandbox);

            return(await SubmitJobAndPollStatus(sandbox, serviceConfigurationId, xboxUserId));
        }
Beispiel #4
0
        /// <summary>
        /// Deletes a blob 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></returns>
        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}");
            }
        }
        static public async Task <IEnumerable <UserResetResult> > ResetProgressAsync(string sandbox, string scid, IEnumerable <string> xuids)
        {
            // Pre-fetch the product/sandbox etoken before getting into the loop, so that we can
            // populate the auth error up-front.
            await Auth.GetETokenSilentlyAsync(scid, sandbox);

            var tasks = new List <Task <UserResetResult> >();

            foreach (string xuid in xuids)
            {
                tasks.Add(SubmitJobAndPollStatus(sandbox, scid, xuid));
            }

            await Task.WhenAll(tasks.ToArray());

            return(tasks.Select(task => task.Result).ToList());;
        }
Beispiel #6
0
        /// <summary>
        /// Get title global storage quota information.
        /// </summary>
        /// <param name="serviceConfigurationId">The service configuration ID (SCID) of the title</param>
        /// <param name="sandbox">The target sandbox id for title storage</param>
        /// <returns>GlobalStorageQuotaInfo object contains quota info</returns>
        static public async Task <GlobalStorageQuotaInfo> GetGlobalStorageQuotaAsync(string serviceConfigurationId, string sandbox)
        {
            using (var request = new XboxLiveHttpRequest())
            {
                var requestMsg = new HttpRequestMessage(HttpMethod.Get, new Uri(baseUri, "/global/scids/" + serviceConfigurationId));

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

                AddRequestHeaders(ref requestMsg, eToken);

                var response = await request.SendAsync(requestMsg);

                string content = await response.Content.ReadAsStringAsync();

                JObject storageQuota        = JObject.Parse(content);
                GlobalStorageQuotaInfo info = storageQuota["quotaInfo"].ToObject <GlobalStorageQuotaInfo>();

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

                return(info);
            }
        }
Beispiel #7
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);
            }
        }