Example #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>()
                                         };
        }
Example #2
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();
            }

        }
        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);
                }
            }
        }
Example #4
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));
                }
            }

            
        }