Managing Trial Applications for Windows Phone 7

8/30/2010 11:53:00 AM

(Download Source Code)

(Video Walk-Through)

Windows Phone 7 provides the LicenseInformation class that includes the IsTrial() method.  IsTrial() allows you to check, at runtime, if the running application has been installed from the Marketplace as a trial application, or if the user has purchased the application.  Developers are able to use IsTrial() to change the behavior of their application based on whether or not the user is running a trial version or a paid for version.  Unfortunately for WP7 devs, there is no easy way to control the IsTrial() results when developing and debugging their applications. IsTrial() will always return False when developing an application.  Even more disappointing, LicenseInformation is a sealed class and there is no ILicenseInfo interface that you could use to mock out your own implementation while developing.

In addition, each developer is left to his or her own devices to come up with a system for controlling how their trial software behaves.  Simple things like turning of features in the trial version is pretty straightforward, but if you want to have a more complex behavior, things get trickier.  What if you want someone to be able to use your application for 30 days before you disable features?  How about 10 uses of the application before they need to buy the full version?  You are on your own.

TrialManager is a simple piece of code that you can add to any WP7 project to help manage the behavior of your trial apps.  TrialManager will also make it easier to simulate you application running in Trial mode when creating your apps.  You can get the source to TrialManager here.  Feel free to use it, modify, etc.  The only licensing restriction is that I ask you send me an email letting me know you are using the code in some form or fashion.

Setting Up TrialManager for Usage Tracking

To get start with TrialManager, just at the SlickThought.Phone.dll to your Windows Phone project.  After that, the first thing you need to do is modify your App.xaml file to instantiate TrialManager each time your application runs.  The nice thing about TrialManager is that all of its behavior is configured using App.xaml.  Here are the changes you would need to make in your app to get started…

    xmlns:trial="clr-namespace:SlickThought.Phone;assembly=SlickThought.Phone"

Next, we modify the Application.ApplicationLifetimeObjects element as shown below:

    <Application.ApplicationLifetimeObjects>
        <trial:TrialManager RunAsTrial="True" Expired="TrialManager_Expired" >
            <trial:TrialManager.ApplicationPolicy>
                <trial:UsageExpirationPolicy MaxUsage="5"/>
            </trial:TrialManager.ApplicationPolicy>
        </trial:TrialManager>
    </Application.ApplicationLifetimeObjects>

This will cause our WP7 application to instantiate the TrialManager every time the application loads.  It doesn’t matter if it is the first time the app launches of if we are pulling the app off the back stack, we will get a brand new TrialManager object.  Taking a look at the markup, there are a few things to note.  First, we can have the TrialManager to simulate that the application we are developing is running in trial mode by setting the RunAsTrial property to TrueTrialManager has its own IsTrial() method, just like the LicenseInformation class.  Normally, TrialManager.IsTrial() will create its own LicenseInformation object and return that object’s IsTrial() result.  When we set RunAsTrial to True, however, TrialManager will always return True for a call to IsTrial().  The code for TrialManager.IsTrial() is shown below:

if (this.RunAsTrial)
   return true;
else 
{
   if (_license == null)
      _license = new LicenseInformation();
   return _license.IsTrial();
}     

Second, TrialManager has an Expired event that is fired when the ExpirationPolicy object fires its own Expired event.  In the example above, we are wiring the Expired event to an event handler named TrialManager_Expired.  In the sample application, a MessageBox is shown when the application expires.  In your own application, you would probably do something like using the MarketPlaceLauncher to redirect the customer to your applications details page in order to buy a full version. 

The TrialManager’s behavior is controlled by the object assigned to the ApplicationProperty property.  This object must be derived from the ExpirationPolicy base class.  TrialManager comes with two implementations for you to use: UsageExpirationPolicy and TimeExpirationPolicy.  The UsageExpirationPolicy is the easiest to set up.  In our example, we are setting up a MaxUsage to 5.  What MaxUsage means is entirely up to you.  You control how to increment the UsageCount property.  You could do it each time the application starts or when a particular feature is used.  It is as easy as the following:

(TrialManager.Current.ApplicationPolicy as UsageExpirationPolicy).UsageCount++;

When UsageCount exceeds MaxCount, the UsageExpirationPolicy will fire its Expired events, which in turn causes TrialManager to fire its Expired event.

Setting Up and Using Trial Expiration

The other ExpirationPolicy derived class is the TimeExpirationPolicy. An example of configuring TrialManager to use the TimeExpirationPolicy is shown below:

<trial:TrialManager RunAsTrial="True" Expired="TrialManager_Expired" TimerInterval="00:05:00" >
   <trial:TrialManager.ApplicationPolicy>
       <trial:TimeExpirationPolicy TrialDuration="01:00:00" Mode="Lifetime" />
   </trial:TrialManager.ApplicationPolicy>
