public void PreLoadStoreData() { PreLoadTask = Task.Factory.StartNew(() => { try { Store = StoreContext.GetDefault(); Store.OfflineLicensesChanged += Store_OfflineLicensesChanged; if (ApplicationData.Current.LocalSettings.Values.TryGetValue("LicenseGrant", out object GrantState)) { if (!Convert.ToBoolean(GrantState)) { License = Store.GetAppLicenseAsync().AsTask().Result; } } else { License = Store.GetAppLicenseAsync().AsTask().Result; } ProductResult = Store.GetStoreProductForCurrentAppAsync().AsTask().Result; } catch (Exception ex) { LogTracer.Log(ex, "Could not load MSStore data"); } }, TaskCreationOptions.LongRunning); }
private async void InitializeLicense() { try { if (context == null) { context = StoreContext.GetDefault(); // If your app is a desktop app that uses the Desktop Bridge, you // may need additional code to configure the StoreContext object. // For more info, see https://aka.ms/storecontext-for-desktop. } appLicense = await context.GetAppLicenseAsync(); if (appLicense.IsActive) { if (appLicense.IsTrial) { int remainingTrialTime = (appLicense.ExpirationDate - DateTime.Now).Days; trial.Visibility = Visibility.Visible; //Debug.WriteLine($"This is the trial version. Expiration date: {appLicense.ExpirationDate}"); textlic.Text = $"You can use this app for {remainingTrialTime} more days before the trial period ends."; // StoreServicesCustomEventLogger logger = StoreServicesCustomEventLogger.GetDefault(); // logger.Log("isTrialEvent"); // textBlock.Text = $"This is the trial version. Expiration date: {appLicense.ExpirationDate}"; // Show the features that are available during trial only. } else { textlic.Text = "You have a full license."; trial.Visibility = Visibility.Collapsed; // StoreServicesCustomEventLogger logger = StoreServicesCustomEventLogger.GetDefault(); // logger.Log("NotTrialEvent"); // Show the features that are available only with a full license. } } else { trial.Visibility = Visibility.Collapsed; textlic.Text = "You don't have a license. The trial time can't be determined."; //StoreServicesCustomEventLogger logger = StoreServicesCustomEventLogger.GetDefault(); // logger.Log("NotActiveEvent"); } // Register for the licenced changed event. context.OfflineLicensesChanged += context_OfflineLicensesChanged; } catch (Exception ex) { trial.Visibility = Visibility.Collapsed; } }
/// <summary> /// Checks if user has active subscription and durables. it doesnt include consumeables /// </summary> /// <param name="subscriptionStoreId">if it is not provided, checks if there is an active licence.</param> /// <returns></returns> public async Task <bool> CheckIfUserHasActiveSubscriptionAsync(string subscriptionStoreId, ItemType itemType = ItemType.InAppPurchase) { if (context == null) { context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await context.GetAppLicenseAsync(); return(appLicense.AddOnLicenses.Any(s => (s.Value.InAppOfferToken.StartsWith("sub_") || s.Value.SkuStoreId.StartsWith("sub_")) && s.Value.ExpirationDate > DateTime.Now)); }
public async Task <bool> CheckPurchaseStatusAsync() { try { if (ApplicationData.Current.LocalSettings.Values.TryGetValue("LicenseGrant", out object GrantState) && Convert.ToBoolean(GrantState)) { return(true); } if (HasVerifiedLicense && ApplicationData.Current.LocalSettings.Values.ContainsKey("LicenseGrant")) { return(Convert.ToBoolean(ApplicationData.Current.LocalSettings.Values["LicenseGrant"])); } else { HasVerifiedLicense = true; StoreAppLicense License = GetLicenseTask == null ? await Store.GetAppLicenseAsync() : await GetLicenseTask.ConfigureAwait(false); if (License.AddOnLicenses.Any((Item) => Item.Value.InAppOfferToken == "Donation")) { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true; return(true); } else { if (License.IsActive) { if (License.IsTrial) { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = false; return(false); } else { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true; return(true); } } else { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = false; return(false); } } } } catch (Exception ex) { LogTracer.Log(ex, $"{nameof(CheckPurchaseStatusAsync)} threw an exception"); return(false); } }
public async Task <bool> HasLicense() { if (storeContext == null) { storeContext = StoreContext.GetDefault(); //IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext; //initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); } StoreAppLicense license = await storeContext.GetAppLicenseAsync(); return(license != null && license.IsActive); }
private async void InitializeLicense() { if (context == null) { context = StoreContext.GetDefault(); } appLicense = await context.GetAppLicenseAsync(); // register changed event, in case license change during app session context.OfflineLicensesChanged += Context_OfflineLicensesChanged; CheckLicense(appLicense); }
public async void GetLicenseInfo() { if (context == null) { context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await context.GetAppLicenseAsync(); if (appLicense == null) { // textBlock.Text = "An error occurred while retrieving the license."; return; } // Access the add on licenses for add-ons for this app. foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses) { StoreLicense addOnLicense = item.Value; // Use members of the addOnLicense object to access license info // for the add-on... //addOnLicense. if (addOnLicense.IsActive) { AdGrid.Visibility = Visibility.Collapsed; } } }
public string getName() { StoreContext storeContext = StoreContext.GetDefault(); StoreAppLicense license = storeContext.GetAppLicenseAsync().AsTask().Result; if (license == null) { return(LocaleFactory.localizedString("Unknown")); } if (license.IsActive) { if (license.IsTrial) { return(LocaleFactory.localizedString("Trial Version", "License")); } else { return((string)storeContext.User?.GetPropertyAsync(KnownUserProperties.DisplayName).AsTask().Result ?? LocaleFactory.localizedString("Unknown")); } } else { return(LocaleFactory.localizedString("Unknown")); } }
public bool verify(LicenseVerifierCallback callback) { StoreContext storeContext = StoreContext.GetDefault(); StoreAppLicense license = storeContext.GetAppLicenseAsync().AsTask().Result; return(true || (license?.IsActive ?? true)); // HACK Windows Store Submission Process }
/// <inheritdoc/> public async Task <bool> IsOwnedAsync(string iapId) { if (!NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { return(false); } if (_context == null) { _context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await _context.GetAppLicenseAsync(); if (appLicense == null) { return(false); } /// Check if user has an active license for given add-on id. foreach (var addOnLicense in appLicense.AddOnLicenses) { var license = addOnLicense.Value; if (license.InAppOfferToken == iapId && license.IsActive) { return(true); } } return(false); }
public async void GetLicenseInfo() { if (context == null) { context = StoreContext.GetDefault(); // If your app is a desktop app that uses the Desktop Bridge, you // may need additional code to configure the StoreContext object. // For more info, see https://aka.ms/storecontext-for-desktop. } workingProgressRing.IsActive = true; StoreAppLicense appLicense = await context.GetAppLicenseAsync(); workingProgressRing.IsActive = false; if (appLicense == null) { textBlock.Text = "An error occurred while retrieving the license."; return; } // Use members of the appLicense object to access license info... // Access the valid licenses for durable add-ons for this app. foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses) { StoreLicense addOnLicense = item.Value; // Use members of the addOnLicense object to access license info // for the add-on. } }
private static async Task <bool> CheckPurchaseStatusAsync() { try { StoreContext Store = StoreContext.GetDefault(); StoreAppLicense License = await Store.GetAppLicenseAsync(); if (License.AddOnLicenses.Any((Item) => Item.Value.InAppOfferToken == "Donation")) { return(true); } if (License.IsActive) { if (License.IsTrial) { return(false); } else { return(true); } } else { return(false); } } catch { throw new NetworkException("Network Exception"); } }
private static async Task <bool> CheckIfUserHasSubscriptionAsync(string msProductId) { if (context == null) { context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await context.GetAppLicenseAsync(); // Check if the customer has the rights to the subscription. foreach (var addOnLicense in appLicense.AddOnLicenses) { StoreLicense license = addOnLicense.Value; if (license.SkuStoreId.StartsWith(msProductId)) { if (license.IsActive) { // The expiration date is available in the license.ExpirationDate property. accountType = "starter"; updateCloureAccount(license.ExpirationDate); return(true); } } } // The customer does not have a license to the subscription. return(false); }
async Task <ReadOnlyCollection <DurableAddOn> > PlatformGetDurableAddOns(params string[] keys) { if (context == null) { context = StoreContext.GetDefault(); } var durables = new Collection <DurableAddOn>(); // Specify the kinds of add-ons to retrieve. if (keys.Length == 0) { durables.AddRange(_addOnsByKey.Values.OfType <DurableAddOn>()); } else { foreach (var key in keys) { if (_addOnsByKey[key] is DurableAddOn dao) { durables.Add(dao); } } } var queryResult = await context.GetStoreProductsAsync(new List <string>() { "Durable" }, durables.Select(d => d.Id)); if (queryResult.ExtendedError == null) { var license = await context.GetAppLicenseAsync(); foreach (var durable in durables) { var product = queryResult.Products[durable.Id]; if (!product.Skus[0].IsSubscription) { durable.Title = product.Title; durable.Description = product.Description; durable.Price = product.Price.FormattedPrice; durable.CustomData = product.Skus[0].CustomDeveloperData; durable.IsActive = license.AddOnLicenses.TryGetValue(product.StoreId, out var l) ? l.IsActive : false; } } } return(new ReadOnlyCollection <DurableAddOn>(durables)); }
// Call this while your app is initializing. private async void InitializeLicense() { if (context == null) { context = StoreContext.GetDefault(); // If your app is a desktop app that uses the Desktop Bridge, you // may need additional code to configure the StoreContext object. // For more info, see https://aka.ms/storecontext-for-desktop. } workingProgressRing.IsActive = true; appLicense = await context.GetAppLicenseAsync(); workingProgressRing.IsActive = false; // Register for the licenced changed event. context.OfflineLicensesChanged += context_OfflineLicensesChanged; }
public async void InitializeLicenseAsync() { if (storeContext == null) { storeContext = StoreContext.GetDefault(); storeContext.As <IInitializeWithWindow>().Initialize(new WindowInteropHelper(this).Handle); } ProgressRing.IsActive = true; appLicense = await storeContext.GetAppLicenseAsync(); ProgressRing.IsActive = false; if (appLicense.IsTrial) { await ShowStoreContextControlAsync(appLicense); } storeContext.OfflineLicensesChanged += StoreContext_OfflineLicensesChanged; }
public async Task <IReadOnlyDictionary <string, StoreLicense> > GetAddOnLicenses() { StoreContext storeContext = StoreContext.GetDefault(); StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync(); if (appLicense == null) { return(null); } return(appLicense.AddOnLicenses); }
// Store Stuff private async Task GetLicense() { StoreAppLicense license = await storeContext.GetAppLicenseAsync(); if (license.IsActive) { if (license.IsTrial) { UiShowPurchaseButton = true; } else { UiShowPurchaseButton = false; } } else { UiShowPurchaseButton = true; } }
private async Task GetLicenseState() { StoreAppLicense license = await storeContext.GetAppLicenseAsync(); if (license.IsActive) { if (license.IsTrial) { LicenseMode.Text = "Trial license"; } else { LicenseMode.Text = "Full license"; } } else { LicenseMode.Text = "Inactive license"; } }
/// <inheritdoc/> public async Task <bool> IsProductPurchasedAsync(string id) { if (!(await StoreContext.GetAppLicenseAsync() is StoreAppLicense license)) { return(false); } return(license.AddOnLicenses .FirstOrDefault(pair => pair.Value.InAppOfferToken.Equals(id)) .Value?.IsActive == true); }
private async void Store_OfflineLicensesChanged(StoreContext sender, object args) { try { StoreAppLicense License = await sender.GetAppLicenseAsync(); if (License.IsActive && !License.IsTrial) { ApplicationData.Current.LocalSettings.Values["LicenseGrant"] = true; } } catch (Exception ex) { LogTracer.Log(ex, $"{nameof(Store_OfflineLicensesChanged)} threw an exception"); } }
public void PreLoadStoreData() { PreLoadTask = Task.Factory.StartNew(() => { try { Store = StoreContext.GetDefault(); Store.OfflineLicensesChanged += Store_OfflineLicensesChanged; License = Store.GetAppLicenseAsync().AsTask().Result; ProductResult = Store.GetStoreProductForCurrentAppAsync().AsTask().Result; Updates = Store.GetAppAndOptionalStorePackageUpdatesAsync().AsTask().Result; } catch (Exception ex) { LogTracer.Log(ex, "Could not load MSStore data"); } }, TaskCreationOptions.LongRunning); }
private async void PurchaseAddOnButton_Click(object sender, RoutedEventArgs e) { string productStoreId = ""; StorePurchaseResult result = await storeContext.RequestPurchaseAsync(productStoreId); if (result.ExtendedError != null) { Debug.WriteLine(result.ExtendedError); return; } switch (result.Status) { case StorePurchaseStatus.AlreadyPurchased: break; case StorePurchaseStatus.Succeeded: break; case StorePurchaseStatus.NotPurchased: break; case StorePurchaseStatus.NetworkError: break; case StorePurchaseStatus.ServerError: break; default: break; } var license = await storeContext.GetAppLicenseAsync(); if (license.AddOnLicenses != null) { foreach (var licenseItem in license.AddOnLicenses) { Debug.WriteLine($"{licenseItem.Key}:{licenseItem.Value.IsActive}:{licenseItem.Value.ExpirationDate.ToLocalTime()}"); } } }
//检查用户是否有订阅的许可证 private async Task <bool> CheckIfUserHasSubscriptionAsync() { StoreAppLicense appLicense = await context.GetAppLicenseAsync(); //检查客户是否具有订阅权限。 foreach (var addOnLicense in appLicense.AddOnLicenses) { StoreLicense license = addOnLicense.Value; if (license.SkuStoreId.StartsWith(productID)) { if (license.IsActive) { // The expiration date is available in the license.ExpirationDate property. return(true); //客户有订阅的许可证。 } } } //客户没有订阅的许可证。 return(false); }
private async Task <bool> CheckIfUserHasSubscriptionAsync() { StoreAppLicense appLicense = await context.GetAppLicenseAsync(); // Check if the customer has the rights to the subscription. foreach (var addOnLicense in appLicense.AddOnLicenses) { StoreLicense license = addOnLicense.Value; if (license.SkuStoreId.StartsWith(subscriptionStoreId)) { if (license.IsActive) { // The expiration date is available in the license.ExpirationDate property. return(true); } } } // The customer does not have a license to the subscription. return(false); }
public static async Task <bool> IsBuyPro() { if (context == null) { context = StoreContext.GetDefault(); } var a = await context.GetAppLicenseAsync(); var licenses = a.AddOnLicenses; foreach (KeyValuePair <string, StoreLicense> item in licenses) { if (item.Key == "9NQXP4JCLXWB") { return(true); } } return(false); }
protected async override Task <IEnumerable <InAppBillingPurchase> > GetPurchasesAsync(ItemType itemType, IInAppBillingVerifyPurchase verifyPurchase, string verifyOnlyProductId) { StoreAppLicense license = await storeContext.GetAppLicenseAsync(); var products = new List <InAppBillingPurchase>(); foreach (KeyValuePair <string, StoreLicense> kvp in license.AddOnLicenses) { Debug.WriteLine("Store license for:" + kvp.Key + " Lic:" + kvp.Value.InAppOfferToken + " " + kvp.Value.SkuStoreId + " " + kvp.Value.ExtendedJsonData); products.Add(new InAppBillingPurchase { Id = kvp.Key, ProductId = kvp.Value.InAppOfferToken, State = PurchaseState.Purchased, // AutoRenewing = false, // PurchaseToken // ConsumptionState = ConsumptionState.NoYetConsumed }); } //return products; return(null); }
public async void CheckTrialStatus() { string[] filterList = new string[] { "Consumable", "Durable", "UnmanagedConsumable" }; StoreAppLicense license = await storeContext.GetAppLicenseAsync(); //StoreProductQueryResult addOns = await storeContext.GetAssociatedStoreProductsAsync(filterList); //ShowToast(addOns.ToString()); if (license.IsActive) { if (license.IsTrial) { UpdateTile("Trial license"); } else { UpdateTile("Full license"); } } else { UpdateTile("This license seems broken!"); ShowToast("this license ain't working!"); } }
public async Task <bool> GetAddOnLicenseInfo() { bool IsActive = false; var users = await User.FindAllAsync(); StoreContext context = StoreContext.GetForUser(users[0]); StoreAppLicense appLicense = await context.GetAppLicenseAsync(); System.Diagnostics.Debug.WriteLine(appLicense.AddOnLicenses.Count); foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses) { StoreLicense addOnLicense = item.Value; if (addOnLicense.SkuStoreId.ToLower().Contains("9pc587j41rs1")) { PremiumFeaturesActivatedType = "Month"; } else if (addOnLicense.SkuStoreId.ToLower().Contains("9pf5zlm4lprg")) { PremiumFeaturesActivatedType = "Year"; } else { return(false); } PremiumFeaturesActivatedRemain = (addOnLicense.ExpirationDate - DateTime.Now).Days.ToString(); IsActive = addOnLicense.IsActive; } return(IsActive); }
public async void GetLicenseInfo() { if (context == null) { context = StoreContext.GetDefault(); } StoreAppLicense appLicense = await context.GetAppLicenseAsync(); if (appLicense == null) { return; } foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses) { StoreLicense addOnLicense = item.Value; if (addOnLicense.IsActive) { AdGrid.Visibility = Visibility.Collapsed; DrinkManager.IsAdFree = true; } } }