Пример #1
0
        public static void SetListingInformation(uint AgeRating, string CurrentMarket, string Description, string FormattedPrice, string Name)
        {
            CheckIfInitialized();

            if (_appListingInformation != null)
                throw new Exception("ListingInformation already created.");

            _appListingInformation = new ListingInformation
                                         {
                                             AgeRating = AgeRating,
                                             CurrentMarket = CurrentMarket,
                                             Description = Description,
                                             FormattedPrice = FormattedPrice,
                                             Name = Name,
                                             ProductListings = new Dictionary<string, ProductListing>()
                                         };
        }
Пример #2
0
 public CurrentApp()
 {
     ListingInformation = new ListingInformation();
     LicenseInformation = new LicenseInformation();
 }
Пример #3
0
        public async void inAppPurchase_Purchase(string productID)
        {
            try
            {
                ListingInformation products = await CurrentApp.LoadListingInformationByProductIdsAsync(new[] { productID });

                // get specific in-app product by ID
                ProductListing productListing = null;
                if (!products.ProductListings.TryGetValue(productID, out productListing))
                {
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "false");
                    return;
                }

                bool           isActive = false;
                ProductLicense pLicense;
                if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue(productID, out pLicense))
                {
                    isActive = pLicense.IsActive;
                }

                if (isActive)
                {
                    // Auto-consume product
                    if (pLicense.IsConsumable)
                    {
                        CurrentApp.ReportProductFulfillment(productID);
                    }
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true");
                    return;
                }

                string result = await CurrentApp.RequestProductPurchaseAsync(productID, true);

                if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue(productID, out pLicense))
                {
                    // Auto-consume product
                    if (pLicense.IsConsumable)
                    {
                        CurrentApp.ReportProductFulfillment(productID);
                    }
                }

                if (result.Length > 0)
                {
                    // Purchased
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true");
                }
                else
                {
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true");
                }
            }
            catch (Exception e)
            {
#if DEBUGON
                MainPage.m_d3dInterop.Print("InAppPurchase::Error" + e.ToString());
#endif

                // The in-app purchase was not completed because the
                // customer canceled it or an error occurred.
                MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "false");
            }
        }