</trial:TrialManager>

In this case, we set up a TimeExpirationPolicy object in the XAML.  The most important property is the TrialDuration property.  Here, you set the TimeSpan that you want to make the application available before expiring.  The Mode property is optional.  By default, the Mode property is set to LifetimeLifetime durations mean that the cumulative ElapsedTime for the application is tracked each time the application is used.  If the user runs an application for five minutes the first time,  and fifteen minutes the second time, TrialManager will record this as twenty minutes of total usage and compare that value to the TrialDuration.  You can also set the Mode property to Session, which specifies that the ElapsedTime is reset to zero each time the application is launched.  When using the TimeExpirationPolicy, the TrialManager creates a DispatcherTimer and uses this to track the applications time usage.  By default, the DispatcherTimer.Interval property is set to one minute.  You can override Tick interval by setting the TimerInterval Property on the TrialManager.  In the example above, we are setting the Tick of the DispatcherTimer to five minutes.

Other Things About TriaManager

A couple of other notes about using TrialManager:

  • TrialManager has a DoNotPersist property.  By default, TrialManager will persist the state of the ExpirationPolicy to IsolatedStorage each time the application is exited (either via Deactivate or Closed).  This means the only way to get rid of persisted state information is to recycle the emulator.  Setting the DoNotPersist property to True will prevent the TrialManager from persisting state when the application is exited making debugging in certain situation easier.
  • The ExpirationPolicy base class has an Expired event.  This means you can hook up the Expired event at either the TrialManager or at the ExpirationPolicy level.  TrialManager actually hooks to the ExecutionPolicy’s Expired event and just fires its own Expired event when the ExpirationPolicy fires its event.  In the future, I see TrialManager having different ExpirationPolicy objects to control different features.  There will be an application level ExipirationPolicy, which will always cause the main TrialManager Expired event to fire.  Just an FYI…

 

Tags:

Headlines | Windows Phone

HDC Community Jam–Don’t Miss It

8/27/2010 2:42:23 PM

If you are active in the .NET community and are heading the the Heartland Developers Conference, take the opportunity to attend the HDC Community Jam.  You can get all the details here: http://bit.ly/ComJam-HDC-2 This is a great opportunity to interact with other user group leaders, presenters, bloggers, influentials, and MVPs.  Build contacts, network, provide input on how to make the community stronger, and learn a thing or two along the way on how to provide even more impact in the .NET community.

See you there!

Tags:

Headlines

STL Day of .NET Presentation

8/22/2010 6:14:32 PM

Thanks to everyone that came to my two Windows Phone 7 Jumpstart sessions. Getting to a session the first thing each morning – 8am each day – was much appreciated.  You can download the presentation here.  You can find the integrated dev tool install here http://bit.ly/CDevWP7Toolkit

Tags:

Headlines

Windows Phone 7 Boot Camps Coming to a City Near You

7/19/2010 10:50:54 AM

You can find details below.  This is a great opportunity to spend some time learning WP7.  Make sure you visit http://developer.windowsphone.com to install the Beta bits before arriving.  I will be leading the events in Minneapolis, St Louis, Overland Park, and Des Moines.  I hope to see you there!

clip_image002[4]

clip_image004[6]

clip_image005[4]

clip_image006[4]
Windows Phone 7 Bootcamp

Silverlight, XNA, and Windows Phone 7

Are you ready to gain access to the latest tools, turning your hobby into a source of revenue, or expand your network?

Stop dreaming. Start building. Join us for a new series of Windows Phone 7 Bootcamps where you can get an inside track on how to be part of the next step of Microsoft’s mobile strategy and get hands-on training for building Silverlight-based applications.  These free, live learning sessions explore the latest tools, discuss tips and technologies, and provide access to Windows Phone 7 experts.

ATTEND these special events and learn about:

Ø the Windows Phone 7 platform

Ø building Silverlight Applications for Windows Phone 7

Ø submitting your application to the Windows Phone 7 Marketplace

Take advantage of this opportunity to explore with a Hands-on Lab where you can leverage the Windows Phone 7 Experts and your peers as you build your Windows Phone 7 Application.

clip_image008[4]

clip_image010[4] clip_image012[4]

clip_image014[4]

clip_image016[4]

clip_image018[6]Location/Reg

clip_image018[7]Date

Nashville, TN

July 27

Cincinnati, OH

July 29

Minneapolis, MN

August 3

Dallas, TX

August 4

Indianapolis, IN

August 5

Overland Park, KS

August 5

Columbus, OH

September 7

Waukesha, WI

September 14

Grand Rapids, MI

September 14

Little Rock, AR

September 15

Cleveland, OH

September 15

St. Louis, MO

September 16

Downers Grove, IL

September 21

Southfield, MI

September 21

Austin, TX

September 22

Chicago, IL

