public void RunFlightSubmissionUpdate() { // ********************** // SETTINGS // ********************** var appId = this.ClientConfig.ApplicationId; var flightId = this.ClientConfig.FlightId; var clientId = this.ClientConfig.ClientId; var clientSecret = this.ClientConfig.ClientSecret; var serviceEndpoint = this.ClientConfig.ServiceUrl; var tokenEndpoint = this.ClientConfig.TokenEndpoint; var scope = this.ClientConfig.Scope; var file = this.ClientConfig.AppxFile; var zipFile = this.ClientConfig.ZipFile; // Get authorization token Console.WriteLine("Getting authorization token "); var accessToken = IngestionClient.GetClientCredentialAccessToken( tokenEndpoint, clientId, clientSecret, scope).Result; Console.WriteLine("Getting flight"); var client = new IngestionClient(accessToken, serviceEndpoint); dynamic flights = client.Invoke <dynamic>( HttpMethod.Get, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.GetApplicationFlightsUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, flightId), requestContent: null).Result; for (int i = 0; i < flights.value.Count; i++) { if (flights.value[i].friendlyName == flightId) { flightId = flights.value[i].flightId; } } // flightId= flight. dynamic flight = client.Invoke <dynamic>( HttpMethod.Get, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.GetFlightUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, flightId), requestContent: null).Result; if (flight.pendingFlightSubmission != null) { var submissionId = flight.pendingFlightSubmission.id.Value as string; // Let's try deleting it. If it was NOT creationg via the API, then you need to // manually delete it from the dashboard. This is a safety measure to make sure that a // human user and an automated system don't make conflicting edits. Console.WriteLine("Deleting the pending submission"); client.Invoke <dynamic>( HttpMethod.Delete, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.GetFlightSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, flightId, submissionId), requestContent: null).Wait(); } // Create a new submission, which will be an exact copy of the last published submission. Console.WriteLine("Creating a new submission"); dynamic flightSubmission = client.Invoke <dynamic>( HttpMethod.Post, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.CreateFlightSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, flightId), requestContent: null).Result; // Update packages. // Let's say we want to delete the existing package: flightSubmission.flightPackages[0].fileStatus = "PendingDelete"; // Let's add a new package. var packages = new List <dynamic>(); packages.Add(flightSubmission.flightPackages[0]); packages.Add( new { fileStatus = "PendingUpload", fileName = Path.GetFileName(file), }); flightSubmission.flightPackages = JToken.FromObject(packages.ToArray()); var flightSubmissionId = flightSubmission.id.Value as string; // Upload the zip archive with all new files to the SAS URL returned with the submission. var fileUploadUrl = flightSubmission.fileUploadUrl.Value as string; Console.WriteLine("FileUploadUrl: " + fileUploadUrl); Console.WriteLine("Uploading file"); IngestionClient.UploadFileToBlob(zipFile, fileUploadUrl).Wait(); // Update the submission. Console.WriteLine("Updating the submission"); client.Invoke <dynamic>( HttpMethod.Put, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.GetFlightSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, flightId, flightSubmissionId), requestContent: flightSubmission).Wait(); // Tell the system that we are done updating the submission. Console.WriteLine("Committing the submission"); client.Invoke <dynamic>( HttpMethod.Post, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.CommitFlightSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, flightId, flightSubmissionId), requestContent: null).Wait(); // Periodically check the status until it changes from "CommitsStarted" to either // successful status or a failure. Console.WriteLine("Waiting for the submission commit processing to complete. This may take a couple of minutes."); string submissionStatus = null; dynamic completeStatus; do { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); dynamic statusResource = client.Invoke <dynamic>( HttpMethod.Get, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.FlightSubmissionStatusUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, flightId, flightSubmissionId), requestContent: null).Result; submissionStatus = statusResource.status.Value as string; Console.WriteLine("Current status: " + submissionStatus); completeStatus = statusResource; }while ("CommitStarted".Equals(submissionStatus)); if ("CommitFailed".Equals(submissionStatus)) { Console.WriteLine("Submission has failed. Please check the Errors collection of the submissionResource response."); Console.WriteLine("###########################################################"); Console.WriteLine(completeStatus); Console.WriteLine("###########################################################"); return; } else { Console.WriteLine("Submission commit success!"); } }
public void RunAppSubmissionUpdate() { // ********************** // SETTINGS // ********************** var appId = this.ClientConfig.ApplicationId; var clientId = this.ClientConfig.ClientId; var clientSecret = this.ClientConfig.ClientSecret; var serviceEndpoint = this.ClientConfig.ServiceUrl; var tokenEndpoint = this.ClientConfig.TokenEndpoint; var scope = this.ClientConfig.Scope; var file = this.ClientConfig.AppxFile; var zipFile = this.ClientConfig.ZipFile; var mandatory = this.ClientConfig.IsMandatory; var publishMode = Enum.GetName(typeof(TargetPublishMode), this.ClientConfig.PublishMode); // Get authorization token Console.WriteLine("Getting authorization token "); var accessToken = IngestionClient.GetClientCredentialAccessToken( tokenEndpoint, clientId, clientSecret).Result; Console.WriteLine("Getting application "); var client = new IngestionClient(accessToken, serviceEndpoint); dynamic app = client.Invoke <dynamic>( HttpMethod.Get, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.GetApplicationUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId), requestContent: null).Result; Console.WriteLine(app.ToString()); // Let's get the last published submission, and print its contents, just for information if (app.lastPublishedApplicationSubmission == null) { // It is not possible to create the very first submission through the API throw new InvalidOperationException( "You need at least one published submission to create new submissions through API."); } // Let's see if there is a pending submission. Warning! If it was created through the API, // it will be deleted so that we could create a new one in its stead. if (app.pendingApplicationSubmission != null) { var submissionId = app.pendingApplicationSubmission.id.Value as string; // Try deleting it. If it was NOT created via the API, then you need to manually // delete it from the dashboard. This is done as a safety measure to make sure that a // user and an automated system don't make conflicting edits. Console.WriteLine("Deleting the pending submission"); client.Invoke <dynamic>( HttpMethod.Delete, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.GetSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, submissionId), requestContent: null).Wait(); } // Create a new submission, which will be an exact copy of the last published submission. Console.WriteLine("Creating a new submission"); dynamic clonedSubmission = client.Invoke <dynamic>( HttpMethod.Post, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.CreateSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId), requestContent: null).Result; // Update some property on the root submission object //clonedSubmission.notesForCertification = "This is a test update, updating listing info, images, and packages"; //// Now, assume we have an en-us listing. Let's try to change its description //clonedSubmission.listings["en-us"].baseListing.description = "This is my new en-Us description!"; //// Update images //// Assuming we have at least 1 image, let's delete one image //clonedSubmission.listings["en-us"].baseListing.images[0].fileStatus = "PendingDelete"; //var images = new List<dynamic>(); //images.Add(clonedSubmission.listings["en-us"].baseListing.images[0]); //images.Add( // new // { // fileStatus = "PendingUpload", // fileName = "rectangles.png", // imageType = "Screenshot", // description = "This is a new image uploaded through the API!", // }); //clonedSubmission.listings["en-us"].baseListing.images = JToken.FromObject(images.ToArray()); clonedSubmission.targetPublishMode = publishMode; clonedSubmission.packageDeliveryOptions.isMandatoryUpdate = mandatory; clonedSubmission.packageDeliveryOptions.mandatoryUpdateEffectiveDate = "1601-01-01T00:00:00.0000000Z"; // Update packages // Let's say we want to delete the existing package: clonedSubmission.applicationPackages[0].fileStatus = "PendingDelete"; // Now, let's add a new package var packages = new List <dynamic>(); packages.Add(clonedSubmission.applicationPackages[0]); packages.Add( new { fileStatus = "PendingUpload", fileName = Path.GetFileName(file), }); clonedSubmission.applicationPackages = JToken.FromObject(packages.ToArray()); var clonedSubmissionId = clonedSubmission.id.Value as string; // Uploaded the zip archive with all new files to the SAS url returned with the submission var fileUploadUrl = clonedSubmission.fileUploadUrl.Value as string; Console.WriteLine("FileUploadUrl: " + fileUploadUrl); Console.WriteLine("Uploading file"); IngestionClient.UploadFileToBlob(zipFile, fileUploadUrl).Wait(); // Update the submission Console.WriteLine("Updating the submission"); client.Invoke <dynamic>( HttpMethod.Put, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.UpdateUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, clonedSubmissionId), requestContent: clonedSubmission).Wait(); // Tell the system that we are done updating the submission. // Update the submission Console.WriteLine("Committing the submission"); client.Invoke <dynamic>( HttpMethod.Post, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.CommitSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, clonedSubmissionId), requestContent: null).Wait(); // Let's periodically check the status until it changes from "CommitsStarted" to either // successful status or a failure. Console.WriteLine("Waiting for the submission commit processing to complete. This may take a couple of minutes."); string submissionStatus = null; dynamic completeStatus; do { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); dynamic statusResource = client.Invoke <dynamic>( HttpMethod.Get, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.ApplicationSubmissionStatusUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, clonedSubmissionId), requestContent: null).Result; submissionStatus = statusResource.status.Value as string; Console.WriteLine("Current status: " + submissionStatus); completeStatus = statusResource; }while ("CommitStarted".Equals(submissionStatus)); if ("CommitFailed".Equals(submissionStatus)) { Console.WriteLine("Submission has failed. Please checkt the Errors collection of the submissionResource response."); Console.WriteLine("###########################################################"); Console.WriteLine(completeStatus); Console.WriteLine("###########################################################"); return; } else { Console.WriteLine("Submission commit success! Here are some data:"); dynamic submission = client.Invoke <dynamic>( HttpMethod.Get, relativeUrl: string.Format( CultureInfo.InvariantCulture, IngestionClient.GetSubmissionUrlTemplate, IngestionClient.Version, IngestionClient.Tenant, appId, clonedSubmissionId), requestContent: null).Result; Console.WriteLine("Packages: " + submission.applicationPackages); Console.WriteLine("en-US description: " + submission.listings["en-us"].baseListing.description); } }