Windows Phone 7 Development : Building a Trial Application (part 3) - Verifying Trial and Full Mode & Adding Finishing Touches

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
2/21/2011 11:47:23 AM

4. Verifying Trial and Full Mode

Creating trial applications is the central theme of this article and we have spent the first part of it looking at various issues that may arise as part of trialing an application. When you allow application trials, one of your most important tasks is to ensure that certain application features are accessible to full license holders only; otherwise, there would be no reason to buy an application.

For the Currency Converter application, you must ensure that that the MoreStuff.xaml page is visible only when the application runs with a full license. You have already seen the code that performs that check; in this section, you must verify that the trial mode indeed behaves as expected. You will learn the technique of writing your own version of the LicenseInformation class just discussed to validate the trial mode of an application.

  1. With the Currency Converter application open, right-click the project name in Solution Explorer, select Add => New Item, and then select Class from the list of available items. Name the new class "LicenseInformation" and click OK.

  2. Make the LicenseInformation class look like the one here:

public sealed class LicenseInformation
// Fields
private boolm_fIsTrial = true;

// Methods
public boolIsTrial()
int num = 0;
if (num != 0)
this.m_fIsTrial = true;
return this.m_fIsTrial;

// Nested Types
internal static class NativeMethods
// Fields
internal const intS_FALSE = 1;
internal const intS_OK = 0;

You will test the trial mode shortly, right after we put finishing touches on our Currency Converter application.

5. Adding Finishing Touches

You are nearly ready to test the Currency Converter application—just a few items remain. In this section, we will complete the application and take it for a test drive. Follow these steps to get there.

Before an application is functional, it needs to know what currency to convert to what. We have created two list boxes inside the MainPage.xaml file to allow the user to make her selection. To keep things simple in the first version, you include only three currencies: the US dollar, the euro, and the Russian ruble. When an application loads, you need to load list boxes with those currencies.

  1. Open MainPage.xaml.cs and paste the following LoadCurrencies method inside the MainPage() constructor.

    private void LoadCurrencies()


MoreStuff.xaml needs code to perform calculations on the currency rates passed in and entered into the application. This code belongs inside thebtnCalculateDamage_Click event.

  1. In Design view, double-click the Calculate Damage button and replace the btnCalculateDamage_Click event code with the following:

    private void btnCalculateDamage_Click(object sender, RoutedEventArgs e)
    decimal decTotalToReceive;
    decimal decTotalAccordingToConversionRate;

    decTotalToReceive = Convert.ToDecimal(txtExchangeRateQuoted.Text) *
    decTotalAccordingToConversionRate = Convert.ToDecimal(dblExchgRate) *

    txtDamageExplained.Text = "With exchange rate quoted, you will receive " +
    decTotalToReceive.ToString() + "\r\n";
    txtDamageExplained.Text = txtDamageExplained.Text + "Given market exchange
    rate, you should receive " + decTotalAccordingToConversionRate.ToString() + "\r\n";

    txtDamageExplained.Text = txtDamageExplained.Text + "You lose " +
    (decTotalAccordingToConversionRate - decTotalToReceive).ToString();

Finally, Upgrade.xaml needs code to bring up the Windows Phone Marketplace and load the application review page, which will enable the user to purchase a full version of the application if the user elects to do so.

  1. Add the following using directive to the top of the Upgrade.xaml.cs file:

    using Microsoft.Phone.Tasks;

  2. Next, bring up the Upgade.xaml page in design mode and double-click the "Yes, Upgrade" button. Make that button's click event look like the following:

private void btnUpgrade_Click(object sender, RoutedEventArgs e)
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();

You're now done writing code for the Currency Converter application. The application should compile and run if you press F5 now. If, for some reason, there are errors preventing an application from launching, it's best to compare your code to code available for download for this article.

Assuming the code runs, the current value of the IsTrial method returned by our own implementation of the LicenseInformation class is true. Therefore, if we run the application and click the More Stuff button, we should see a message prompting us to upgrade to the full version of an application. That is the expected behavior. Let's go ahead and change the value of m_fIsTrial to false. We should now see the "More Stuff" screen, just as we expected the application with full license to behave.

We can also verify that the program works as expected by entering values and asking it to convert those from one currency to another. For instance, today, as shown in Figure 5, $345 is only 267.86 euros. To get that output, type "345" in the "Amount to Convert" text box, select "USD" from the "Convert From" list box and select "EUR" from the "Convert To" list box. Then, press the Convert button. Assuming that the connection to the Internet is available, you should get results that are similar.

While the Currency Converter application is functional, it can stand many improvements, particularly in the area of validating user input. For instance, an application throws an error if the user tries to go to the "More Stuff" screen without entering a value in the "Amount to Convert" text box. Addressing this and other issues is left as an exercise for the reader.

Figure 5. Currency Converter application converting $345 to euros

  •  jQuery 1.3 : Table Manipulation - Sorting and paging (part 2) : Server-side pagination & JavaScript pagination
  •  jQuery 1.3 : Table Manipulation - Sorting and paging (part 1) : Server-side sorting & JavaScript sorting
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 3) - Simulating Application Trial and Full Modes
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 2) - Using the Marketplace APIs
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 1) - Using the IsTrial Method
  •  Mobile Application Security : SymbianOS Security - Application Packaging
  •  Mobile Application Security : SymbianOS Security - Code Security
  •  iPhone Application Development : Getting the User’s Attention - Generating Alerts
  •  iPhone Application Development : Getting the User’s Attention - Exploring User Alert Methods
  •  iPhone Application Development : Using Advanced Interface Objects and Views - Using Scrolling Views
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us