forked from MicrosoftDocs/windows-dev-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppSubmissionUpdateSample.cs
224 lines (200 loc) · 9.86 KB
/
AppSubmissionUpdateSample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//<AppSubmissionUpdateSample>
namespace DeveloperApiCSharpSample
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
/// <summary>
/// This sample update does a full submission update, updating listings info, images, and packages
/// </summary>
public class AppSubmissionUpdateSample
{
private ClientConfiguration ClientConfig;
/// <summary>
/// Constructor
/// </summary>
/// <param name="c">An instance of ClientConfiguration that contains all parameters populated</param>
public AppSubmissionUpdateSample(ClientConfiguration c)
{
this.ClientConfig = c;
}
public void RunAppSubmissionUpdateSample()
{
// **********************
// 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;
// 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());
// 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 = "package.appx",
minimumDirectXVersion = "None",
minimumSystemRam = "None"
});
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(@"..\..\files.zip", 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;
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);
}
while ("CommitStarted".Equals(submissionStatus));
if ("CommitFailed".Equals(submissionStatus))
{
Console.WriteLine("Submission has failed. Please checkt the Errors collection of the submissionResource response.");
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);
Console.WriteLine("Images: " + submission.listings["en-us"].baseListing.images);
}
}
}
}
//</AppSubmissionUpdateSample>