예제 #1
0
        public static void ClearCache()
        {
            StateInformation.ClearCache();
            var rs = new MockReceiptStore();

            rs.ClearStore();
        }
예제 #2
0
        internal static void ReportFulfillment(string selectedProductId)
        {
            ProductListing listing = allProducts.Values.FirstOrDefault(p => p.ProductId.Equals(selectedProductId, StringComparison.InvariantCultureIgnoreCase));

            if (listing == null)
            {
                throw new Exception(string.Format("Specified ProductID ({0}) does not exist", selectedProductId));
            }

            switch (listing.ProductType)
            {
            case ProductType.Durable:
            {
                throw new InvalidOperationException("Fulfillment is only applicable to Consumables");
            }

            case ProductType.Unknown:
            {
                throw new InvalidOperationException("ProductType is Unknown");
            }

            case ProductType.Consumable:
            {
                StateInformation.SetState(selectedProductId, true);
                var rs = new MockReceiptStore();
                rs.DeleteReceipt(selectedProductId);
                _appLicenseInformation.ProductLicenses[selectedProductId].IsActive = false;
                break;
            }
            }
        }
예제 #3
0
        public static void AddProductListing(string key, ProductListing productListing)
        {
            CheckIfInitialized();

            if (_appListingInformation == null)
            {
                throw new Exception("A call to SetListingInformation is required before calling this method");
            }

            if (allProducts == null)
            {
                allProducts = new Dictionary <string, ProductListing>();
            }

            allProducts.Add(key, productListing);

            var store = new MockReceiptStore();
            Dictionary <string, string> receipts = store.EnumerateReceipts();

            // add a license for this item as well.
            var license = new ProductLicense
            {
                ExpirationDate = DateTimeOffset.Now,
                IsActive       = receipts.ContainsKey(productListing.ProductId),
                IsConsumable   = productListing.ProductType == ProductType.Consumable,
                ProductId      = productListing.ProductId
            };

            _appLicenseInformation.ProductLicenses.Add(productListing.ProductId, license);
        }
예제 #4
0
        public static void ClearCache()
        {
            StateInformation.ClearCache();
            var rs = new MockReceiptStore();

            foreach (var lic in _appLicenseInformation.ProductLicenses.Values)
            {
                lic.IsActive = false;
            }
            rs.ClearStore();
        }