Пример #4
0
        // **********************************************************************
        // JavaScript communicating with C#
        // **********************************************************************

        private async void Browser_ScriptNotify(object sender, NotifyEventArgs e)
        {


            // Get a comma delimited string from js and convert to array
            string valueStr = e.Value;
            string[] valueArr = valueStr.Split(',');

            // Trim and convert empty strings to null
            for (int i = 0; i < valueArr.Length; i++)
            {
                valueArr[i] = valueArr[i].Trim();
                if (string.IsNullOrWhiteSpace(valueArr[i]))
                    valueArr[i] = null;
            }

            // Activate trial mode
            if (valueArr[0] == "checkLicense")
            {

                // Check if trial
                if (valueArr[1] == "true")
                {
                    C2SettingIsTrial = true;
                }
                CheckLicense();
            }

            // Game loaded
            if (valueArr[0] == "gameLoaded")
            {
                Browser.Visibility = System.Windows.Visibility.Visible;

                checkMusic();

                if (App.WasTombstoned)
                {
                    Browser.InvokeScript("eval", "window['tombstoned'] = true");
                    App.WasTombstoned = false;
                }
            }

            // Stop music
            if (valueArr[0] == "stopMusic")
            {
                if (MediaPlayer.GameHasControl)
                {
                    FrameworkDispatcher.Update();
                    MediaPlayer.Stop();
                }
            }

            // Play music
            if (valueArr[0] == "playMusic")
            {
                if (MediaPlayer.GameHasControl)
                {
                    var file = valueArr[1];
                    var loop = valueArr[2] == "0" ? false : true;

                    var db = Single.Parse(valueArr[3], CultureInfo.InvariantCulture);
                    var volume = Convert.ToSingle(dbToScale(db));

                    var uri = new Uri(file, UriKind.Relative);
                    var song = Song.FromUri(file, uri);
                    MediaPlayer.IsRepeating = loop;
                    MediaPlayer.Volume = volume;
                    FrameworkDispatcher.Update();
                    MediaPlayer.Stop();
                    MediaPlayer.Play(song);
                }
            }

            // Stop music
            if (valueArr[0] == "stopMusic")
            {
                if (MediaPlayer.GameHasControl)
                {
                    FrameworkDispatcher.Update();
                    MediaPlayer.Stop();
                }
            }

            // Play sound
            if (valueArr[0] == "playSound")
            {

                var file = valueArr[1];
                var loop = valueArr[2] == "0" ? false : true;

                var db = Single.Parse(valueArr[3], CultureInfo.InvariantCulture);
                var volume = Convert.ToSingle(dbToScale(db));

                var tag = valueArr[4];

                Stream stream = TitleContainer.OpenStream(file);
                SoundEffect effect = SoundEffect.FromStream(stream);

                sound = effect.CreateInstance();
                sound.IsLooped = loop;
                sound.Volume = volume;

                if (!string.IsNullOrEmpty(tag))
                {
                    if (SoundList.ContainsKey(tag))
                    {
                        SoundList[tag].Stop();
                    }
                    SoundList[tag] = sound;
                }

                FrameworkDispatcher.Update();
                sound.Play();

            }

            // Stop sound
            if (valueArr[0] == "stopSound")
            {
                var tag = valueArr[1];
                if (SoundList.ContainsKey(tag))
                {
                    FrameworkDispatcher.Update();
                    SoundList[tag].Stop();
                }
            }

            // Vibrate
            if (valueArr[0] == "vibrate")
            {
                float seconds = float.Parse(valueArr[1], CultureInfo.InvariantCulture);
                VibrateController vibrate = VibrateController.Default;
                vibrate.Start(TimeSpan.FromSeconds(seconds));
            }

            // Quit app
            if (valueArr[0] == "quitApp")
            {
                App.Current.Terminate();
            }

            // Live Tiles (http://tinyurl.com/afvhgz8)
            // *******************************************************

            // Flipped Tile
            if (valueArr[0] == "flippedTileUpdate")
            {
                ShellTile myTile = ShellTile.ActiveTiles.First();
                if (myTile != null)
                {
                    var smallBackgroundImage = valueArr[6] == null ? null : new Uri(valueArr[6], UriKind.Relative);
                    var backgroundImage = valueArr[7] == null ? null : new Uri(valueArr[7], UriKind.Relative);
                    var backBackgroundImage = valueArr[8] == null ? null : new Uri(valueArr[8], UriKind.Relative);
                    var wideBackgroundImage = valueArr[9] == null ? null : new Uri(valueArr[9], UriKind.Relative);
                    var wideBackBackgroundImage = valueArr[10] == null ? null : new Uri(valueArr[10], UriKind.Relative);

                    FlipTileData newTileData = new FlipTileData
                    {
                        Title = valueArr[1],
                        BackTitle = valueArr[2],
                        BackContent = valueArr[3],
                        WideBackContent = valueArr[4],
                        Count = Convert.ToInt32(valueArr[5]),
                        SmallBackgroundImage = smallBackgroundImage,
                        BackgroundImage = backgroundImage,
                        BackBackgroundImage = backBackgroundImage,
                        WideBackgroundImage = wideBackgroundImage,
                        WideBackBackgroundImage = wideBackBackgroundImage
                    };
                    myTile.Update(newTileData);
                }
            }

            // Payments

            // Purchase app
            if (valueArr[0] == "purchaseApp")
            {
                MarketplaceDetailTask _marketPlaceDetailTask = new MarketplaceDetailTask();
                _marketPlaceDetailTask.Show();
            }

            // Purchase product
            if (valueArr[0] == "purchaseProduct")
            {
                string productID = valueArr[1];

                if (!CurrentApp.LicenseInformation.ProductLicenses[productID].IsActive)
                {
                    try
                    {
                        var receipt = await CurrentApp.RequestProductPurchaseAsync(productID, true);
                        if (CurrentApp.LicenseInformation.ProductLicenses[productID].IsActive)
                        {
                            Browser.InvokeScript("eval", "window['wp_call_IAPPurchaseSuccess']('" + productID + "');");
                        }
                    }
                    catch
                    {
                        // The in-app purchase was not completed because the
                        // customer canceled it or an error occurred.
                        Browser.InvokeScript("eval", "window['wp_call_IAPPurchaseFail']();");
                    }
                }
                else
                {
                    //Already owns the product
                }
            }

            // Request store listing
            if (valueArr[0] == "requestStoreListing")
            {
                try
                {

                    li = await Store.CurrentApp.LoadListingInformationAsync();

                    foreach (string key in li.ProductListings.Keys)
                    {
                        ProductListing pListing = li.ProductListings[key];

                        productItems[pListing.ProductId] = new ProductItem
                        {
                            Name = pListing.Name,
                            Description = pListing.Description,
                            FormattedPrice = pListing.FormattedPrice,
                            Tag = pListing.Tag,
                            Purchased = CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? "True" : "False"
                        };
                    }

                    storeListingRecieved();
                }
                catch (Exception)
                {
                    // Failed to load listing information
                }
            }

            // Rate App
            if (valueArr[0] == "rateApp")
            {
                MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
                marketplaceReviewTask.Show();
            }

        }
