forked from microsoft/Appsample-Photosharing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrentAppProxy.cs
256 lines (240 loc) · 11.6 KB
/
CurrentAppProxy.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//-----------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ---------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Windows.ApplicationModel.Store;
using Windows.Foundation;
namespace PhotoSharingApp.Universal.Store
{
/// <summary>
/// Proxy class for <see cref="CurrentApp" /> and
/// <see cref="CurrentAppSimulator" />.
/// This class is handling mocking and therefore should be the only
/// entry point for store licensing calls.
/// </summary>
public class CurrentAppProxy
{
/// <summary>
/// Determines if mocking is enabled. If enabled,
/// <see cref="CurrentAppSimulator" /> is used, otherwise
/// <see cref="CurrentApp" />.
/// </summary>
public static bool IsMockEnabled { get; set; }
/// <summary>
/// Gets the license metadata for the current app.
/// </summary>
public static LicenseInformation LicenseInformation
{
get
{
return IsMockEnabled
? CurrentAppSimulator.LicenseInformation
: CurrentApp.LicenseInformation;
}
}
/// <summary>
/// Gets the Uniform Resource Identifier (URI) of the
/// app's listing page in the web catalog of the Windows Store.
/// </summary>
public static Uri LinkUri
{
get
{
return IsMockEnabled
? CurrentAppSimulator.LinkUri
: CurrentApp.LinkUri;
}
}
/// <summary>
/// Retrieves the promotion campaign ID for the current app.
/// </summary>
/// <returns>The advertising campaign ID for your app.</returns>
public static IAsyncOperation<string> GetAppPurchaseCampaignIdAsync()
{
return IsMockEnabled
? CurrentAppSimulator.GetAppPurchaseCampaignIdAsync()
: CurrentApp.GetAppPurchaseCampaignIdAsync();
}
/// <summary>
/// Requests all receipts for the purchase of the app
/// and any in-app products.
/// </summary>
/// <returns>
/// An XML-formatted string that contains all receipt
/// information for the purchase of the app and any in-app products.
/// </returns>
public static IAsyncOperation<string> GetAppReceiptAsync()
{
return IsMockEnabled
? CurrentAppSimulator.GetAppReceiptAsync()
: CurrentApp.GetAppReceiptAsync();
}
/// <summary>
/// Returns a list of purchased consumable in-app products
/// that have not been reported to the Windows Store as fulfilled.
/// </summary>
/// <returns>
/// When the operation completes, a list of consumable
/// in-app products not yet reported as fulfilled is returned
/// (UnfulfilledConsumable objects).
/// </returns>
public static IAsyncOperation<IReadOnlyList<UnfulfilledConsumable>> GetUnfulfilledConsumablesAsync()
{
return IsMockEnabled
? CurrentAppSimulator.GetUnfulfilledConsumablesAsync()
: CurrentApp.GetUnfulfilledConsumablesAsync();
}
/// <summary>
/// Loads the app's listing information asynchronously.
/// </summary>
/// <returns>
/// The apps' listing information. If the method fails,
/// it returns an HRESULT error code.
/// </returns>
public static IAsyncOperation<ListingInformation> LoadListingInformationAsync()
{
return IsMockEnabled
? CurrentAppSimulator.LoadListingInformationAsync()
: CurrentApp.LoadListingInformationAsync();
}
/// <summary>
/// Loads the app listing information asynchronously, returning features
/// and products in the ProductListings collection that match all supplied keywords.
/// </summary>
/// <param name="keywords">
/// The list of keywords by which to filter the ProductListings
/// collection that is returned in the ListingInformation object.
/// </param>
/// <returns>
/// The app's listing information, with ProductListings collection filtered by keywords. If the method fails, it
/// returns an HRESULT error code. If no products or features are found that match all of the given keywords, the
/// ProductListings collection will be empty.
/// </returns>
public static IAsyncOperation<ListingInformation> LoadListingInformationByKeywordsAsync(
IEnumerable<string> keywords)
{
return IsMockEnabled
? CurrentAppSimulator.LoadListingInformationByKeywordsAsync(keywords)
: CurrentApp.LoadListingInformationByKeywordsAsync(keywords);
}
/// <summary>
/// Loads the app listing information asynchronously, returning features and products in the ProductListings collection
/// that match any of the given products IDs.
/// </summary>
/// <param name="productIds">The list of product IDs by which to filter the ProductListings collection.</param>
/// <returns>
/// The app's listing information, with ProductListings collection filtered by product IDs. If the method fails,
/// it returns an HRESULT error code. If no products or features are found that match the given product IDs, the
/// ProductListings collection will be empty.
/// </returns>
public static IAsyncOperation<ListingInformation>
LoadListingInformationByProductIdsAsync(IEnumerable<string> productIds)
{
return IsMockEnabled
? CurrentAppSimulator.LoadListingInformationByProductIdsAsync(productIds)
: CurrentApp.LoadListingInformationByProductIdsAsync(productIds);
}
/// <summary>
/// Notifies the Windows Store that the purchase of a consumable is fulfilled and that the user has the right to access the
/// content.
/// </summary>
/// <param name="productId">Identifies the consumable.</param>
/// <param name="transactionId">Identifies a transaction that includes the purchase of the consumable (productId).</param>
/// <returns>
/// A value that indicates the status of fulfillment for a consumable in-app product. Possible values are defined
/// by the FulfillmentResult enumeration.
/// </returns>
public static IAsyncOperation<FulfillmentResult>
ReportConsumableFulfillmentAsync(string productId, Guid transactionId)
{
return IsMockEnabled
? CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId)
: CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId);
}
/// <summary>
/// Notifies the Windows Store that the application has fulfilled the in-app product. This product cannot be re-purchased
/// until the app has confirmed fulfillment using this method.
/// </summary>
/// <param name="productId">The ID of the product that has been delivered to the user.</param>
public static void ReportProductFulfillment(string productId)
{
if (IsMockEnabled)
{
// There is no fulfillment method in the simulator that
// accepts one parameter.
throw new ArgumentException();
}
CurrentApp.ReportProductFulfillment(productId);
}
/// <summary>
/// Requests the purchase of a full app license.
/// </summary>
/// <param name="includeReceipt">Determines if this method should return the receipts for this app.</param>
/// <returns>
/// If the includeReceipt parameter is set to true, this string contains XML that represents all receipts for the
/// app and any in-app purchases. If includeReceipt is set to false, this string is empty.
/// </returns>
public static IAsyncOperation<string> RequestAppPurchaseAsync(bool includeReceipt)
{
return IsMockEnabled
? CurrentAppSimulator.RequestAppPurchaseAsync(includeReceipt)
: CurrentApp.RequestAppPurchaseAsync(includeReceipt);
}
/// <summary>
/// Requests the purchase of an in-app product. Additionally, calling this method displays the UI that is used to complete
/// the transaction via the Windows Store.
/// </summary>
/// <param name="productId">Specifies the id of the in-app product.</param>
/// <returns>The results of the in-app product purchase request.</returns>
public static IAsyncOperation<PurchaseResults>
RequestProductPurchaseAsync(string productId)
{
return IsMockEnabled
? CurrentAppSimulator.RequestProductPurchaseAsync(productId)
: CurrentApp.RequestProductPurchaseAsync(productId);
}
/// <summary>
/// Requests the purchase of an in-app product. Additionally, calling this method displays the UI that is used to complete
/// the transaction via the Windows Store.
/// </summary>
/// <param name="productId">Specifies the id of the in-app product.</param>
/// <param name="offerId">
/// The specific in-app feature or content within the large purchase catalog represented on the
/// Windows Store by the productId. This value correlates with the content your app is responsible for fulfilling. The
/// Windows Store only uses this value to itemize the PurchaseResults.
/// </param>
/// <param name="displayProperties">
/// The name of the app feature or content offer that is displayed to the user at time of
/// purchase.
/// </param>
/// <returns>The results of the in-app product purchase request.</returns>
public static IAsyncOperation<PurchaseResults> RequestProductPurchaseAsync(string productId, string offerId,
ProductPurchaseDisplayProperties displayProperties)
{
return IsMockEnabled
? CurrentAppSimulator.RequestProductPurchaseAsync(productId, offerId, displayProperties)
: CurrentApp.RequestProductPurchaseAsync(productId, offerId, displayProperties);
}
}
}