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); }
protected async Task <XdtsTokenResponse> FetchXdtsToken(string aadToken, string scid, string sandbox) { var tokenRequest = new XboxLiveHttpRequest(); var requestMsg = new HttpRequestMessage(HttpMethod.Post, this.authContext.XtdsEndpoint); var requestContent = JsonConvert.SerializeObject(new XdtsTokenRequest(scid, sandbox)); requestMsg.Content = new StringContent(requestContent); // Add the aadToken header without validation as the framework // does not like the values returned for aadTokens for MSA accounts. requestMsg.Headers.TryAddWithoutValidation("Authorization", aadToken); var responseContent = await tokenRequest.SendAsync(requestMsg); Log.WriteLog("Fetch xdts Token succeeded."); string content = await responseContent.Content.ReadAsStringAsync(); var token = JsonConvert.DeserializeObject <XdtsTokenResponse>(content); this.cachedTokens[scid + sandbox] = token; return(token); }
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); } }
/// <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}"); } }
/// <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); } }
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); } }