Пример #5
0
        private async Task RenderStoreItems()
        {
            picItems.Clear();

            try
            {
                //StoreManager mySM = new StoreManager();
                ListingInformation li = await Store.CurrentApp.LoadListingInformationAsync();

                txtError.Visibility = Visibility.Collapsed; //if error, it would go to catch.

                string         key                 = "";
                ProductListing pListing            = null;
                string         imageLink           = "";
                string         status              = "";
                string         pname               = "";
                Visibility     buyButtonVisibility = Visibility.Collapsed;


                // get bronze in-app purcase
                key       = "bronzedonation";
                imageLink = "/Assets/Icons/bronze_dollar_icon.png";
                if (li.ProductListings.TryGetValue(key, out pListing))
                {
                    ProductLicense license = Store.CurrentApp.LicenseInformation.ProductLicenses[key];
                    status = license.IsActive ? "Donated, thank you!" : pListing.FormattedPrice;
                    //string receipt = await Store.CurrentApp.GetProductReceiptAsync(license.ProductId);

                    buyButtonVisibility = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? Visibility.Collapsed : Visibility.Visible;
                    pname = pListing.Name;
                }
                else
                {
                    status = "Product is in certification with MS. Please try again in tomorrow.";
                    buyButtonVisibility = Visibility.Collapsed;
                    pname = "Bronze Donation";
                }

                picItems.Add(
                    new ProductItem
                {
                    imgLink             = imageLink,
                    Name                = pname,
                    Status              = status,
                    key                 = key,
                    BuyNowButtonVisible = buyButtonVisibility
                }
                    );


                // get silver in-app purcase
                key       = "silverdonation";
                imageLink = "/Assets/Icons/silver_dollar_icon.png";
                if (li.ProductListings.TryGetValue(key, out pListing))
                {
                    status = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? "Donated, thank you!" : pListing.FormattedPrice;
                    buyButtonVisibility = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? Visibility.Collapsed : Visibility.Visible;
                    pname = pListing.Name;
                }
                else
                {
                    status = "Product is in certification with MS. Please try again in tomorrow.";
                    buyButtonVisibility = Visibility.Collapsed;
                    pname = "Silver Donation";
                }

                picItems.Add(
                    new ProductItem
                {
                    imgLink             = imageLink,
                    Name                = pname,
                    Status              = status,
                    key                 = key,
                    BuyNowButtonVisible = buyButtonVisibility
                }
                    );

                // get gold in-app purcase
                key       = "golddonation";
                imageLink = "/Assets/Icons/gold_dollar_icon.png";
                if (li.ProductListings.TryGetValue(key, out pListing))
                {
                    status = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? "Donated, thank you!" : pListing.FormattedPrice;
                    buyButtonVisibility = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? Visibility.Collapsed : Visibility.Visible;
                    pname = pListing.Name;
                }
                else
                {
                    status = "Product is in certification with MS. Please try again in tomorrow.";
                    buyButtonVisibility = Visibility.Collapsed;
                    pname = "Gold Donation";
                }

                picItems.Add(
                    new ProductItem
                {
                    imgLink             = imageLink,
                    Name                = pname,
                    Status              = status,
                    key                 = key,
                    BuyNowButtonVisible = buyButtonVisibility
                }
                    );
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
                txtError.Visibility = Visibility.Visible;
            }
            finally
            {
                txtLoading.Visibility = Visibility.Collapsed;
            }
        } //end renderstoresitem
