Archive for June, 2006

Mount Si

On Saturday went hiking to Mount Si, one of the quintessential Seattle hikes.

It was a beautiful day, with a clear view of Mount Rainer from the top.

View of Mount Rainer from Mount Si

XBAPs: OnDemand & ClickOnce

If your XBAP has some “heft” to it (large resource files, large assemblies, etc), it may make sense to architect your app to use ClickOnce’s OnDemand APIs.

OnDemand APIs enable developers to delay download parts of the application. This can result in a friendlier end-user UX. Note: OnDemand files can be traditional resource files (e.g. images, xml files, etc) or assemblies.

Architecture Tips & Tricks
Got satellite assemblies or large resource files? Slim down your primary EXE to the bare minimum needed to start the app. Then, when the XBAP is launched, only the application manifest, deployment manifest, and primary EXE will be downloaded. As the user navigates around the xbap, you can use a second thread to download other files/assemblies silently in the background or show app-specific progress UI.

The Sample
I’ve created a sample XBAP that does just this:

  1. Has slim primary EXE.
  2. Utilizes 4 large image files and a controls dll. (Approx 3MB)
  3. When user navigates to xbap, she sees a landing screen while the controls dll & images are being downloaded on separate thread.

The major implementation steps are:

  1. Include resource files (i.e. images) as Content not Resource.
  2. No change to control assemblies.
  3. On the project properties page, select the publish tab. Click the Application Files button. Put the “OnDemand” files in to a separate group. (NOT “Required”.)
  4. Add a reference to System.Deployment
  5. Call the OnDemand Deployment APIs on a separate thread.

Try it out the xbap (RC 1). Get the code here.

Note: OnDemand APIs should only be called when applications are actually deployed using ClickOnce, not during F5 debug.

Pretty Illustrations
Step 1 above: Setting resources files as Content

 Step 3 above: Setting resources files as Content

More Resources

  1. MSDN ClickOnce Deployment and Localization
  2. MSDN ClickOnce OnDemand Deployment Technology Sample
  3. MSDN Walkthrough: Downloading Assemblies on Demand with the ClickOnce Deployment API Using the Designer

Caching & XBAPs

When relying on resources living on a server, you can increase client app perf & decrease network traffic by storing local versions. When trying to build a sandboxed XBAP, however, you cannot create your own local cache store in the file system beyond the space available in isolated storage (512KB).

Fortunately, WPF resource loading uses System.NET’s HttpWebRequest and its “Default” caching policy. In addition, depending on your resources’ sizes and your scenario, it may make sense to use a non-default caching policy when issuing your own HttpWebRequest.

This post aims to give you a little bit of caching context, an overview of your caching options and some sample code.

Understanding the HTTP Cache

How long is something good for?
This answer is determined through a combination of server & client settings.

The server sets the HTTP Response Header “Expires” to indicate the time after which a resource is considered stale. A stale cache entry may not normally be retrieved unless it is first validated with the origin server as being the current version. In addition, the server may specifiy certain cache directives in the header. These include “no-cache,” “max-age,” and “must-revalidate.”

The client/app’s cache policy can determine whether or not a “stale” or even a “not yet stale” value should be returned. Some of these policies are time based (e.g. “okay if stale only for X days”) or location based (“return cached value if it’s there and meets server specified revalidation requirements.) However whatever the app’s cache policy, it must respect the server’s cache directives.


System.Net’s Cache
System.Net.HttpWebRequest’s cache uses the IE cache. This has many benefits: there is a single place for user management perspective. Also, a shared store widens the chance that a recent response might have already been cached. The IE cache (“inet cache”) uses the Temporary Internet Files (“TIF”) to cache results of HTTP requests. Some details:

System.Net.HttpWebRequest’s cache uses the IE cache. This has many benefits: there is a single place for user management perspective. Also, a shared store widens the chance that a recent response might have already been cached. The IE cache (“inet cache”) uses the Temporary Internet Files (“TIF”) to cache results of HTTP requests. Some details:

  • (Update 11 Oct 06)The TIF is by default 3% of the harddrive on XP and 50MB on Vista. This amount is user configurable.
  • The TIF is clearable by users through the Internet Options control panel. It is scavenged when full.
  • On Vista, IE7 Protected Mode puts Low Integrity Level content in a separate cache.

