Esempio n. 1
0
        public static async void Donate(string productId, bool isConsurable = false)
        {
            try
            {
                PopupMessage popupMessage = new PopupMessage();
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    var listing = await CurrentApp.LoadListingInformationAsync();

                    var myProduct = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == productId);
                    if (!CurrentApp.LicenseInformation.ProductLicenses[myProduct.Value.ProductId].IsActive)
                    {
                        await CurrentApp.RequestProductPurchaseAsync(productId, false);

                        var            productLicenses = CurrentApp.LicenseInformation.ProductLicenses;
                        ProductLicense tokenLicense    = productLicenses[productId];
                        if (tokenLicense.IsActive)
                        {
                            if (isConsurable)//если продукт расходуемый
                            {
                                CurrentApp.ReportProductFulfillment(productId);
                            }
                            var    settings = IsolatedStorageSettings.ApplicationSettings;
                            string product  = "product" + productId;
                            if (!settings.Contains(product))
                            {
                                settings.Add(product, true);
                                settings.Save();
                            }
                            //popupMessage.Show("Thank you for your purchase!");//en
                            //popupMessage.Show(AppResources.ThankYouForPurchase);//it
                            popupMessage.Show("Thank you for your purchase!");
                        }
                    }
                    else
                    {
                        //popupMessage.Show("You have already bought this product!");//en
                        //popupMessage.Show(AppResources.ProductExitsts);//it
                        popupMessage.Show("You have already bought this product!");
                    }
                }
                else
                {
                    //popupMessage.Show("Пожалуйста, проверьте подключение к сети Интернет!");//ru
                    //popupMessage.Show("Please check the connection to the Internet!");//en
                    //popupMessage.Show(AppResources.NoInternet);//it
                    popupMessage.Show("Please check the connection to the Internet!");
                }
            }
            catch (Exception ex)
            {
            }
        }
        public static async void Donate(string productId, bool isConsurable = false)
        {
            try
            {
                PopupMessage popupMessage = new PopupMessage();
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    var listing = await CurrentApp.LoadListingInformationAsync();
                    var myProduct = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == productId);
                    if (!CurrentApp.LicenseInformation.ProductLicenses[myProduct.Value.ProductId].IsActive)
                    {
                        await CurrentApp.RequestProductPurchaseAsync(productId, false);
                        var productLicenses = CurrentApp.LicenseInformation.ProductLicenses;
                        ProductLicense tokenLicense = productLicenses[productId];
                        if (tokenLicense.IsActive)
                        {
                            if (isConsurable)//если продукт расходуемый
                            {
                                CurrentApp.ReportProductFulfillment(productId);
                            }
                            var settings = IsolatedStorageSettings.ApplicationSettings;
                            string product = "product" + productId;
                            if (!settings.Contains(product))
                            {
                                settings.Add(product, true);
                                settings.Save();
                            }
                            //popupMessage.Show("Thank you for your purchase!");//en
                            //popupMessage.Show(AppResources.ThankYouForPurchase);//it
                            popupMessage.Show("Thank you for your purchase!");
                        }
                    }
                    else
                    {
                        //popupMessage.Show("You have already bought this product!");//en
                        //popupMessage.Show(AppResources.ProductExitsts);//it
                        popupMessage.Show("You have already bought this product!");
                    }
                }
                else
                {
                    //popupMessage.Show("Пожалуйста, проверьте подключение к сети Интернет!");//ru
                    //popupMessage.Show("Please check the connection to the Internet!");//en
                    //popupMessage.Show(AppResources.NoInternet);//it
                    popupMessage.Show("Please check the connection to the Internet!");
                }
            }
            catch (Exception ex)
            {

            }
        }
 public void ShowAd(Action cancelAction)
 {
     var currentCulture = CultureInfo.CurrentCulture.ToString().Substring(0, 2).ToUpper();
     var supportGames = AdsGames.Where(x => x.SupportLanguages == SupportLanguages.All || Enum.GetName(typeof(SupportLanguages), x.SupportLanguages) == currentCulture).ToList();
     if (supportGames.Count > 0)
     {
         var rand = new Random();
         int selectIndex = rand.Next(0, supportGames.Count);
         var game = supportGames[selectIndex];
         string isShowAds = String.Format("isShowAds{0}", game.AppId);
         if (!settings.Contains(isShowAds))
         {
             settings[isShowAds] = true;
             settings.Save();
             var image = new Image()
             {
                 Source = new BitmapImage(game.Icon),
                 Width = 150,
                 Height = 150
             };
             image.Tap += delegate
             {
                 OpenGameInStore(game.AppId);
             };
             var title = new TextBlock
             {
                 Text = game.TitleMessage,
                 Foreground = new SolidColorBrush(Colors.White),
                 HorizontalAlignment = HorizontalAlignment.Center,
                 Margin = new Thickness(5, 5, 5, 10),
                 TextWrapping = TextWrapping.Wrap
             };
             var gameName = new TextBlock
             {
                 Text = game.Name,
                 Foreground = new SolidColorBrush(Colors.White),
                 HorizontalAlignment = HorizontalAlignment.Center,
                 Margin = new Thickness(5, 5, 5, 20)
             };
             var body = new StackPanel
             {
                 Orientation = System.Windows.Controls.Orientation.Vertical,
                 HorizontalAlignment = HorizontalAlignment.Center,
                 Children =
             {
                 title,
                 image,
                 gameName
             }
             };
             var popup = new PopupMessage
             {
                 Body = body
             };
             popup.OnOkClick += delegate
             {
                 OpenGameInStore(game.AppId);
             };
             popup.OnCancelClick += delegate
             {
                 cancelAction.Invoke();
             };
             popup.Show("", true);
         }
     }
 }