Пример #6
0
        private async Task <WinProductDescription[]> DoRetrieveProducts(bool productsOnly)
        {
            ListingInformation result = await currentApp.LoadListingInformationAsync();

            if (productsOnly == false)
            {
                Log("Building full product list with existing purchases");
                // We need a comprehensive list of transaction IDs for owned items.
                // Microsoft make this difficult by failing to provide transaction IDs
                // on product licenses that are owned.
                // Therefore two data sets are joined; unfulfilled consumables (which have product IDs)
                // and transactions from the App receipt (Durables).
                var unfulfilledConsumables = await currentApp.GetUnfulfilledConsumablesAsync();

                var transactionMap = unfulfilledConsumables.ToDictionary(x => x.ProductId, x => x.TransactionId.ToString());

                // Add transaction IDs from our app receipt.
                string appReceipt = null;
                try {
                    appReceipt = await currentApp.RequestAppReceiptAsync();
                } catch (Exception e) {
                    Log("Unable to retrieve app receipt:{0}", e.Message);
                }

                var receiptTransactions = XMLUtils.ParseProducts(appReceipt);
                foreach (var receiptTran in receiptTransactions)
                {
                    transactionMap[receiptTran.productId] = receiptTran.transactionId;
                }

                // Create fake transaction Ids for any owned items that we can't find transaction IDs for.
                foreach (var license in currentApp.LicenseInformation.ProductLicenses)
                {
                    if (!transactionMap.ContainsKey(license.Key))
                    {
                        transactionMap[license.Key] = license.Key.GetHashCode().ToString();
                        Log("Fake transactionID: Set transactionMap[{0}] = {1}", license.Key, transactionMap[license.Key]);
                    }
                }


                // Construct our products including receipts and transaction ID where owned
                var productDescriptions = from listing in result.ProductListings.Values
                                          let priceDecimal = TryParsePrice(listing.FormattedPrice)
                                                             let transactionId = transactionMap.ContainsKey(listing.ProductId) ? transactionMap[listing.ProductId] : null
                                                                                 let receipt = transactionId == null ? null : appReceipt
                                                                                               select new WinProductDescription(listing.ProductId,
                                                                                                                                listing.FormattedPrice, listing.Name, string.Empty, RegionInfo.CurrentRegion.ISOCurrencySymbol,
                                                                                                                                priceDecimal, receipt, transactionId);

                // Transaction IDs tracked for finalising transactions
                transactionIdToProductId = transactionMap.ToDictionary(x => x.Value, x => x.Key);
                return(productDescriptions.ToArray());
            }
            else
            {
                Log("Building product list without purchases");
                var productDescriptions = from listing in result.ProductListings.Values
                                          let priceDecimal = TryParsePrice(listing.FormattedPrice)
                                                             select new WinProductDescription(listing.ProductId,
                                                                                              listing.FormattedPrice, listing.Name, string.Empty, RegionInfo.CurrentRegion.ISOCurrencySymbol,
                                                                                              priceDecimal, null, null);
                return(productDescriptions.ToArray());
            }
        }
