Spaghetti Code Podcast–August 2010 Edition

8/31/2010 10:36:09 AM

Spaghetti Code kicks off its new format with hosts Jeff Brand and Adam Grocholski discussing the news and events in the .NET world and beyond.  This month, Jeff and Adam talk about Lightswitch, Windows Phone 7, the IronRuby “situation”, and more.  Listen and drop Jeff and Adam some listener feedback at podcast@slickthought.net to help us steer the show and get your thoughts “on the air” as well.

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

    SpaghettiCode

    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

    My Recent Reading List

    7/14/2010 10:21:39 AM

    A rededication to finding time to read, some free evenings, and summer vacation has really let me dive into reading.  I have knocked down quite a few books in the last month and thought I would share what I have finished.  If you are like me, you are always on the look out for something good to read. 

    1. Coyote series – Alan Steele.  A four book series that follows the colonization of a distant world against the backdrop of political and environmental upheaval on Earth.  A surprisingly engaging mix of frontier exploration with science fiction wonder.  A sometimes not so subtle discourse on politics provides a compelling way to keep the story line moving.  Wonderful character development through the series. 
    2. Atlas Shrugged – Ayn Rand.  Ok, I actually read the Cliff Notes.  Yep, its true.  I read the original back in college – required reading for a philosophy course I had.  I only “skim read” it then since at over 1000 pages it was a load, but it was a significant learning experience because of the in class discussions and comparison to other philosophical points of view we looked at.  Rand’s philosophy of Objectivism is probably one of the most misrepresented philosophies out there, as is the underlying meaning of Atlas Shrugged.
    3. The Peshawar Lancers – S.M. Stirling.  I finally finished this one after having started it over a year ago.  An alternate reality, steam punkish setting, Stirling has written a book that I have really had to slog my way through.  If you have a hankering for a book that describes the setting in excruciating detail, this is the book for you.  I have found the story very interesting, but it is lost under pages and pages of unnecessary detail.  I often find myself skipping paragraphs at a time to get back to the point of the scene.  I’m a bit of a Stirling fan, but this was not high on my list.
    4. Executive Power - Vince Flynn.  Ahhhh, nothing like a little Flynn action thriller.  Its the standard Flynn formula with Mitch Rapp once again defeating the bad guys.  Fast pace and intrigue keep you turning pages.  Easy mind candy that went by fast despite it being a thick book.
    5. Economics in One Lesson - Henry Hazlitt.  A very short read and while the examples used are a bit dated, the fundamental ideas are timeless.  It had been forever since I had any economics courses, so I thought I would refresh my understanding given the current debates going on.  Finished it in a couple of days and was pleased with how so many of the debates of today could be found inside this book and clear, concise, and complete answers on why something is good or bad.

    So what’s next… I have two on the table right now. 

    1. The Prefect - Alastair Reynolds.  I have enjoyed Reynold’s previous works and the reviews on this one have been good.  I am a grand total of 20 pages into it so I have yet to form an opinion but so far it is good. ;-)  The question is, will it conclude with “the big, long interstellar spaceship chase” that Reynold’s seems to put in all of his books. ;-)
    2. Capitalism and Freedom - Milton Friedman.  The Hazlitt book renewed my interest in economics, a field I had thought about studying more in college.  I have always been more on the Friedman side of things than Keynesian (few people know that Friedman was originally a Keynesian).  The thing I find most appealing about Friedman is that he understands the connection between economic models and their impact on politics and liberty – both are so intertwined but so few people realize this.

    What have you been reading?

    Tags:

    Slick Thoughts

    Making Great Events

    7/14/2010 9:38:06 AM

    All of you have at one time or another attended some great events.  What I am interested in is what you would say are the things that make an event truly stand out from other events.  In this case, I am thinking about how Microsoft could raise the bar for events that it delivers as “first party” events in places like Minneapolis, Omaha, Des Moines, etc.  Think – how could the VS 2010 Launch event have been absolutely killer…. 

    Clearly, content is king, but I would love to hear your thoughts on the end-to-end experience….  Just some things to get the ball rolling…

    - Content – Clearly we need to have good content.  What makes good content?  Is there a difference between Launch style content (new stuff) vs. other types of events (everyone has some level of understanding)?  Can you have content that pleases both senior developers and a junior developer?

    - Venue – How do you feel about theaters? Hotels better? Other? Is parking a big deal or just something you deal with?  Screen requirements (multiple? High resolution? Etc.)

    - Swag – is it a major turn-off if you don’t get product?  Do you think handing out eval software on premise is worth it? Trinkets? Hard copy of links to resources?

    - Food and Beverage – what is your expectation?  The minimum required for an event?

    - Demos – do you like longer, more elaborate demos?  Quick hit, show me what I need to know? Scenario based?  Do certain types of demos lend themselves to different types of events?

    - Videos – Do you like opening videos?  What kind? “Welcome from Steve Ballmer”, “Funny spoof videos”, “customer testimonials”, “cool tech demonstration videos”

    I know there is more. If you could take some time leave a comment or two, that would be great!

    Tags:

    Slick Thoughts

    Spaghetti Code: Evolutionary Programming with Jason Bock

    6/29/2010 12:30:00 PM

    Spaghetti Code talks with Jason Bock about how Evolutionary Programming lets you use genetic principles to find solutions to complex problems. You can get the source code, presentation deck, and more @ http://www.jasonbock.net/JB/Code/EvolvingNET.zip

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

    SpaghettiCode

    Custom Per-Page Transitions in Windows Phone 7

    6/1/2010 3:57:49 PM

    Continuing our previous explorations of the TransitioningContentControl (hereand here – all WinPhone content here), we will now take a look at how we can extend the TCC to allow transitions to be defined on a per-page basis.  Put simply, we would like to be able to have a default transition for all pages, and then provide a list of custom transitions that will be used on a page-by-page basis.  You can also watch a screencast  making these changes.  Source is linked at the end of the article.

    Our first step is to create a simple class that will be used to hold Page-to-Transition mappings.  That class is shown below:

    1. namespace System.Windows.Controls
    2. {
    3.      public class PageTransitionMapping
    4.      {
    5.           public string Page { get; set; }
    6.           public string Transition { get; set; }
    7.      }
    8. }

    I added this class to the TCC folder from the previous screencast (download here).  Notice that I changed the namespace to match the TCC’s namespace.

    Next, the TCC is modified to allow us to provide Page-To-Transition mappings via the App.xaml file.  See below:

    1. public class TransitioningContentControl : ContentControl
    2. {
    3.  
    4. private List<PageTransitionMapping> _mappings = new List<PageTransitionMapping>();
    5. public List<PageTransitionMapping> PageTransitionMappings { get { return _mappings; } }
    6.   …

    The _mappings field stores a List<> of PageTransitionMapping objects.  These mapping objects are created by accessing the PageTransitionMappings property via App.xaml as shown below

    1. <phoneNavigation:PhoneApplicationFrame x:Name="RootFrame" Source="/MainPage.xaml">
    2. <phoneNavigation:PhoneApplicationFrame.Template>
    3. <ControlTemplate>
    4. <layout:TransitioningContentControl Content="{TemplateBinding Content}" Style="{StaticResource TransitioningStyle}">
    5. <layout:TransitioningContentControl.PageTransitionMappings>
    6. <layout:PageTransitionMapping Page="AprilCTP.Views.Favorites.Default" Transition="SwingTransition" />
    7. </layout:TransitioningContentControl.PageTransitionMappings>
    8. </layout:TransitioningContentControl>
    9. </ControlTemplate>
    10. </phoneNavigation:PhoneApplicationFrame.Template>

    In this example, the Default.xaml page in the Views/Favorites folder has been mapped to use the SwingTransition.  Just like before, all of the transitions used by the TCCC must be in the TCC’s Style definition – the ControlTemplate’s VisualStateManager specifically).

    The next last step is to update the way the TCC applies transitions to pages as they are displayed.  To do this, we update the TCC’s StartTransition() method as shown below:

    1. private void StartTransition(object oldContent, object newContent)
    2. {
    3. // both presenters must be available, otherwise a transition is useless.
    4. if (CurrentContentPresentationSite != null && PreviousContentPresentationSite != null)
    5. {
    6. PageTransitionMapping transitionMapping = null;
    7. var newPage = newContent as PhoneApplicationPage;
    8.  
    9. if (newPage != null)
    10. {
    11. string pageType = newPage.GetType().ToString();
    12. transitionMapping = (from m in this.PageTransitionMappings where m.Page == pageType select m).SingleOrDefault();
    13. }
    14.  
    15.  
    16.  
    17. // and start a new transition
    18. if (!IsTransitioning || RestartTransitionOnContentChange)
    19. {
    20. IsTransitioning = true;
    21.  
    22. if (transitionMapping != null)
    23. {
    24. Transition = transitionMapping.Transition;
    25. }
    26. else
    27. Transition = _standardTransition;
    28.  
    29. CurrentContentPresentationSite.Content = newContent;
    30. PreviousContentPresentationSite.Content = oldContent;
    31. VisualStateManager.GoToState(this, NormalState, false);
    32. VisualStateManager.GoToState(this, Transition, true);
    33. }
    34. }
    35. }

    There are a couple of important points.  First, the CurrentContextPresentionSite.Content = and the PreviousContentPresentationState.Content = lines of code have been moved a bit from where they appeared in the original code.  Secondly, there is no real error handling for cases where you enter the wrong name for your custom transition inside the App.xaml mapping.  This is more “proof of concept” code than production ready code.  The TCC has a GetStoryboard method that you can use to make sure the transition is available, it is just a matter of where you want to detect that and then how you want to handle it in case a transition does not exist (fall back to the default transition is probably the easiest).

    The last thing we have to do is set the value for _standardTransition.  We will set its value in the OnApplyTemplate() method inside the TCC.  This method gets called one time when the TCC is first created and the template is applied.  We will add the declaration for _standardTransition immediately before the method (stick it where ever you like):

    1. private string _standardTransition;
    2. /// <summary>
    3. /// Builds the visual tree for the TransitioningContentControl control
    4. /// when a new template is applied.
    5. /// </summary>
    6. public override void OnApplyTemplate()

    The OnApplyTemplate discovers the value of the TCC Transition property that was set in the Style in the App.xaml file.  Setting _standardTransition to this value let’s us use it whenever there is not a custom page transition defined.  Update the OnApplyTemplate() method as shown:

    1. ^^^^ REST OF METHOD ^^^^
    2. _standardTransition = Transition;
    3. VisualStateManager.GoToState(this, NormalState, false);
    4. }

     

    I have included the source for a working solution here.

    Tags:

    Spaghetti Code: XNA Game Development with Chris Williams

    6/1/2010 9:17:22 AM

    Spaghetti Code Talks XNA Game Development for Windows, XBOX and Windows Phone 7 with XNA MVP Chris Williams.

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

    SpaghettiCode

    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