Understanding the most common cache matrixes
The below table calls out some of the most common caching policies. (Note: We assume that no additional server cache constraints were set other than Expires header.)
Cache Policy
Note: If the server does not set the Expires http header, than the expiration=none. In this case, the machine determines what the right “Freshness” time for the resource. By default, this is 1 day but it is configurable.

Note: For System.Net.HttpWebRequest, “Default” policy is somewhat misleading. Unless you explicitly set HttpWebRequest.CachePolicy (or HttpWebRequest.DefaultCachePolicy), the policy is “BypassCache.”

What cache version to use
If your resource files are large & unlikely to change (and having current version is not critical), you should consider:

  • Set a large value in your resources HTTP Expires header
  • Set cache policy to HttpRequestCacheLevel.Default.

If it is critical to have the current version of the resource, you should consider:

  • Set cache policy to HttpRequestCacheLevel.Revalidate.

If you don’t want a unique caching policy, you should stiil:

  • Manually set the cache policy to HttpRequestCacheLevel.Default when creating your own HttpWebRequests

How to set cache policy
Here is a code snippet:

      //  eCreate request
      HttpWebRequest request =
         (HttpWebRequest)WebRequest.Create(requestURI);

      //  Create & set cache policy
      HttpRequestCachePolicy cachePolicy =
         new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
      request.CachePolicy = cachePolicy;
 
      //  Send request/Get response
      HttpWebResponse response = (HttpWebResponse) request.GetResponse();

      //  Put response in to stream
      Encoding enc = Encoding.GetEncoding(1252);
      StreamReader responseStream =
         new StreamReader(response.GetResponseStream(), enc);

      //  Manipulate Response stream
      //  Cleanup
      response.Close();
      responseStream.Close();


 Resources to more deeply understand standard caching

 

New York City

Had a fun quick trip to New York City.

Spent several hours at the Museum of Modern Art. The MOMA is just amazing… it makes the SF MOMA just look so small and modest in comparison. I’m jealous of new yorkers who have such a rich collection in such a beautiful building so close to them.

MOMA

Karen

MOMA

Continue reading ‘New York City’

Woodgrove Demo

At the TechEd chalktalk that Ashish and I tag teamed earlier this week, I demo-ed the Woodgrove Financial Application as an XBAP. I also showed loose XAML and an embedded FlowDocument inside of an HTML.

loose XAML with vector graphics (link)

Woodgrove financial app w/ 3D chart as xbap (link)

html page with FlowDocument in IFRAME (link)

Try try out the app.

The last scenario (FlowDocument in HTML) is particularly compelling:

  • You can leverage your existing site.
  • If you have your article content in XML, it’s easy to create another XSLT transform to XAML.
  • Your content continues to be viewable by everyone, with a better experience for WPF users.
    • Use javascript or server side script to determine the useragent string. (See SDK for example of former.)
    • If user navigates to the article with a .NET 3.0 browser/machine, you’ll get html + FlowDocument. Otherwise, you’ll get html + html.
    • Try it out: link

[Apr 17]: Karsten posted the source code for the Woodgrove Finance app a while back. Adding links.

PhotoStore - XBAP & Standalone

In a chalktalk yesterday, I demo-ed a modified PhotoStore application (you may have seen this demo at last year’s PDC or played with it in the Hands on Labs).

In this version, you can display images bundled with the app as well as those located in your “My Pictures” directory.  This works fine as standalone app because it runs in full trust.  However, the sandboxed XBAP does NOT have FileIOPermission, and so fails with a SecurityException.

To make both XBAP & Standalone work with the same code base, I demoed the compile switching, runtime switching, and XAML switching tips I wrote about last week. 

You can get code here.  Or just run the xbap on RC1.

Note: this app uses my VS Flexible Application template

In Boston!

…for Microsoft’s TechEd conference.

Some flowers at Boston Public Garden 

Purple Flowers

 

 

.NET Framework 3.0 & Dev Community Site

WinFX has officially been rebranded .NET Framework 3.0.

Also, the offical “.NET Framework 3.0″ Developer Community site has just launched!

There are sub-community sites for Windows Presentation Foundationa> , Windows Communication Foundation, and Windows Workflow Foundation  as well as Windows CardSpace (formerly InfoCard).

WPF @ TechEd

We’ve got a great presence at TechEd Boston.

WPF at TechEd
some of the WPF product team members

Vista Security Whitepaper

An interesting overview of Vista Security is now posted on MSDN.