Пример #7
0
        private async Task RenderStoreItems()
        {
            picItems.Clear();

            try
            {
                //StoreManager mySM = new StoreManager();
                ListingInformation li = await Store.CurrentApp.LoadListingInformationAsync();

                txtError.Visibility = Visibility.Collapsed; //if error, it would go to catch.

                string         key                 = "";
                ProductListing pListing            = null;
                string         imageLink           = "";
                string         status              = "";
                string         pname               = "";
                Visibility     buyButtonVisibility = Visibility.Collapsed;

                // get gold in-app purcase
                key       = "noads_premium";
                imageLink = "/Assets/Icons/noad_plus_icon.png";
                if (li.ProductListings.TryGetValue(key, out pListing))
                {
                    ProductLicense license = Store.CurrentApp.LicenseInformation.ProductLicenses[key];
                    NoAdsPremiumBought  = license.IsActive;
                    status              = license.IsActive ? AppResources.PurchasedThankYouText : pListing.FormattedPrice;
                    buyButtonVisibility = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? Visibility.Collapsed : Visibility.Visible;
                    pname = pListing.Name;
                }
                else
                {
                    status = AppResources.ProductNotAvailableText;
                    buyButtonVisibility = Visibility.Collapsed;
                    pname = "No Ads + Premium Features";
                }

                picItems.Add(
                    new ProductItem
                {
                    imgLink             = imageLink,
                    Name                = pname,
                    Status              = status,
                    key                 = key,
                    BuyNowButtonVisible = buyButtonVisibility
                }
                    );

                // no ads
                key       = "removeads";
                imageLink = "/Assets/Icons/noad_icon.png";
                if (li.ProductListings.TryGetValue(key, out pListing))
                {
                    ProductLicense license = Store.CurrentApp.LicenseInformation.ProductLicenses[key];
                    NoAdsBought = license.IsActive;
                    status      = license.IsActive ? AppResources.PurchasedThankYouText : pListing.FormattedPrice;
                    //string receipt = await Store.CurrentApp.GetProductReceiptAsync(license.ProductId);

                    buyButtonVisibility = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? Visibility.Collapsed : Visibility.Visible;
                    pname = pListing.Name;
                }
                else
                {
                    status = AppResources.ProductNotAvailableText;
                    buyButtonVisibility = Visibility.Collapsed;
                    pname = "Remove ads";
                }

                picItems.Add(
                    new ProductItem
                {
                    imgLink             = imageLink,
                    Name                = pname,
                    Status              = status,
                    key                 = key,
                    BuyNowButtonVisible = buyButtonVisibility
                }
                    );


                // get silver in-app purcase
                key       = "premiumfeatures";
                imageLink = "/Assets/Icons/plus_sign.png";
                if (li.ProductListings.TryGetValue(key, out pListing))
                {
                    ProductLicense license = Store.CurrentApp.LicenseInformation.ProductLicenses[key];
                    PremiumBought = license.IsActive;

                    status = license.IsActive ? AppResources.PurchasedThankYouText : pListing.FormattedPrice;
                    buyButtonVisibility = Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? Visibility.Collapsed : Visibility.Visible;
                    pname = pListing.Name;
                }
                else
                {
                    status = AppResources.ProductNotAvailableText;
                    buyButtonVisibility = Visibility.Collapsed;
                    pname = "Premium Features";
                }

                picItems.Add(
                    new ProductItem
                {
                    imgLink             = imageLink,
                    Name                = pname,
                    Status              = status,
                    key                 = key,
                    BuyNowButtonVisible = buyButtonVisibility
                }
                    );
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
                txtError.Visibility = Visibility.Visible;
            }
            finally
            {
                txtLoading.Visibility = Visibility.Collapsed;
            }
        } //end renderstoresitem
