Example #1
0
        private async void loadTestData(InAppPurchaseDesc desc, InAppPurchaseCreatedCallbackMethod createdCallback)
        {
            bool pass = true;

            try
            {
                // create xml obj
                var currentApp = new InAppTestObjects.CurrentApp();
                currentApp.ListingInformation.Products = new InAppTestObjects.ListingInformation_Product[desc.WinRT_MicrosoftStore_InAppIDs.Length];
                currentApp.LicenseInformation.Products = new InAppTestObjects.LicenseInformation_Product[desc.WinRT_MicrosoftStore_InAppIDs.Length];
                for (int i = 0; i != currentApp.ListingInformation.Products.Length; ++i)
                {
                    var listingProduct = new InAppTestObjects.ListingInformation_Product();
                    listingProduct.ProductId                  = desc.WinRT_MicrosoftStore_InAppIDs[i].ID;
                    listingProduct.ProductType                = desc.WinRT_MicrosoftStore_InAppIDs[i].Type == InAppPurchaseTypes.NonConsumable ? null : "Consumable";
                    listingProduct.MarketData.Name            = desc.WinRT_MicrosoftStore_InAppIDs[i].ID;
                    listingProduct.MarketData.Description     = null;
                    listingProduct.MarketData.Price           = desc.WinRT_MicrosoftStore_InAppIDs[i].Price.ToString();
                    listingProduct.MarketData.CurrencySymbol  = desc.WinRT_MicrosoftStore_InAppIDs[i].CurrencySymbol;
                    currentApp.ListingInformation.Products[i] = listingProduct;

                    var licenseProduct = new InAppTestObjects.LicenseInformation_Product();
                    licenseProduct.ProductId = desc.WinRT_MicrosoftStore_InAppIDs[i].ID;
                    currentApp.LicenseInformation.Products[i] = licenseProduct;
                }

                // serialize obj
                var    xml  = new XmlSerializer(typeof(InAppTestObjects.CurrentApp));
                byte[] data = null;
                using (var stream = new MemoryStream())
                {
                    xml.Serialize(stream, currentApp);
                    stream.Position = 0;
                    data            = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                }

                // write and read test InApp data
                StorageFile writeFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("TEST_InAppPurchase.xml", CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteBytesAsync(writeFile, data);

                StorageFile readFile = await ApplicationData.Current.LocalFolder.GetFileAsync("TEST_InAppPurchase.xml");

                await CurrentAppSimulator.ReloadSimulatorAsync(readFile);

                licenseInformation = CurrentAppSimulator.LicenseInformation;
                licenseInformation.LicenseChanged += licenseChanged;
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                pass = false;
            }

            if (createdCallback != null)
            {
                createdCallback(pass);
            }
        }
		private async void loadTestData(InAppPurchaseDesc desc, InAppPurchaseCreatedCallbackMethod createdCallback)
		{
			bool pass = true;
			try
			{
				// create xml obj
				var currentApp = new InAppTestObjects.CurrentApp();
				currentApp.ListingInformation.Products = new InAppTestObjects.ListingInformation_Product[desc.WinRT_MicrosoftStore_InAppIDs.Length];
				currentApp.LicenseInformation.Products = new InAppTestObjects.LicenseInformation_Product[desc.WinRT_MicrosoftStore_InAppIDs.Length];
				for (int i = 0; i != currentApp.ListingInformation.Products.Length; ++i)
				{
					var listingProduct = new InAppTestObjects.ListingInformation_Product();
					listingProduct.ProductId = desc.WinRT_MicrosoftStore_InAppIDs[i].ID;
					listingProduct.ProductType = desc.WinRT_MicrosoftStore_InAppIDs[i].Type == InAppPurchaseTypes.NonConsumable ? null : "Consumable";
					listingProduct.MarketData.Name = desc.WinRT_MicrosoftStore_InAppIDs[i].ID;
					listingProduct.MarketData.Description = null;
					listingProduct.MarketData.Price = desc.WinRT_MicrosoftStore_InAppIDs[i].Price.ToString();
					listingProduct.MarketData.CurrencySymbol = desc.WinRT_MicrosoftStore_InAppIDs[i].CurrencySymbol;
					currentApp.ListingInformation.Products[i] = listingProduct;

					var licenseProduct = new InAppTestObjects.LicenseInformation_Product();
					licenseProduct.ProductId = desc.WinRT_MicrosoftStore_InAppIDs[i].ID;
					currentApp.LicenseInformation.Products[i] = licenseProduct;
				}

				// serialize obj
				var xml = new XmlSerializer(typeof(InAppTestObjects.CurrentApp));
				byte[] data = null;
				using (var stream = new MemoryStream())
				{
					xml.Serialize(stream, currentApp);
					stream.Position = 0;
					data = new byte[stream.Length];
					stream.Read(data, 0, data.Length);
				}

				// write and read test InApp data
				StorageFile writeFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("TEST_InAppPurchase.xml", CreationCollisionOption.ReplaceExisting);
				await FileIO.WriteBytesAsync(writeFile, data);
			
				StorageFile readFile = await ApplicationData.Current.LocalFolder.GetFileAsync("TEST_InAppPurchase.xml");
				await CurrentAppSimulator.ReloadSimulatorAsync(readFile);
				licenseInformation = CurrentAppSimulator.LicenseInformation;
				licenseInformation.LicenseChanged += licenseChanged;
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				pass = false;
			}

			if (createdCallback != null) createdCallback(pass);
		}