September 23

Des Moines, IA

September 23

Tulsa, OK

September 28

Memphis, TN

September 29

Houston, TX

September 30

Knoxville, TN

September 30

Events run from 8am–5pm

Seating for the live event is limited, so register today.

 

clip_image004[7]

clip_image020[4]

clip_image022[4]

Tags:

Headlines

Spaghetti Code Podcast: Windows Phone 7 with Adam Grocholski

5/17/2010 9:00:52 AM

Spaghetti Code talks with Adam Grocholski about Developing on Windows Phone 7 using Silverlight.

 

  • Direct Download - click here
  • Subscribe - click here
  • iTunes - click here
  • Tags:

    SpaghettiCode | Headlines | Windows Phone

    Windows Phone 7 Presentation and Sample Code

    5/14/2010 11:18:45 AM

    I’ve been doing a lot of Windows Phone 7 presentations lately, and have finally gotten around to posting my slides and demo code.  Hit these links for your downloading pleasure…

    Tags:

    Headlines | Windows Phone

    Next Generation Testing with Visual Studio 2010 Road Show

    3/3/2010 9:28:50 AM

    Get a sneak peek at some of the new capabilities in Microsoft® Visual Studio® 2010, a landmark release of the premier development and testing toolset for Windows®, Web and Cloud development. 
    Microsoft has made significant investments to improve the Testing/QA tools in Visual Studio 2010.  The Next Generation Testing Event is your exclusive opportunity to experience the incredible power and capabilities these new tools bring to the QA and testing process.  At this event, you’ll get a comprehensive overview, as well as a deep dive, into the range of new tools and how they can enable you to improve the way you develop and test software on the Microsoft platform. 
    This will be an invaluable opportunity to learn how to take software development to the next level with Visual Studio 2010’s new testing features

    Event Agenda

    Topic

    Registration, Welcome, Food Served

    30 min.

    The QA Challenge

    30 min.

    Taking Testing to a New Level

    3 hours

    Making it Real

    30 min.

    Prize Drawing

    15 min.


    clip_image001Date

    clip_image001[1]Location

    Event ID

    3/3

    Nashville

    1032441936

    3/3

    Houston

    1032441938

    3/4

    Cincinnati

    1032441934

    3/12

    Bloomington

    1032442187

    3/12

    Southfield

    1032441932

    3/15

    Milwaukee

    1032441929

    3/15

    St. Louis

    1032441930

    3/15

    Columbus

    1032442186

    3/16

    Kansas City

    1032441931

    3/16

    Cleveland

    1032441933

    3/18

    Indianapolis

    1032441928

    4/13

    Chicago

    1032442250

    Tags:

    Headlines

    New Web App Toolkits

    2/23/2010 9:36:47 AM

    Several new Web App Toolkits were released recently:

    • “Freemium” - A popular way to attract first time users is to offer a free version of a service that has limited functionality and once you’ve got them hooked provide an easy way to upgrade and pay for more features. This Web Application Toolkit offers a more elegant and cost-effective way to solve this problem.
    • Calendars - This Web Application Toolkit provides a standards-based service that can be reused in your own Web application to expose calendaring and events information for different users, using different data formats (iCalendar, XML, JSON) using REST.
    • Bing Maps - A set of reusable custom controls built in Silverlight, which integrated with the Bing Maps Silverlight Control, make a perfect fit for some of the most common location-aware scenarios.
    • Bing Search - This Web Application Toolkit shows how to take advantage of the Bing API to add search capabilities to your Web site by leveraging the various search results that the Bing API provides, including Web content, images, news and videos, among others.

    There quite a few more around IE8, Mobile apps, Template Driven Email, and more.

     Check them out today!

    Tags:

    Headlines

    Spaghetti Code Talks Android with Donn Felker

    2/22/2010 3:55:00 PM

    Spaghetti Code hosts Donn Felker as he discusses his experiences developing applications for the Android platform.

  • Direct Download - click here
  • Subscribe - click here
  • iTunes - click here
  • Tags:

    Headlines | SpaghettiCode

    RIA Services Content Posted

    2/8/2010 3:21:37 PM

    The slide deck and demo walkthroughs from the recent RIA Roadshow events in Omaha and Minneapolis are now available for download.

    Tags:

    Headlines

    Powered by BlogEngine.NET 1.6.0.0
    Theme by Mads Kristensen

    About the author

    Jeff Brand Jeff Brand

    This is the personal web site of Jeff Brand, self-proclaimed .NET Sex Symbol and All-Around Good guy. Content from my presentations, blog, and links to other useful .NET information can all be found here.

    E-mail me Send mail


    Calendar

    <<  September 2010  >>
    MoTuWeThFrSaSu
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910

    View posts in large calendar

    My Twitter Updates

    XBOX
    Live

    Recent comments

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in