Пример #8
0
        private async void GetListingInfo()
        {
            //Load associated product listings
            try
            {
                mListingInformation = await CurrentApp.LoadListingInformationAsync();
            }
            catch (Exception e)
            {
                Debug.Assert(false, "StoreManager::GetListingInfo: " + e.Message + ", " + e.StackTrace);
            }

            if (mListingInformation != null)
            {
                // Dictionary<string, ProductListing> ListingInformation.ProductListings
                foreach (ProductListing info in mListingInformation.ProductListings.Values)
                {
                    Debug.WriteLine(info.Name + ", " + info.Description);
                }
            }
        }
Пример #9
0
        // **********************************************************************
        // JavaScript communicating with C#
        // **********************************************************************

        private async void Browser_ScriptNotify(object sender, NotifyEventArgs e)
        {
            // Get a comma delimited string from js and convert to array
            string valueStr = e.Value;

            string[] valueArr = valueStr.Split(',');

            // Trim and convert empty strings to null
            for (int i = 0; i < valueArr.Length; i++)
            {
                valueArr[i] = valueArr[i].Trim();
                if (string.IsNullOrWhiteSpace(valueArr[i]))
                {
                    valueArr[i] = null;
                }
            }

            // Activate trial mode
            if (valueArr[0] == "checkLicense")
            {
                // Check if trial
                if (valueArr[1] == "true")
                {
                    C2SettingIsTrial = true;
                }
                CheckLicense();
            }

            // Game loaded
            if (valueArr[0] == "gameLoaded")
            {
                Browser.Visibility = System.Windows.Visibility.Visible;

                checkMusic();

                if (App.WasTombstoned)
                {
                    Browser.InvokeScript("eval", "window['tombstoned'] = true");
                    App.WasTombstoned = false;
                }
            }

            // Stop music
            if (valueArr[0] == "stopMusic")
            {
                if (MediaPlayer.GameHasControl)
                {
                    FrameworkDispatcher.Update();
                    MediaPlayer.Stop();
                }
            }

            // Play music
            if (valueArr[0] == "playMusic")
            {
                if (MediaPlayer.GameHasControl)
                {
                    var file = valueArr[1];
                    var loop = valueArr[2] == "0" ? false : true;

                    var db     = Single.Parse(valueArr[3], CultureInfo.InvariantCulture);
                    var volume = Convert.ToSingle(dbToScale(db));

                    var uri  = new Uri(file, UriKind.Relative);
                    var song = Song.FromUri(file, uri);
                    MediaPlayer.IsRepeating = loop;
                    MediaPlayer.Volume      = volume;
                    FrameworkDispatcher.Update();
                    MediaPlayer.Stop();
                    MediaPlayer.Play(song);
                }
            }

            // Stop music
            if (valueArr[0] == "stopMusic")
            {
                if (MediaPlayer.GameHasControl)
                {
                    FrameworkDispatcher.Update();
                    MediaPlayer.Stop();
                }
            }

            // Play sound
            if (valueArr[0] == "playSound")
            {
                var file = valueArr[1];
                var loop = valueArr[2] == "0" ? false : true;

                var db     = Single.Parse(valueArr[3], CultureInfo.InvariantCulture);
                var volume = Convert.ToSingle(dbToScale(db));

                var tag = valueArr[4];

                Stream      stream = TitleContainer.OpenStream(file);
                SoundEffect effect = SoundEffect.FromStream(stream);

                sound          = effect.CreateInstance();
                sound.IsLooped = loop;
                sound.Volume   = volume;

                if (!string.IsNullOrEmpty(tag))
                {
                    if (SoundList.ContainsKey(tag))
                    {
                        SoundList[tag].Stop();
                    }
                    SoundList[tag] = sound;
                }

                FrameworkDispatcher.Update();
                sound.Play();
            }

            // Stop sound
            if (valueArr[0] == "stopSound")
            {
                var tag = valueArr[1];
                if (SoundList.ContainsKey(tag))
                {
                    FrameworkDispatcher.Update();
                    SoundList[tag].Stop();
                }
            }

            // Vibrate
            if (valueArr[0] == "vibrate")
            {
                float             seconds = float.Parse(valueArr[1], CultureInfo.InvariantCulture);
                VibrateController vibrate = VibrateController.Default;
                vibrate.Start(TimeSpan.FromSeconds(seconds));
            }

            // Quit app
            if (valueArr[0] == "quitApp")
            {
                App.Current.Terminate();
            }

            // Live Tiles (http://tinyurl.com/afvhgz8)
            // *******************************************************

            // Flipped Tile
            if (valueArr[0] == "flippedTileUpdate")
            {
                ShellTile myTile = ShellTile.ActiveTiles.First();
                if (myTile != null)
                {
                    var smallBackgroundImage    = valueArr[6] == null ? null : new Uri(valueArr[6], UriKind.Relative);
                    var backgroundImage         = valueArr[7] == null ? null : new Uri(valueArr[7], UriKind.Relative);
                    var backBackgroundImage     = valueArr[8] == null ? null : new Uri(valueArr[8], UriKind.Relative);
                    var wideBackgroundImage     = valueArr[9] == null ? null : new Uri(valueArr[9], UriKind.Relative);
                    var wideBackBackgroundImage = valueArr[10] == null ? null : new Uri(valueArr[10], UriKind.Relative);

                    FlipTileData newTileData = new FlipTileData
                    {
                        Title                   = valueArr[1],
                        BackTitle               = valueArr[2],
                        BackContent             = valueArr[3],
                        WideBackContent         = valueArr[4],
                        Count                   = Convert.ToInt32(valueArr[5]),
                        SmallBackgroundImage    = smallBackgroundImage,
                        BackgroundImage         = backgroundImage,
                        BackBackgroundImage     = backBackgroundImage,
                        WideBackgroundImage     = wideBackgroundImage,
                        WideBackBackgroundImage = wideBackBackgroundImage
                    };
                    myTile.Update(newTileData);
                }
            }

            // Payments

            // Purchase app
            if (valueArr[0] == "purchaseApp")
            {
                MarketplaceDetailTask _marketPlaceDetailTask = new MarketplaceDetailTask();
                _marketPlaceDetailTask.Show();
            }

            // Purchase product
            if (valueArr[0] == "purchaseProduct")
            {
                string productID = valueArr[1];

                if (!CurrentApp.LicenseInformation.ProductLicenses[productID].IsActive)
                {
                    try
                    {
                        var receipt = await CurrentApp.RequestProductPurchaseAsync(productID, true);

                        if (CurrentApp.LicenseInformation.ProductLicenses[productID].IsActive)
                        {
                            Browser.InvokeScript("eval", "window['wp_call_IAPPurchaseSuccess']('" + productID + "');");
                        }
                    }
                    catch
                    {
                        // The in-app purchase was not completed because the
                        // customer canceled it or an error occurred.
                        Browser.InvokeScript("eval", "window['wp_call_IAPPurchaseFail']();");
                    }
                }
                else
                {
                    //Already owns the product
                }
            }

            // Request store listing
            if (valueArr[0] == "requestStoreListing")
            {
                try
                {
                    li = await Store.CurrentApp.LoadListingInformationAsync();

                    foreach (string key in li.ProductListings.Keys)
                    {
                        ProductListing pListing = li.ProductListings[key];

                        productItems[pListing.ProductId] = new ProductItem
                        {
                            Name           = pListing.Name,
                            Description    = pListing.Description,
                            FormattedPrice = pListing.FormattedPrice,
                            Tag            = pListing.Tag,
                            Purchased      = CurrentApp.LicenseInformation.ProductLicenses[key].IsActive ? "True" : "False"
                        };
                    }

                    storeListingRecieved();
                }
                catch (Exception)
                {
                    // Failed to load listing information
                }
            }

            // Rate App
            if (valueArr[0] == "rateApp")
            {
                MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
                marketplaceReviewTask.Show();
            }
        }
