Windows 8 Metro design and development-Windows application store (1)

Source: Internet
Author: User
In this experiment, you will be charged for using the Windows Store API. First, modify the "about" dialog box to check the test version. If the application is not paid, a purchase button is displayed. Then, use currentappsimulator to simulate the purchase when you click the Buy button. Finally, the simulation application embedded purchase, the original free Italian Recipes as an additional charge.

In this exercise, you must useWindowsApp Store at runtimeAPICustomContosocookbookPage content. If the application has been paid, the license information is displayed. If you have not paid yet, that is, the trial version, the purchase information is displayed. In addition, the price displayed on the purchase button should not be hard-coded in the application, but should be fromWindowsList information obtained by the application.

Task1-AddWindowsstoreproxy. xml

We will useCurrentappsimulatorAnd other functions. To make the simulation as practical as possible, we willWindowsstoreproxy. xmlFile directionCurrentappsimulatorProvide price, expiration date, and other information.

1.InVisual StudioOpen in lab7Completed inContosocookbookProject. If you have not completed the experiment7Alternatively, you can find the complete version of the experiment in the raw material if you want to start with the reference copy.

2.If the project does not have a data folder, create one.

3.Right-clickDataFolder,Add-existing item"Command to import from the raw material data folderLicense. xml. We will use this file to createWindowsstoreproxy. xml4.OpenDefault. js, InApp. onactivatedOfWinjs. UI. processallAfter the call, add the following statement:

Javascript

// Initialize windowsstoreproxy. xml

Appdata. Current. localfolder. createfolderasync ("Microsoft \ windowsstore \ apidata", windows. Storage. creationcollisionoption. openifexists). Then (function (folder ){

Windows. ApplicationModel. Package. Current. installedlocation. getfileasync ("data \ license. xml"). Then (function (File ){

Folder. createfileasync ("windowsstoreproxy. xml", windows. Storage. creationcollisionoption. replaceexisting). Then (function (newfile ){

File. copyandreplaceasync (newfile );

});

});

});

Note:TheCodeUseWindowsRuntime storageAPICreate at specified locationWindowsstoreproxy. xmlFile,CurrentappsimulatorThe file will be searched at this location, andLicense. xml. You can simulate application payment and product payment without using a proxy file. However, if you want more extensive simulation, that is, to obtain price information and other information, you must include windowsstoreproxy. xml.

5.OpenLicense. xmlIt takes some time to study its contents.<Listinginformation>The element contains information about the application and we want to exercise3Information about the Italian recipe products that are purchased at a cost.<Licenseinformation>Contains license information for applications and products. In the real environment, all information comes fromWindowsApp Store. However, in simulated situations, the information comes fromWindowsstoreproxy. xml.

 

Task2-Modify"About"Page

Now modify in lab6TheAbout"Page. Now,About"Under the application title of the page,"Trial version(Trial version. We want to use storageAPIDetermine whether the application is a trial version and customize the page content based on the results.

1.OpenAbout.html.

2.Find the text"Trial version"H4Element to addId = "info"Attribute:

Html

<H4Id = "info"> Trial version </H4>

3.InH4Add the followingButtonStatement:

Html

<Button id = "purchase" class = "purchase-button"> </button>

4.OpenAbout.css, Add the followingCSSClass, set the button style:

CSS

. Purchase-button {

Width: 225px;

Height: 120px;

Margin-top: 24px;

}

5.OpenAbout. js, InReadyAdd the following statement to the function:

Javascript

VaR APP = windows. ApplicationModel. Store. currentappsimulator;

 

If (App. licenseinformation. istrial ){

// Show the purchase price on the purchase button

VaR button = Document. queryselector ("# purchase ");

 

App. loadlistinginformationasync (). Then (function (listing ){

Button. textcontent = "upgrade to Thefull version for" + listing. formattedprice;

});

}

Else {

// Show the expiration date and hide the purchase button

Document. queryselector ("# Info"). textcontent = "valid until" + app. licenseinformation. expirationdate. tolocaledatestring ();

Document. queryselector ("# purchase"). style. Visibility = "hidden ";

}

6.Take some time to study the code just added. It usesCurrentappsimulator. licenseinformation. istrialDetermines whether the application is running in the trial version.Currentappsimulator. loadlistinginformationasyncObtain the price information so that it is displayed on the purchase button. ReturnedListinginformationThe object also contains other information about the application. For more information, seeSDKInWindows. ApplicationModel. Store. listinginformation.

 

Task3-Test Results

Test the changes now.CurrentappsimulatorAndWindowsstoreproxy. xml.

1.PressF5Start the applicationProgram.

2.Show the super button bar and click"Settings"Button.

3.In theSettings"Menu, click"About", Show"About"Page.

4.Confirm in"About"The purchase button is displayed on the page. The purchase price is$12.99,1.



Figure1

"About"Page

5.ReturnVisual StudioAnd stop debugging.

6.OpenLicense. xml, Set<App>Zone in progress<Price>The purchase price in the element is from$12.99Change$8.99.

7.Start the application again and open"About"Page. What is the purchase price displayed on the current purchase button?

8.ReturnVisual StudioAnd stop debugging.

9.OpenLicense. xml, Change the price back$12.99. And set<Istrial>SlaveTrueChangeFalse.

10.Start the application and open"About"Page. Confirm that the purchase button has disappeared. What you see is"Validuntil Saturday, December 31,202 2"Message,2.


Figure2

The"About"Page

11.ReturnVisual StudioAnd stop debugging.

12.When preparing for the next exerciseLicense. xmlLieutenant General<Istrial>SlaveFalseChangeTrue.

Note: ThisArticleThis is the script for Windows 8 online lab on msdn. It is for your reference only. If you want to experience the complete experiment, click the msdn online lab below

Http://msdn.microsoft.com/zh-cn/hh968278

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.