예제 #5
0
        /// <summary>
        /// Populates the Mock Library with IAP items defined in XML
        /// </summary>
        /// <param name="Xml">XML to parse</param>
        public static void PopulateIAPItemsFromXml(string Xml)
        {
            //MessageBox.Show(Xml);
            CheckIfInitialized();
            try
            {
                XElement xmlDoc = XElement.Parse(Xml);

                foreach (XElement element in xmlDoc.Elements())
                {
                    var pl = new ProductListing();

                    pl.Name           = element.Element("Name").Value;
                    pl.ProductId      = element.Element("ProductId").Value;
                    pl.Description    = element.Element("Description").Value;
                    pl.FormattedPrice = element.Element("FormattedPrice").Value;
                    string uri = element.Element("ImageUri").Value;
                    pl.ImageUri    = string.IsNullOrEmpty(uri) ? null : new Uri(uri);
                    pl.ProductType = (ProductType)Enum.Parse(typeof(ProductType), element.Element("ProductType").Value);
                    string keywords = element.Element("Keywords").Value;
                    pl.Keywords = string.IsNullOrEmpty(keywords) ? null : keywords.Split(';');
                    pl.Tag      = element.Element("Tag").Value;

                    if (pl.Tag.Length > 3000)
                    {
                        throw new Exception("Data stored in the 'Tag' can not exceed 3000 characters!");
                    }

                    AddProductListing(element.Attribute("Key").Value, pl);

                    bool purchased = bool.Parse(element.Attribute("Purchased").Value);
                    bool fulfilled = bool.Parse(element.Attribute("Fulfilled").Value);

                    if (!purchased && fulfilled)
                    {
                        throw new InvalidOperationException("Error in your XML definition: An item can't be marked as fulfilled but not purchased! Item: " + pl.Name);
                    }

                    if (purchased)
                    {
                        var store = new MockReceiptStore();
                        store.SaveReceipt(pl, false);
                        StateInformation.SetState(pl.ProductId, fulfilled);
                        _appLicenseInformation.ProductLicenses[pl.ProductId].IsActive = true;
                    }
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show("load mock list error:" + ex.Message);
            }
            //MessageBox.Show("success");
        }
예제 #6
0
        internal static string SimulatePurchase(string ProductId, bool includeReceipt)
        {
            ProductListing listing = allProducts.Values.FirstOrDefault(p => p.ProductId.Equals(ProductId, StringComparison.InvariantCultureIgnoreCase));

            if (listing == null)
            {
                throw new ArgumentException("Specified productId has no ProductListing");
            }

            string receipt      = string.Empty;
            bool   OkToPurchase = true;

            bool?state = StateInformation.GetState(listing.ProductId);

            if (state != null && state.Value == false)
            {
                // This is an unfulfiled item
                MessageBox.Show("You have already purchased this but not fulfiled it yet");
                OkToPurchase = false;
            }
            else
            {
                var rs = new MockReceiptStore();
                if (listing.ProductType == ProductType.Durable && rs.EnumerateReceipts().ContainsKey(listing.ProductId))
                {
                    MessageBox.Show("You already purchased this durable");
                    OkToPurchase = false;
                }
            }

            if (OkToPurchase)
            {
                MessageBoxResult result = MessageBox.Show(string.Format("Simulating purchase. Do you want to buy this item ({0})?", listing.Name), "Mock UI", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    var store = new MockReceiptStore();
                    receipt = store.SaveReceipt(listing, includeReceipt);
                    StateInformation.SetState(listing.ProductId, listing.ProductType == ProductType.Durable); // Set as fulfilled for Durables only
                    _appLicenseInformation.ProductLicenses[listing.ProductId].IsActive = true;
                }
                else
                {
                    throw new Exception("User has clicked on Cancel. In the real API, an exception will be thrown if that happens as well. You must put a try/catch around the RequestProductPurchaseAsync call to handle this.");
                }
            }

            return(receipt);
        }
예제 #7
0
        public static async Task<string> GetProductReceiptAsync(string selectedProductId)
        {
            MockIAP.CheckIfInitialized();

            string receipt = null;

            if (!MockIAP.MockMode)
            {
                receipt = await Windows.ApplicationModel.Store.CurrentApp.GetProductReceiptAsync(selectedProductId);
            }
            else
            {
                var rs = new MockReceiptStore();
                Dictionary<string, string> receipts = rs.EnumerateReceipts();
                if (receipts.ContainsKey(selectedProductId))
                    receipt = receipts[selectedProductId];
            }

            return receipt;
        }
예제 #8
0
        public static async Task <string> GetProductReceiptAsync(string selectedProductId)
        {
            MockIAP.CheckIfInitialized();

            string receipt = null;

            if (!MockIAP.MockMode)
            {
                receipt = await Windows.ApplicationModel.Store.CurrentApp.GetProductReceiptAsync(selectedProductId);
            }
            else
            {
                var rs = new MockReceiptStore();
                Dictionary <string, string> receipts = rs.EnumerateReceipts();
                if (receipts.ContainsKey(selectedProductId))
                {
                    receipt = receipts[selectedProductId];
                }
            }

            return(receipt);
        }
예제 #9
0
        /// <summary>
        /// Populates the Mock Library with IAP items defined in XML
        /// </summary>
        /// <param name="Xml">XML to parse</param>
        public static void PopulateIAPItemsFromXml(string Xml)
        {
            CheckIfInitialized();

            XElement xmlDoc = XElement.Parse(Xml);

            foreach (XElement element in xmlDoc.Elements())
            {
                var pl = new ProductListing();

                pl.Name = element.Element("Name").Value;
                pl.ProductId = element.Element("ProductId").Value;
                pl.Description = element.Element("Description").Value;
                pl.FormattedPrice = element.Element("FormattedPrice").Value;
                string uri = element.Element("ImageUri").Value;
                pl.ImageUri = string.IsNullOrEmpty(uri) ? null : new Uri(uri);
                pl.ProductType = (ProductType) Enum.Parse(typeof (ProductType), element.Element("ProductType").Value);
                string keywords = element.Element("Keywords").Value;
                pl.Keywords = string.IsNullOrEmpty(keywords) ? null : keywords.Split(';');
                pl.Tag = element.Element("Tag").Value;

                if (pl.Tag.Length > 3000)
                    throw new Exception("Data stored in the 'Tag' can not exceed 3000 characters!");

                AddProductListing(element.Attribute("Key").Value, pl);

                bool purchased = bool.Parse(element.Attribute("Purchased").Value);
                bool fulfilled = bool.Parse(element.Attribute("Fulfilled").Value);

                if (!purchased && fulfilled)
                    throw new InvalidOperationException("Error in your XML definition: An item can't be marked as fulfilled but not purchased! Item: " + pl.Name);

                if (purchased)
                {
                    var store = new MockReceiptStore();
                    store.SaveReceipt(pl, false);
                    StateInformation.SetState(pl.ProductId, fulfilled);
                    _appLicenseInformation.ProductLicenses[pl.ProductId].IsActive = true;
                }
            }
        }
예제 #10
0
 public static void ClearCache()
 {
     StateInformation.ClearCache();
     var rs = new MockReceiptStore();
     foreach (var lic in _appLicenseInformation.ProductLicenses.Values)
     {
         lic.IsActive = false;
     }
     rs.ClearStore();
 }
예제 #11
0
        internal static void ReportFulfillment(string selectedProductId)
        {
            ProductListing listing = allProducts.Values.FirstOrDefault(p => p.ProductId.Equals(selectedProductId, StringComparison.InvariantCultureIgnoreCase));

            if (listing == null)
                throw new Exception(string.Format("Specified ProductID ({0}) does not exist", selectedProductId));

            switch (listing.ProductType)
            {
                case ProductType.Durable:
                    {
                        throw new InvalidOperationException("Fulfillment is only applicable to Consumables");
                    }
                case ProductType.Unknown:
                    {
                        throw new InvalidOperationException("ProductType is Unknown");
                    }
                case ProductType.Consumable:
                    {
                        StateInformation.SetState(selectedProductId, true);
                        var rs = new MockReceiptStore();
                        rs.DeleteReceipt(selectedProductId);
                        _appLicenseInformation.ProductLicenses[selectedProductId].IsActive = false;
                        break;
                    }
            }
        }
예제 #12
0
        internal static string SimulatePurchase(string ProductId, bool includeReceipt)
        {
            ProductListing listing = allProducts.Values.FirstOrDefault(p => p.ProductId.Equals(ProductId, StringComparison.InvariantCultureIgnoreCase));

            if (listing == null)
                throw new ArgumentException("Specified productId has no ProductListing");

            string receipt = string.Empty;
            bool OkToPurchase = true;

            bool? state = StateInformation.GetState(listing.ProductId);
            if (state != null && state.Value == false)
            {
                // This is an unfulfiled item
                MessageBox.Show("You have already purchased this but not fulfiled it yet");
                OkToPurchase = false;
            }
            else
            {
                var rs = new MockReceiptStore();
                if (listing.ProductType == ProductType.Durable && rs.EnumerateReceipts().ContainsKey(listing.ProductId))
                {
                    MessageBox.Show("You already purchased this durable");
                    OkToPurchase = false;
                }
            }

            if (OkToPurchase)
            {
                MessageBoxResult result = MessageBox.Show(string.Format("Simulating purchase. Do you want to buy this item ({0})?", listing.Name), "Mock UI", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    var store = new MockReceiptStore();
                    receipt = store.SaveReceipt(listing, includeReceipt);
                    StateInformation.SetState(listing.ProductId, listing.ProductType == ProductType.Durable); // Set as fulfilled for Durables only 
                    _appLicenseInformation.ProductLicenses[listing.ProductId].IsActive = true;
                }
                else
                {
                    throw new Exception("User has clicked on Cancel. In the real API, an exception will be thrown if that happens as well. You must put a try/catch around the RequestProductPurchaseAsync call to handle this.");
                }
            }

            return receipt;
        }
예제 #13
0
        public static void AddProductListing(string key, ProductListing productListing)
        {
            CheckIfInitialized();

            if (_appListingInformation == null)
                throw new Exception("A call to SetListingInformation is required before calling this method");

            if (allProducts == null)
                allProducts = new Dictionary<string, ProductListing>();

            allProducts.Add(key, productListing);

            var store = new MockReceiptStore();
            Dictionary<string, string> receipts = store.EnumerateReceipts();

            // add a license for this item as well. 
            var license = new ProductLicense
                              {
                                  ExpirationDate = DateTimeOffset.Now,
                                  IsActive = receipts.ContainsKey(productListing.ProductId),
                                  IsConsumable = productListing.ProductType == ProductType.Consumable,
                                  ProductId = productListing.ProductId
                              };

            _appLicenseInformation.ProductLicenses.Add(productListing.ProductId, license);
        }
예제 #14
0
 public static void ClearCache()
 {
     StateInformation.ClearCache();
     var rs = new MockReceiptStore();
     rs.ClearStore();
 }