Пример #10
0
        private static async void LoadListing(Action<ListingInformation, Exception> onComplete)
        {

            try
            {
#if DEBUG
                var task = CurrentApp.LoadListingInformationAsync();
#else
                var task = CurrentApp.LoadListingInformationAsync().AsTask();
#endif
                await task;

                var information = task.Result;

                if (information != null)
                {
                    var listing = new ListingInformation();
                    listing.AgeRating = information.AgeRating;
                    listing.CurrentMarket = information.CurrentMarket;
                    listing.Description = information.Description;
                    listing.FormattedPrice = information.FormattedPrice;
                    listing.Name = information.Name;
                    listing.ProductListings = new Dictionary<string, ProductListing>();
                    var productListings = information.ProductListings;

                    foreach (var productListing in productListings)
                    {
                        var value = productListing.Value;
                        var product = new ProductListing();
                        product.ProductId = value.ProductId;
                        product.ProductType = (ProductType)value.ProductType;
                        product.FormattedPrice = value.FormattedPrice;
                        product.Name = value.Name;
                        listing.ProductListings.Add(productListing.Key, product);
                    }
                    if (onComplete != null)
                    {
                        EtceteraWindows.RunOnUnityThread(() => onComplete(listing, null));
                    }
                }
                else
                {
                    if (onComplete != null)
                    {
                        EtceteraWindows.RunOnUnityThread(() => onComplete(null, new Exception("ListingInformation is null")));
                    }
                }
            }
            catch (Exception ex)
            {
                if (onComplete != null)
                {
                    EtceteraWindows.RunOnUnityThread(() => onComplete(null, ex));
                }
            }

            
        }
Пример #11
0
        private async void Fulfill(string item, string receipt)
        {
            var t = CurrentApp.LoadListingInformationAsync();
            int v;

            switch (item)
            {
            case IAPs.IAP_AdditionalLogin:
                products.ItemsSource  = null;
                progressRing.IsActive = true;
                var prevData = await Storage.LoadAsync <byte[]>(IAPs.IAP_AdditionalLogin);

                if (prevData == null)
                {
                    v = 2;
                }
                else
                {
                    var dData = ProtectedData.Unprotect(prevData, null);
                    int value = BitConverter.ToInt32(dData, 0);
                    v = value + 1;
                }

                Save(v);
                using (var c = new HttpClient())
                {
                    var result = await c.PostAsync("https://wauth.apphb.com/api/AddPayment", new StringContent(JsonConvert.SerializeObject(new PayingUser {
                        Username = (App.Current as App).currentInfo.Username, Count = v
                    }), Encoding.UTF8, "application/json"));
                }
                progressRing.IsActive = false;
                products.ItemsSource  = prods.ProductListings.Values.Select(x => new { x.Name, Status = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? "Purchased" : x.FormattedPrice, x.ImageUri, x.ProductId, BuyNowButtonVisible = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible });
                break;

            case IAPs.IAP_PushNotification:
                products.ItemsSource  = null;
                progressRing.IsActive = true;
                var ch = WPUtils.ChannelStartup();
                SystemTray.SetProgressIndicator(this, new ProgressIndicator {
                    IsVisible = true, Text = AppResources.PushConnect, IsIndeterminate = true
                });
                var tsk = WPUtils.UploadCurrentData();

                while (ch.ConnectionStatus != ChannelConnectionStatus.Connected && ch.ChannelUri == null)
                {
                    await Task.Delay(1000);
                }

                await WPUtils.PushNotificationSetUp(this);

                SystemTray.SetProgressIndicator(this, null);

                progressRing.IsActive = false;
                products.ItemsSource  = prods.ProductListings.Values.Select(x => new { x.Name, Status = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? "Purchased" : x.FormattedPrice, x.ImageUri, x.ProductId, BuyNowButtonVisible = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible });
                await tsk;
                break;

            default:
                break;
            }

            prods = await t;
            var prod = prods.ProductListings.Single(x => x.Value.ProductId == item);

            if (prod.Value.ProductType == ProductType.Consumable)
            {
                CurrentApp.ReportProductFulfillment(item);
            }
        }