<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Windows Dev Posts By a Dev Theologian</title>
    <link>http://www.jaykimble.net/silverlight-blog.aspx</link>
    <description />
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>mojoPortal Blog Module</generator>
    <ttl>120</ttl>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DevTheoSL" /><feedburner:info uri="devtheosl" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>WP8 Speech Recognizers</title>
      <description><![CDATA[<p>If you don’t know I have been deep into WP8’s Speech SDK for the last 6 months. So much so that I am starting to help others along the way. I just got a question about how to get the confidence rating on a recognized word. </p> <p>If you don’t know what that means, let me explain. Basically the speech recognition is not an exact science. There are complicated algorithms that analyze your speech to determine what words were spoken. One of the cool things with WP8’s SDK is that you can provide a list of words or phases you are looking for and this makes things a little more accurate (mainly because you are limiting the number of combinations to look for).</p> <p>WP8 has 2 objects that you can use to recognize speech: SpeechRecognizer and SpeechRecognizerUI.</p> <p>SpeechRecognizer gives you something a little more low level. It won't show the “pretty” UI that is shown while listening to the user speak; it won’t play a beep sound to indicate that speech is being recorded for recognition, nor does it give the user any feedback whatsoever. It does let you supply a list of words or phrases you are looking for as well as will do the big check for listening for any word. The SpeechRecognizerResult will give you the word (or words) it thinks the user said. It also will give you a list of alternates (via the GetAlternates() method) that might be what the user said. It also gives you a number to tell you how accurate it estimates that it was (and gives this rating for each of the alternates as well). It will also let you do your own recording and will process the speech from your recording (but it accepts a much smaller clip than what the actual MS mechanisms do). Actually doing a recognize for any word will allow for a shorter amount of data.</p> <p>SpeechRecognizerUI does a lot of work for you. It puts up the UI, plays the beep to inidicate to the user to speek, handles the case where a word isn't quite recognized, and generally let’s the user know what is going on throughout the process. It returns a SpeechRecognizerUIResult object which contains SpeechRecognizerResult (in the RecognizerResult property), but the confidence is usually high (I have yet to see any alternates come through). I think this is mainly because the UI object does the extra work of clarifying with the user when it estimates that the accuracy of the recognition isn’t quite that high.</p> <p>From my work, I have found that I tend to use SpeechRecognizerUI more often the the lower level mechanism. Mainly because the added UI/indicators creates a very good experience for the user.</p> <p>[I find it difficult to not attribute human qualities to the recognizer. It was tough not to use words like “guess” during this post.. the recognizer is really amazing how accurate it is and when it is wrong, it’s usually pretty understandable why.]</p><br /><a href='http://www.jaykimble.net/wp8-speech-recognizers.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/R9uRSPJJyUQ/wp8-speech-recognizers.aspx</link>
      <comments>http://www.jaykimble.net/wp8-speech-recognizers.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/wp8-speech-recognizers.aspx</guid>
      <pubDate>Mon, 15 Apr 2013 14:51:50 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/wp8-speech-recognizers.aspx</feedburner:origLink></item>
    <item>
      <title>Test post.. nothing to see here yet</title>
      <description><![CDATA[<p>Just putting a test post out..</p><br /><a href='http://www.jaykimble.net/test-post-nothing-to-see-here-yet.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/D7lysvaLyhU/test-post-nothing-to-see-here-yet.aspx</link>
      <comments>http://www.jaykimble.net/test-post-nothing-to-see-here-yet.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/test-post-nothing-to-see-here-yet.aspx</guid>
      <pubDate>Fri, 18 Jan 2013 14:59:18 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/test-post-nothing-to-see-here-yet.aspx</feedburner:origLink></item>
    <item>
      <title>Logo For Windows8 in JavaScript: Lessons Learned</title>
      <description><![CDATA[<p>So <a href="http://new.efficientcoder.net/">Kevin Wolf</a> created a community challenge with a ARM Surface Tablet as the prize. He presented this to the local Florida Windows8 Development Community which I am a part of.</p> <p>Here’s the basics of the challenge:</p> <ul> <li>The Windows 8 App must be 100% JavaScript/HTML/CSS; no other client technologies allowed.</li> <li>It had to be in the Windows Store by Dec. 1st (we had approximately 2 months to do it)</li> <li>He wanted the app to be non-trivial so therefore there was criteria for what was “non-trivial”:</li> <ul> <li>App must have a market base that was not the development community (and could not be a sample app). In other words it had to have an audience, a real audience.</li> <li>App must implement some form of capture (first name, last name, etc)</li> <li>App must connect to a web service of some type and pull and push data to it (both reads and writes); social networking sites were disallowed, but any other public or private web service was acceptable</li> <li>Needed to implement either search or the share contracts</li> <li>Must use either:</li> <ul> <li>the camera in a meaningful way</li> <li>Location services AND Bing maps in a meaningful way</li></ul> <li>Must implement 1 animation</li></ul></ul> <p>That was it. When I saw the list I was thought, “Boy, he rigged the contest.” I could do that, but I’ve done this kind of insane project in the past. I considered doing it and forgot about it for a month.</p> <p><strong>A Funny Thing Happened on the way to a presentation</strong></p> <p>So&nbsp; along the way I had agreed to do a presentation for the Great American Teach in at my kids’ school. I decided that I would show them some beginning programming with the Logo programming environment (aka Turtle Graphics). I decided since I would be using my Samsung Slate to do this that I should probably go ahead and find a Windows 8 implementation of logo. I couldn’t find one. After a bit of searching around I found a nifty one in JavaScript using the HTML5 Canvas. I decided to take this single page environment and make a full Windows 8 Store app with it. It was all rather trivial. I think the initial version took me 2 evenings to get working (so a couple of hours). I did have to change things. The version I had was using jqConsole which seemed to be overkill, but it provided one nice thing: history. So I fired up TyopeScript and created a nice little history component for my jqConsole replacement (essentially a Textbox with a sprinkling of JavaScript code to sniff for the enter key). I also added a few buttons to make it convenient to retrieve past history items and a scrollable region containing that history.</p> <p>My presentation went off wonderful, and now I was thinking about finishing the app and getting it into the store (really as a convenience for others). It was at this point that I remember the challenge and realized that I had done the first couple items. Next up was the whole Share contract. Essentially what I did was make it possible to share out your history. I also implemented (I think) the opposite mechanism where you can share text back to the Logo app where each line will be executed by the Logo interpreter. </p> <p>For the animation I created a simple movement of my turtle in CSS; he starts at the bottom of the page and moves to the center where he belongs. </p> <p>Next I implemented hitting my personal App Analytics server for Error reporting (mainly). It stays off in most cases unless I am having issues with something then I turn it on for an app. Anyway, I only implemented the read component of this.</p> <p>At this point I submitted to the Windows8 Store. I failed for not having a privacy policy (you have to have one when you need Internet access). That was harder than it should have been since I needed to learn a few things about doing this in HTML5 apps (which, BTW, is easier than what it takes in XAML.. HTML5 apps have a few more controls that we should have in XAML, but I digress). I got in…</p> <p>I announced that I had won the challenge, only to read closer and realized that I needed GPS and WebService pushes. I decided to implement a non-standard GLAT/GLONG expressions in the Logo interpreter as a nicety for teaching students how to write a “how close am I too the equator (or other landmarks)” function. This didn’t take that long.</p> <p>I next implemented a simple write to my Web service and got it working (this was harder). For both of the these I wrote TypeScript. I’ve learned enough about JavaScript that if I am writing something non-trivial I want a tool to help me. There are way too many gotchas with JavaScript that it just makes sense to me (Mind you, I have maintained systems that have tens of thousands of lines of JavaScript code and even worked on a system with 100k of JavaScript! By no means am I a rookie). I got it working and got rejected on Tuesday do to something not working.. not sure what that would be…</p> <p>BUT I realized that the requirement was to write something with GPS AND Maps.. Not just GPS. If I had chosen camera (and I could have come up with something for that, but reasons also matter, because of the words “meaningful way”), I would have more or less been there. I have resubmitted but even if this version gets in before Dec. 1, I still didn’t complete the challenge…</p> <p><strong>Surprises</strong></p> <p>I ran into a couple of surprises. In some respects the set of controls that MS has enabled with WinJS/Html is a little more rich, and pretty easy to setup. The biggest item was the flyout when I built a settings panel for my GPS Enabler. The code to write this was mostly HTML and magic CSS Classes (I say magic because the MS Environment just knows what to do with them to create the control). This actually had me slightly enamored..</p> <p><strong>Takeaways </strong></p> <p>First of all if you have talked to me in the last week or so you may have gotten a different impression. I mentioned some positives to this. There are definitely some positives. BUT, I also need to factor in me. I was a trainer during the Web 2.0 craze. I knew my stuff. I once worked on/maintained/added features to a web project that had close to 100k lines of JavaScript code. I want you to ponder that for a moment…. you back? Good. Now realize that I can do non-trivial things with JavaScript and HTML (things you might not be able to do). I’m not as knowledgeable with the latest and greatest on the HTML5 track, but by no means am I an newbie with this. </p> <p>Also, the project I took was something that already worked well with IE10, and I simply sucked it into the Windows8 Templates. If that was the end of the story then I would say everyone should be doing this, but it’s not. While my project was non-trivial, the task seemed to be trivial. Creating the share contract for instance involved me tweaking the JS code to expose things I could share. I imagine this is the case with Search as well.. you will have a fair bit of tweaking to make things happen.</p> <p>Lessons Learned</p> <p>So the positives, Microsoft has thought through this and what they have delivered is a nice environment. You can do some stuff with this. They have enabled a pretty easy mechanism for you to access the various controls via CSS Styles which makes things pretty easy on that front. If you are doing something fairly trivial (port a single page over that already works in IE10, or single page that sucks in rss feeds) then have at it. You can do it with HTML5/WinJS. </p> <p>If you are doing anything more complex, I would suggest skipping HTML5, and putting on your “big boy” pants and building your app with XAML, VS2012, Blend (if you need it), and a copy of John Papa’s <a href="http://shop.oreilly.com/product/9780596523107.do">Data-Driven Services with Silverlight 2</a> (which needs to be renamed “Data-Driven Services with XAML” because it still applies today). With all that in hand you can do XAML. It’s not that hard. AND, by “complex” I mean web services in any form (where you don’t already have a fully tested/stable JavaScript library to access that service), Maps, Fancy Animations, File Apis, anything data driven… </p> <p>Another lesson learned, if you have to write JavaScript, write TypeScript instead. You still have to remember that you are using closures from things like events, but it’s certainly a lot better having the design environment tell you when something is wrong due to typing, or misspelling, etc.</p> <p>Html/WinJS has the same net effect in my mind as most of the JavaScript apps I have written in the past.. they are quirky. My Xaml apps feel much more solid. In my mind I will keep an eye on the technology, but I am going to stick with XAML for the near future… (you can’t do everything in JavaScript as some would like us to believe).</p><br /><a href='http://www.jaykimble.net/logo-for-windows8-in-javascript-lessons-learned.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/hLKeSPlU5pM/logo-for-windows8-in-javascript-lessons-learned.aspx</link>
      <comments>http://www.jaykimble.net/logo-for-windows8-in-javascript-lessons-learned.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/logo-for-windows8-in-javascript-lessons-learned.aspx</guid>
      <pubDate>Thu, 29 Nov 2012 20:15:29 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/logo-for-windows8-in-javascript-lessons-learned.aspx</feedburner:origLink></item>
    <item>
      <title>Windows Store Rejection#1: Lessons Learned about Age Ratings</title>
      <description><![CDATA[<p>Just thought I would fire up a quick post (and maybe a little advice to the powers that be at Microsoft).</p> <p>I have been working on a Dropbox Client for the last several months in my spare time. I actually almost quit on the process and realized that what I had was more integrated with Windows 8 than anything else in the Windows Store, and that I really wanted to use my own app over anything else that is currently out there. Mind you I was about a week away when I decided to quit. When my work schedule broke a little I decided I NEEDED to finish this. So last Tuesday I finished it up and submitted to the Windows Store. </p> <p>When I was filling out the submission, I got to the line that asks about Age Rating.. this seems weird to me, I hadn’t really thought about it. I mean I would expect it to be rated E (for Everyone) because you bring your own content. I could see a 3 year old being able to operate it.. so I set it to 3 and eliminated any country that wanted me to back that up (at least for now). </p> <p>SIDENOTE: In other Mobile AppStores (you know the one who considers themselves the owner of the name “AppStore”), they don’t ASK you what you think your rating should be, they ask you a series of questions about your app and then they TELL you what your rating is.</p> <p>So, A whole week later, I get the notification (this morning, actually) that I got rejected. I wasn’t offended. It happens there are many things in the guidelines and it’s really easy to miss something or to have a corner of your app that is not as well tested. This was my first time through so I expected this. Of course it was for the aforementioned Age Rating. I checked SkyDrive and saw it was Age Rated for 12+.&nbsp; I assume from reading the materials it was because I have ads in an app and they don’t think anyone younger than 13 should see ads. Seems weird, but OK.. </p> <p>NOW, This is the rub. I made 2 clicks to change the Age Rating from 3+ to 12+ and hit resubmit.. No code has changed. Nothing has REALLY changed except that my age was set too low. Where am I in the process now? At the back of the line waiting another 7 days to hear if there was anything else.</p> <p align="left">[Warning Rant to proceed from here on]<br>I’m assuming that most of the tough stuff is out of the way, but I don’t really know. It does seem strange that I went through the whole process already and I have to wait 7 days. I mean I already passed presumably a number of issues. It seems like a waste of EVERYONE;’s time for me to have to wait and to have EVERYTHING thus far tested for a ZERO code change (no new binaries have been uploaded). This process needs to be streamlined some more that is for sure. Especially considering they want to have <a href="http://news.cnet.com/8301-10805_3-57527938-75/microsoft-vp-100000-windows-8-apps-by-january/">100,000 apps in the Windows Store by January</a>. If they don’t change the process some then that goal will never happen. Just my 2 cents.</p><br /><a href='http://www.jaykimble.net/windows-store-rejection1-lessons-learned-about-ages.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/Yq-2MxgC1R8/windows-store-rejection1-lessons-learned-about-ages.aspx</link>
      <comments>http://www.jaykimble.net/windows-store-rejection1-lessons-learned-about-ages.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/windows-store-rejection1-lessons-learned-about-ages.aspx</guid>
      <pubDate>Wed, 10 Oct 2012 14:45:54 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/windows-store-rejection1-lessons-learned-about-ages.aspx</feedburner:origLink></item>
    <item>
      <title>Why MetroOAuth? or C# Async makes life easier</title>
      <description><![CDATA[<p>Yesterday, I finally pushed some of the oAuth libraries I have been tinkering with. I have a really nice and simple library (and this simplicity seems to flow throughout the library). I decided to pull out some examples using my DropboxClient to show how much simpler a library can be. <p>Here’s how you log in to Dropbox (in c#):</p> <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; width: 97.5%; background-color: #f4f4f4"> <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span style="color: #008000">// if the user has already auth'd you can save this in ISO Store or localstorage</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">var accessKey = <span style="color: #006080">""</span>; <span style="color: #008000">// in our case we are setting it to empty (but it's not required)</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">var client = <span style="color: #0000ff">new</span> DropboxClient(kDropBoxAppKey, kDropBoxAppSecret, accessKey);</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">var authd = <span style="color: #0000ff">false</span>;</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span style="color: #0000ff">if</span> (client.IsAuthenticated) <span style="color: #008000">// do we already have an access key</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">  authd = <span style="color: #0000ff">true</span>;</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span style="color: #0000ff">else</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">  authd = await App.DropboxApi.Authorize(<span style="color: #006080">"http://www.tbwindev.org"</span>); <span style="color: #008000">// URI to go to once logged in</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">&nbsp;</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span style="color: #0000ff">if</span>(authd)</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">{</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">    <span style="color: #008000">// Do something</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white">}</pre><!--CRLF--></div></div>
<p>We put everything into that example just so you can see the full set up. You don’t need the accessKey for instance and can simply leave it off that call (it’s optional). Like the comment says, after the user has Authorized your app you can grab that value from the client (stored in a property) and save it off, and then the user will not need to re-authenticate.
<p>The “if” statement where we check if the user is already authenticated is really a convenience method, but you don’t want to re-authorize the user.
<p>The only lines you really need are the creation of the DropboxClient and the line to Authorize.</p>
<p>Now what is behind that Authorize call is what makes this amazing to me. There are 2 http calls that happen with a call to the WebAuthenticationBroker to show the user a web browser window that is on the Dropbox site. All of these things happen asynchronously, but they happen in order. So, there is a call to get a temporary key which we use with the URI that we push the user to the Dropbox site’s login. After they have logged in (or closed the windows), we check to see if we got a code from the call. If so we make a call to get our official accessKey, and we can proceed from there. Again, all of this happens asynchronously, and your UI will be responsive during this time.</p>
<p>Async makes it so we don’t have to set up any kind of response action or event, etc. Each of the calls returns a Task or a Task&lt;T&gt;. We simply tell the compiler that we want to wait for the task that was passed back to us to complete before we proceed. Inside of the task that we get back there might be other tasks that get awaited. This makes it possible to have a method have a single responsibility without having to clutter it up with what happens or a link to what will happen on return.</p>
<p>&nbsp;</p>
<p>AND, all this works in Metro and WP7.x (as long as you install the Async CTP)</p>
<p>Anyway, I’ll blog some more on this soon.</p>
<p>BTW, my project is at <a href="http://metrooauth.codeplex.com">http://metrooauth.codeplex.com</a> and the current (rather cluttered) code repo is at <a href="https://bitbucket.org/DevTheo/metrodropbox">https://bitbucket.org/DevTheo/metrodropbox</a></p><br /><a href='http://www.jaykimble.net/why-metrooauth-or-c-async-makes-life-easier.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/e6JV1A641w0/why-metrooauth-or-c-async-makes-life-easier.aspx</link>
      <comments>http://www.jaykimble.net/why-metrooauth-or-c-async-makes-life-easier.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/why-metrooauth-or-c-async-makes-life-easier.aspx</guid>
      <pubDate>Wed, 18 Jul 2012 16:36:04 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/why-metrooauth-or-c-async-makes-life-easier.aspx</feedburner:origLink></item>
    <item>
      <title>Metro Nuggets: Cloud-based File Contracts helper - UriBasedStorageFile</title>
      <description><![CDATA[<p>I have been doing a series of posts around my adventures in creating a cross-platform Dropbox library for Windows Phone and WinRT. I actually have a working API at this point, so of course the next step is to look into implementing a File Open Contract.</p> <p>One of the first things you will notice is that you have to return set of IStorageFile back to the caller. So you have to essentially hand back a mechanism that the caller can use to open your file from the cloud (without the caller necessarily needing to know anything about that). At least this is my understanding at this point. I might have to pre-download my files (something I will be testing very soon).</p> <p>Regardless, I thought it would be nice to go ahead and implement IStorageFile based on an URI. So I have created (and am letting you tinker with) this class. Here’s what happens with it. You call the constructor of my class with a URI that can be used to access the file (aka download the file), and my class builds up a read-only file that the file system thinks is a regular old file (BUT there are a bunch of things unimplemented, so you won’t be deleting files for instance). You can even control how the class acts when an unimplemented function is called (it can silently fail or generate an exception).</p> <p>Let’s see some code:</p> <div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4"> <div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">var cloudFile = <span style="color: #0000ff">new</span> UriBasedStorageFile(</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">            <span style="color: #0000ff">new</span> Uri(someUrl, UriKind.Absolute), </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">            <span style="color: #006080">"Application/text"</span>, <span style="color: #008000">// optional mime type (default is "application/octet-stream")</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">            <span style="color: #006080">"test.txt"</span>, <span style="color: #008000">// optional file name (default last part of the path)</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">            <span style="color: #0000ff">true</span>); <span style="color: #008000">// Ignore Not Implemented items</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">var file = await cloudFile.CopyAsync(Windows.Storage.KnownFolders.DocumentsLibrary);</pre><!--CRLF--></div></div>
<p>Yep, that’s 2 lines of code to copy a file from a URI to a file. Pretty cool hunh?</p>
<p><strong>Implementation details (stuff I learned)</strong></p>
<p>Implementing this interface is a little difficult. Well, not majorly so, but there are some gotchas. First of all, I am used to working with Tasks, something that you will get very familiar/comfortable with when/if you get into the Async stuff. The interface requires that you return IAsyncActions and IAsyncOperation&lt;T&gt;s. If you look at Task you will see that it implements this at some level, but casting does not work. After digging a bit I discovered an extension (which is a part of System). Essentially you can call your functions that return Task and Task&lt;T&gt; and then call AsAsyncAction() or AsAsyncOperation() on the returned Task to get it cast to the appropriate type.</p>
<p><strong>Design</strong></p>
<p>So, here’s what I did with this class. I implemented the interface and then call individual methods that&nbsp; return Task based equivalents and then use the AsAsync___ extension methods mentioned above. My actual methods are virtual and protected (which means you could derive a new class from them and override the missing functionality and get a something that is closer to fully functioning). I’ll actually be doing this with my Dropbox implementation so I can pass Dropbox-based files to the OS and things will act like these are actual files on the file system. Pretty cool, hunh?</p>
<p>By the way, none of this is done yet. If you want to help out, let me know.</p>
<p>Also, my description of building a File Open Contract may be incomplete. Like you I am learning this stuff. There might be a future post where I state that everything I knew is wrong. As far as the Open contract goes, at this point I am assuming that I will need to hand back the object and the caller will be able to open up the file. I am hoping that the caller will not need any kind of Internet access defined, but if that happens I will be rewriting these classes a little (so that this isn’t required.</p>
<p>So here’s the link to where the project lives: <a title="https://bitbucket.org/DevTheo/metrodropbox/overview" href="https://bitbucket.org/DevTheo/metrodropbox/overview">https://bitbucket.org/DevTheo/metrodropbox/overview</a><br>Here’s the link to where the file lives: <a title="https://bitbucket.org/DevTheo/metrodropbox/src/3617e9282c60/Common/IStorageFile" href="https://bitbucket.org/DevTheo/metrodropbox/src/3617e9282c60/Common/IStorageFile">https://bitbucket.org/DevTheo/metrodropbox/src/3617e9282c60/Common/IStorageFile</a></p>
<p>Oh yeah, the code from the last couple Metro Nuggets can be found here as well. (there have been some updates. For instance the Windows Phone WebAuthenticationBroker object has changed a little due to a bug I discovered).</p><br /><a href='http://www.jaykimble.net/metro-nuggets-cloud-based-file-contracts-helper-uribasedstoragefile.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/M-48HsobrFw/metro-nuggets-cloud-based-file-contracts-helper-uribasedstoragefile.aspx</link>
      <comments>http://www.jaykimble.net/metro-nuggets-cloud-based-file-contracts-helper-uribasedstoragefile.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/metro-nuggets-cloud-based-file-contracts-helper-uribasedstoragefile.aspx</guid>
      <pubDate>Wed, 28 Mar 2012 19:19:12 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/metro-nuggets-cloud-based-file-contracts-helper-uribasedstoragefile.aspx</feedburner:origLink></item>
    <item>
      <title>Metro Nuggets: WebAuthenticationBroker an oAuth solution</title>
      <description><![CDATA[<p>A few years ago I worked for a company that sponsors the Facebook C# SDK. I wrote a number of the initial demos and answered questions on StackOverflow for the project. I know what our users’ biggest challenge: getting an AccessToken.</p> <p>In terms of oAuth getting an AccessToken for an App is the equivalent to logging in. Essentially you are authenticating and getting permission from the user. As previously <a href="http://www.jaykimble.net/metro-nuggets-async-is-your-friend.aspx">mentioned</a>, I am building a Dropbox client for Windows8 Metro. Dropbox has a new oAuth style library which is (or at least appears to be) the recommended manner to communicate with Dropbox programmatically. So, my new Windows8 Metro/WinRT library needs to communicate in this manner. We will not go into the ins and outs of oAuth, but the first steps are pretty critical for you to understand. Here’s what they are (provided you don’t have an AccessToken, yet):</p> <ol> <li>Get a RequestToken (this is a temporary key/secret) for your application</li> <li>Redirect user to specific URI –inside of a browser window of some sort-- to logon and accept your app (you can provide an optional redirect URI which the user gets sent to after authenticating and accepting your app)</li> <li>Detect that the user has accepted your app, and get an AccessToken (a more permanent key/secret) using the request token</li></ol> <p>The next steps after this are to first save off the AccessToken and then use the AccessToken when making requests to the REST API. There’s a lot wrapped up in this, but the 1st step and the 3rd step are simply calls to the REST API (they are signed in a manner outlined by the oAuth spec, but let’s not get too heavy into that). That middle step is problematic for people. Constructing the URI is easy, but monitoring the Browser can be a problem for some reason.</p> <p><strong>Enter the WebAuthenticationBroker</strong><br>Microsoft solved this for us in Metro/WinRT. They have a gizmo called the WebAuthenticationBroker. Essentially this manages the process for step 2. The challenge is that sometimes an oAuth service will return additional data that we need in the QueryString of the call to our callback URI (yep, we need to do that). Cutting through all that can be a little work –especially when all you really want to be able to do is make a call to a service and use a third party API to facilitate that. Here’s what it looks like:</p> <p><a href="http://www.jaykimble.net/Data/Sites/1/media/wlw/webauthbroker.png"><img title="WebAuthBroker" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="WebAuthBroker" src="http://www.jaykimble.net/Data/Sites/1/media/wlw/webauthbroker_thumb.png" width="698" height="415"></a></p> <p>Essentially a chromeless browser window appears on the screen. Now I fully expect that Dropbox will be detecting the Windows8 Metro UI and will give us a slightly different UI (right now you have to scroll over to the login). A couple additional important items here. If you look closely you will see 2 links at the top of the WebAuthenticationBroker’s control. The one on the right restarts the process presumably taking the user back to the original URI. The one on the left allows the user to simply say “let’s go back to the app.” </p> <p>The code for this is awesome! I can’t stress how cool it works. Basically you do an await on the WebAuthenticationBroker. It returns you an object that indicates whether the user canceled, an error occurred, or we successfully got to the target URI. If we got to the target URI then we also get the additional data passed in with that request via another property. Here’s the pertinent snippet of code from my library:</p> <div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4"> <div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">String DropBoxUrl = await GetAuthorizeUri(endUrl);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">&nbsp;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">System.Uri StartUri = <span style="color: #0000ff">new</span> Uri(DropBoxUrl);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">&nbsp;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">System.Uri EndUri = <span style="color: #0000ff">null</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span style="color: #0000ff">if</span>(!String.IsNullOrEmpty(endUrl))</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">    EndUri = <span style="color: #0000ff">new</span> Uri(endUrl);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">&nbsp;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">Debug.WriteLine(<span style="color: #006080">"Navigating to: "</span> + DropBoxUrl);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">&nbsp;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">WebAuthenticationResult WebAuthenticationResult;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span style="color: #0000ff">if</span>(!String.IsNullOrEmpty(endUrl))</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">    WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">                                        WebAuthenticationOptions.None,</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">                                        StartUri, </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">                                        EndUri);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span style="color: #0000ff">else</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">    WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">                                        WebAuthenticationOptions.None,</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">          </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span style="color: #0000ff">if</span> (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success ||</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">    (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.UserCancel &amp;&amp; WebAuthenticationResult.ResponseData != <span style="color: #0000ff">null</span>))</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">{</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">    Debug.WriteLine(WebAuthenticationResult.ResponseData.ToString());</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">    var accessToken = await GetAccessToken();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">}</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">{</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">    Debug.WriteLine(<span style="color: #006080">"HTTP Error returned by AuthenticateAsync() : "</span> + WebAuthenticationResult.ResponseErrorDetail.ToString());</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">}</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span style="color: #0000ff">else</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">{</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white">    Debug.WriteLine(<span style="color: #006080">"Error returned by AuthenticateAsync() : "</span> + WebAuthenticationResult.ResponseStatus.ToString());</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">}</pre><!--CRLF--></div></div>
<p>I try to get an AccessToken regardless of whether the user canceled or not because if the programmer didn’t specify an EndUri then I need to assume the user might have simply closed the WebAuthenticationBroker control via the link (back to app).</p>
<p>Anyway, this is a very cool mechanism. I don’t have to attach this code to the UI in any manner. It simply injects itself into the UI all on its own.</p>
<p><strong>Windows Phone compatibility object</strong><br>I have also mentioned that I am back-porting this library to Windows Phone. In the process I realized that I needed a mechanism like this one. In fact after looking at this one, I have to say that this is the way it SHOULD be done. I ha<a href="http://www.jaykimble.net/Data/Sites/1/media/wlw/webauthbroker-wp.png"><img title="WebAuthBroker-WP" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: right; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="WebAuthBroker-WP" align="right" src="http://www.jaykimble.net/Data/Sites/1/media/wlw/webauthbroker-wp_thumb.png" width="242" height="400"></a>d arguments with a few folks back in the day with the FB C# SDK in that I thought we should provide the mechanism. I was shot down (mainly because there were too many scenarios to handle.. that project provides Facebook to everything). Anyway, going back to that SHOULD be done. I realized that there should be a mechanism like this for Windows Phone. I have done that. Warning: it does rely on the Async CTP (truth be told this is what sold me on Async), BUT the code for Windows Phone is the same as the code above. To the right is a scrren shot of the the same code running on the Windows Phone emulator (using my compatibility object):</p>
<p>As you can see Dropbox knows the Windows Phone browser and presents a nicer dialog. You can also see that I have the same links in the project, etc. My underlying object injects it’s UI on top of the current page, so you don’t need to add anything other than the 3 files to your code to get this. There’s still work to be done. </p>
<p>I am attaching an early release of this to this post (but will probably bundle my compatibility plugins into an open source project (or at least will be exposing the source code repository publicly). I need to figure out a few more things before I can call this close to done, but feel free to play around with it (and if you spot any bugs or fix them.. let me know).</p>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:60f6cafc-b193-4ab0-b225-bf513fee9357" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><p>Here's the file: <a href="http://www.jaykimble.net/Data/Sites/1/media/wlw/webauthenticationbroker.zip" target="_blank">WebAuthenticationBroker-WP.zip</a></p></div><br /><a href='http://www.jaykimble.net/metro-nuggets-webauthenticationbroker-an-oauth-solution.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/e_X__qTTSPE/metro-nuggets-webauthenticationbroker-an-oauth-solution.aspx</link>
      <comments>http://www.jaykimble.net/metro-nuggets-webauthenticationbroker-an-oauth-solution.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/metro-nuggets-webauthenticationbroker-an-oauth-solution.aspx</guid>
      <pubDate>Tue, 20 Mar 2012 20:09:35 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/metro-nuggets-webauthenticationbroker-an-oauth-solution.aspx</feedburner:origLink></item>
    <item>
      <title>Metro Nuggets: Async is your friend</title>
      <description><![CDATA[<p>I’m in the process of exploring the Metro-Style Win8 API. If you’ve done much looking you probably have discovered that the new Async is everywhere! This is not a bad thing as your code is much cleaner and easier to read. The downside though is that creating something that is compatible between say Win8 Metro and Windows Phone (the original metro) can be difficult.</p> <p>Luckily there is still a CTP of the Async stuff that works with Windows Phone (and it has a GoLive license, so you can use it). CTP sounds scary (it did to me too). If you are deciding to do install the Async CTP, you might want to go here --<a title="http://blogs.msdn.com/b/lucian/archive/2011/11/01/async-ctp-v3-installation.aspx" href="http://blogs.msdn.com/b/lucian/archive/2011/11/01/async-ctp-v3-installation.aspx">http://blogs.msdn.com/b/lucian/archive/2011/11/01/async-ctp-v3-installation.aspx</a>-- and read up.. since I am betting you –like I-- have some VS patches that will prevent you from installing it). To get it installed you need to temporarily uninstall the Silverlight 5 tools and any Visual Studio patches after say December.. if you look at the link it will get you started (there are a couple forum posts that were helpful to me).</p> <p>Now you are ready to play. I’m sure by now you have seen the syntax, but let’s make some comparisons (and we’ll use WIndows Phone code and an example on a class that I have rarely seen discussed: HttpWebRequest):</p> <p>Here’s the old way (warning there is a lot of code here): <div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4"> <div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #008000">// Pretend like Item info below just contains a couple pieces of info:</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #008000">//  like Uri, Method, and possible a filename to save to --in IsoStorage</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">void</span> downloadSomething(UriInfo item) { </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     var webReq = HttpWebRequest.CreateHttp(UriInfo);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     webReq.Method = item.UriMethod;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     WebRequests.Add(item, webReq);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #008000">// If we were passing post values to the routine we would need to </span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>     <span style="color: #008000">// Begin getting the request stream with a callback and then End Getting </span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>     <span style="color: #008000">// the request stream (this is bad enough.. don't want to overcomplicate things)</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>     webReq.BeginGetResponse(ResponseCallback, item);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> ResponseCallback(IAsyncResult ar) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>     IFileItem item= (IFileItem) ar.AsyncState;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>     var webR = WebRequests[item];</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>     var resp = (HttpWebResponse) webR.EndGetResponse(ar);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span>     <span style="color: #0000ff">if</span> (resp.StatusCode == HttpStatusCode.OK) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060">  18:</span>         <span style="color: #008000">// We could also do the whole Begin/End on the Response Stream </span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060">  19:</span>         <span style="color: #008000">// (with another calllback)</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060">  20:</span>         <span style="color: #0000ff">using</span> (var strm = resp.GetResponseStream()) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060">  21:</span>             var buffer = <span style="color: #0000ff">new</span> <span style="color: #0000ff">byte</span>[4096];</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060">  22:</span>             item.BytesDownloaded = 0;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060">  23:</span>             <span style="color: #008000">// If the file exists we need to delete it (BTW, using Jay's IsolatedStorage Facade which looks like System.IO.File, Directory, FileInfo, and DirectoryInfo -- "PS" stands for persisted storage)</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060">  24:</span>             <span style="color: #0000ff">if</span> (PSFile.Exists(item.DestinationNameAndPath))</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060">  25:</span>                 PSFile.Delete(item.DestinationNameAndPath);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum26" style="color: #606060">  26:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum27" style="color: #606060">  27:</span>             <span style="color: #008000">// We should actually check to see if the path exists for this file.. </span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum28" style="color: #606060">  28:</span>             <span style="color: #008000">// BTW, this uses my Isolated Storage Facade classes </span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum29" style="color: #606060">  29:</span>             <span style="color: #008000">// (so PSDirectory == SystemDirectory, but just against IsolatedStorage)</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum30" style="color: #606060">  30:</span>             <span style="color: #0000ff">if</span> (!String.IsNullOrEmpty(System.IO.Path.GetDirectoryName(item.DestinationNameAndPath)) &amp;&amp; !PSDirectory.Exists(System.IO.Path.GetDirectoryName(item.DestinationNameAndPath)))</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum31" style="color: #606060">  31:</span>                 PSDirectory.CreateDirectory(System.IO.Path.GetDirectoryName(item.DestinationNameAndPath));</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum32" style="color: #606060">  32:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum33" style="color: #606060">  33:</span>             <span style="color: #0000ff">using</span> (var fs = PSFile.Create(item.DestinationNameAndPath)) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum34" style="color: #606060">  34:</span>                 var fileLength = item.ActualSize;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum35" style="color: #606060">  35:</span>                 <span style="color: #0000ff">do</span> {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum36" style="color: #606060">  36:</span>                     <span style="color: #0000ff">int</span> count = strm.Read(buffer, 0, 4096);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum37" style="color: #606060">  37:</span>                     <span style="color: #0000ff">if</span> (count &lt; 1)</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum38" style="color: #606060">  38:</span>                         <span style="color: #0000ff">break</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum39" style="color: #606060">  39:</span>                     fs.Write(buffer, 0, count);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum40" style="color: #606060">  40:</span>                     item.BytesDownloaded += count;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum41" style="color: #606060">  41:</span>                 } <span style="color: #0000ff">while</span> (<span style="color: #0000ff">true</span>);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum42" style="color: #606060">  42:</span>             }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum43" style="color: #606060">  43:</span>             item.BytesDownloaded = item.ActualSize;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum44" style="color: #606060">  44:</span>         }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum45" style="color: #606060">  45:</span>     }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum46" style="color: #606060">  46:</span>     <span style="color: #008000">//else </span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum47" style="color: #606060">  47:</span>         <span style="color: #008000">// We got an error or something. Normally I notify the end user of this (this is left up to you to do on your own)</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum48" style="color: #606060">  48:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum49" style="color: #606060">  49:</span> }</pre><!--CRLF--></div></div></p>
<p>New Way:</p>
<div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> async Task&lt;<span style="color: #0000ff">string</span>&gt; simpleHttpPost(<span style="color: #0000ff">string</span> url)</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     var uri = <span style="color: #0000ff">new</span> Uri(url);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     HttpWebRequest client = HttpWebRequest.CreateHttp(uri);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     client.Method = <span style="color: #006080">"POST"</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>     var response = (HttpWebResponse) (await client.GetResponseAsync());</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>     var _lastResultCode = response.StatusCode;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>     <span style="color: #0000ff">if</span> ((<span style="color: #0000ff">int</span>)_lastResultCode &lt; 400) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>     <span style="color: #0000ff">using</span> (var strm = (<span style="color: #0000ff">new</span> StreamReader( response.GetResponseStream())))</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>         <span style="color: #0000ff">return</span> await strm.ReadToEndAsync();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>     }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>&nbsp; </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>     <span style="color: #0000ff">return</span> <span style="color: #006080">""</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span> }</pre><!--CRLF--></div></div>
<p>Admittedly when giving examples you try to keep the code similar for comparison sake. I decided to simply grab some code from my new project and from an old project. Please forgive me. I will do my best to highlight the big differences here.</p>
<p>The old way with HttpWebRequest was that you did a <em><strong>Begin____(callbackFunction)</strong></em> for nearly everything. The callback function must (among other things) call End______() to actually get what you were looking for (this could be the RequestStream, so you could make a post and push post variables, or it could be the response, or the ResponseStream – the ResponseStream at least has a synchronous version which I used above). Because this was going on you could use delegates and not lose context, but the execution order was jumbled.. so essentially you created a delegate for each callback (so the code came first) then you would call the Begin which would go out do the activity and then make calls into your code that was previously defined.. it is very ugly and hard to follow what is happening…</p>
<p>The new way introduces the use of the <em><strong>await</strong></em> or <strong><em>Await</em></strong> (in VB) keyword. When I first saw this I thought it was a gimmick, but the reality is that our APIs can be cleaner. You get the ability to simply suspend execution of your code while you wait for something to come back. You do have to mark your function with the async (or Async in VB) Keyword and use Task&lt;T&gt; as a result. </p>
<p>I really feel like the second example is much cleaner and easier to follow. At the very least you know what order things are happening..</p>
<p><strong>An Added Benefit</strong><br>Let’s make a not so contrived example to show you something else that is pretty cool. Let’s assume that we have an app whose first action is to run out to a service of some sort and get some data that will be databound to the UI. Meanwhile we have a few additional things that need to be done (so we don’t want to be prevented by the download)..</p>
<div id="codeSnippetWrapper" style="cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; overflow: auto; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> setupMainPage() {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>     getData();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #008000">// Next line will happen before the getData call fully completes</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #008000">// this is because we are not "await"ing the return</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     doSomethingElse();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span> <span style="color: #0000ff">protected</span> async <span style="color: #0000ff">void</span> getData() {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>     var result = await simpleHttpPost(<span style="color: #0000ff">new</span> Uri(<span style="color: #006080">"http://someDomain.com/someService"</span>));</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>     var dataObject = deserializeObject(result); <span style="color: #008000">// turns json string into object</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>     <span style="color: #0000ff">this</span>.DataContext = dataObject;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; overflow: visible; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span> }</pre><!--CRLF--></div></div>
<p>So essentially we can fire things off and when they complete they will continue running. We don’t have to await everything.</p>
<p><strong>Preview of Future posts</strong><br>At present I am building a new Dropbox client library for Windows8 and am retrofitting it for Windows Phone. To do this I had to create some compatibility objects for Windows Phone to make this happen. I actually also had to create some helper objects that do things like HTTP because they are very different and I wanted to avoid compiler directives as much as is possible. I will be writing about all of this in the coming weeks. I will eventually be speaking at a combines Tampa Bay Windows Phone UG and Tampa Bay Windows Dev UG meeting about all of this.</p><br /><a href='http://www.jaykimble.net/metro-nuggets-async-is-your-friend.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/DxogrHo2Ub0/metro-nuggets-async-is-your-friend.aspx</link>
      <comments>http://www.jaykimble.net/metro-nuggets-async-is-your-friend.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/metro-nuggets-async-is-your-friend.aspx</guid>
      <pubDate>Tue, 20 Mar 2012 18:15:04 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/metro-nuggets-async-is-your-friend.aspx</feedburner:origLink></item>
    <item>
      <title>Windows8 CP: Almost there!</title>
      <description><![CDATA[<p>So this is more of a review and less of a techy post. Yesterday as I was exploring Win8, I discovered 2 apps in the store that are important in my mobile world: EverNote and the YouVersion Bible. </p> <p>You see, I have a daily routine where I bring up YouVersion on my Acer Iconia (Android) Tablet (before this I used an iPad2.. before that I had a less techy way of doing this). I read a little scripture and then note a couple verses and then I bring up EverNote paste in the scriptures and write a few notes for myself as well as do some general journaling. It helps to keep my thoughts together before I go full force in my day.</p> <p>I was stoked because I could possibly move entirely to Windows 8. I actually started checking prices on Tablets that would run Win8, and I was thinking I could have my tablet experience with the full power of Windows.. this would be more than cool!</p> <p>Now I tried this with the developer bits, but the desktop EverNote didn’t bring up the keyboard appropriately, I gave up and went back to my iPad at the time..</p> <p>So this morning I tried it. You can guess by the post’s title that something didn’t work. I was actually able to not only bring both apps up, but pin the Bible on the left hand side. Where things failed was EverNote. It let’s you edit notes, but I could not change the notebook I was saving too. It seems to default to a Notebook I set up to do a knowledge transfer to my job (as I was leaving the company). I also couldn’t figure out how to edit after I had accidently closed the notebook. I will have to wait for an update to EverNote before I can really use this.</p> <p>Oh yeah, I will also be wanting the YouVersion guys to update their app and give me offline bibles (otherwise I have to have wifi always which in the morning isn’t too much trouble).</p> <p>Beyond this fact I am liking the evolution of the OS from the Developer Bits. I have read some stuff about how the OS isn’t necessarily intuitive in all respects, and I would concur. I have watched all the intro videos, so I know to swipe up to get app’s menu or swipe on the right hand side to get the charms or to swipe left to bring in an already running app.. and I figured out the whole swipe down to be able to throw your app off screen (shutting it off).</p><br /><a href='http://www.jaykimble.net/windows8-cp-almost-there.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/VNAoMZVF9Ck/windows8-cp-almost-there.aspx</link>
      <comments>http://www.jaykimble.net/windows8-cp-almost-there.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/windows8-cp-almost-there.aspx</guid>
      <pubDate>Fri, 02 Mar 2012 13:09:16 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/windows8-cp-almost-there.aspx</feedburner:origLink></item>
    <item>
      <title>Forced Landscape Printing in Silverlight (On a Mac)</title>
      <description><![CDATA[<p>I ran into an issue with the Silverlight5 app I am working on. One of the very important things in this app is the ability to print (in formats other than Letter format in portrait mode). My client uses a Mac and as he was testing the app on his Mac he discovered that the print dialog did not offer Landscape printing to him. After searching quite a bit on the Internet I discovered that low and behold Silverlight (both 4 and 5) don’t really have the best story for Landscape printing on a Mac. In fact if you are using Silverlight to produce printouts, you need to be aware of this fact especially when you know that your printout must be on a Landscape page.</p> <p>The solution is relatively simple (and I discovered the initial technique in this blog post – <a href="http://earok.net/sections/articles/web-dev/easy-landscape-printing-silverlight?page=3%2C8">http://earok.net/sections/articles/web-dev/easy-landscape-printing-silverlight?page=3%2C8</a>)</p> <p>This essentially gives us the ability to print Landscape, but on a PC the user could choose landscape mode. Here’s how I detect it:</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">bool</span> rotateContentForLandscape = <span style="color: #0000ff">false</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">void</span> doc_PrintPage(<span style="color: #0000ff">object</span> sender, PrintPageEventArgs e)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    rotateContentForLandscape = (e.PrintableArea.Height &gt;= e.PrintableArea.Width);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    var printedPage = generatePrintContent();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">if</span> (rotateContentForLandscape)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        var transformGroup = <span style="color: #0000ff">new</span> TransformGroup();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        transformGroup.Children.Add(<span style="color: #0000ff">new</span> RotateTransform() { Angle = 90 });</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        transformGroup.Children.Add(<span style="color: #0000ff">new</span> TranslateTransform() { X = e.PrintableArea.Width });</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        printedPage.RenderTransform = transformGroup;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    e.PageVisual = printedPage;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div>
<p>I use a class level variable <em><strong>rotateContentForLandscape</strong></em>, so in the process of creating content I can detect if there are any weird edge cases where I need to generate something slightly different (I might never really need this). The whole <em>TransformGroup</em> code (inside the <em>If</em>) simply rotates the content and positions it properly on the print page.</p>
<p>That’s all there is to it. Depending on your UI you might not want to detect quite like I’m doing. Your preference might be to have a checkbox in the UI to force landscape and then do the Landscape detection.</p><br /><a href='http://www.jaykimble.net/forced-landscape-printing-in-silverlight-on-a-mac.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/8bRPLb5NsUo/forced-landscape-printing-in-silverlight-on-a-mac.aspx</link>
      <comments>http://www.jaykimble.net/forced-landscape-printing-in-silverlight-on-a-mac.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/forced-landscape-printing-in-silverlight-on-a-mac.aspx</guid>
      <pubDate>Tue, 14 Feb 2012 16:25:02 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/forced-landscape-printing-in-silverlight-on-a-mac.aspx</feedburner:origLink></item>
    <item>
      <title>The WP7/Windows Metro/RT Opportunity!</title>
      <description><![CDATA[<p>I think we’ve all seen the commercial where the kids are playing with their dad who is grocery shopping. The kids update the grocery list with all kinds of sweets. Eventually the dad realizes what is happening and he changes the list to “Do your homework!!” Microsoft is famous for showing stuff like this, and about 2 to 3 versions of VS later it gets available to the masses. In other words, it’s a feature they keep to themselves for a bit and then they give it to the developers. Oftentimes we have already moved on or have built our own solutions to the problem that we are now stuck with (until we refactor our code).</p> <p>This is why I am amazed at what has been announced surrounding SkyDrive, Windows Phone (aka WP7, WP7.5, etc), and the next version of Windows. We are actually getting the ability to make apps like this! Very, very cool! </p> <p><strong>Theme Park Pro – A Scenario</strong><br>I was recently at an Amusement Park and used my buddy’s NeurelNet’s <a href="http://www.windowsphone.com/en-US/apps/3caa74ce-d2e7-4a3b-8970-2ff2495ad77a" target="_blank">Theme Park Pro</a> App. If you are not familiar with the app, it let’s you scope out a bunch of Amusement parks (like Walt Disney World, Busch Gardens in Tampa, and Universal Studios Parks in Florida – just to name a couple). They actually offer badges as you walk around the park letting you check in at the Roller Coasters and other rides. As I was using the app that day I started thinking about a few changes I was going to suggest to the guys. </p> <p>As the went on I realized that there were a couple things bugging me. I’m getting older (but still in my early 40s), so there are few roller coasters I ‘m not really interested in riding (mainly because I am not the daredevil I once was). I started realizing that what I wish I could have done was customized my trip to show those things that I wanted to do on my trip. Of course I really didn’t want to do this on my phone.. I wanted to do this on something like my tablet or my laptop.. I wanted to be able to customize my experience in Theme Park Pro and have it reflected when I grabbed my phone. </p> <p><strong>The Opportunity!</strong><br>As I was thinking how to send this idea to my NeurelNet buddies I realized what an opportunity we all have (those of us who develop for Windows Phone –or other Mobile Platforms, really). We can make Phone Apps that absolutely rock and that combine the experiences of the PC and the Phone. I watched the demos at BUILD, but the reality is hitting me now.. I think there is a huge financial opportunity for us all again!</p><br /><a href='http://www.jaykimble.net/the-wp7windows-metrort-opportunity.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/u3yPljb3h9c/the-wp7windows-metrort-opportunity.aspx</link>
      <comments>http://www.jaykimble.net/the-wp7windows-metrort-opportunity.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/the-wp7windows-metrort-opportunity.aspx</guid>
      <pubDate>Wed, 25 Jan 2012 16:56:27 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/the-wp7windows-metrort-opportunity.aspx</feedburner:origLink></item>
    <item>
      <title>WinRT Quick Tip #1: Get the Constructor for a Type</title>
      <description><![CDATA[<p>I ran into this on the Win8 Developer’s Preview. I am porting over some Windows Phone Code. This code has a MEF/IOC-Like mechanism that let’s me do discovery on the project. The project itself is a simple App Framework; it has a bunch of content controls, but with the way it is configured you may decide that you don’t want to deploy all these controls, SO I needed to be able to discover controls and create them dynamically (the latter is what this tip is all about).</p> <p>My original code looked like this:</p><pre class="csharpcode">        <span class="kwrd">public</span> UserControl GetAndInitControlFor(<span class="kwrd">string</span> targetType, SectionInfo data) 
        {
            UserControl result = <span class="kwrd">null</span>;
            var typ = (from item <span class="kwrd">in</span> Catalog 
                              <span class="kwrd">where</span> item.Key.Equals(targetType, 
                                                  StringComparison.InvariantCultureIgnoreCase) 
                              select item).FirstOrDefault();

            <span class="kwrd">if</span> (!typ.Equals(<span class="kwrd">null</span>))
            {
                var ctor = typ.Value.GetConstructor(<span class="kwrd">new</span> Type[0]);
                result = ctor.Invoke(<span class="kwrd">new</span> <span class="kwrd">object</span>[0]) <span class="kwrd">as</span> UserControl;
                <span class="kwrd">if</span> (result != <span class="kwrd">null</span> )
                {
                    ((ISUAFContentControl)result).SetData(data);
                }
            }
            <span class="kwrd">return</span> result;
        }
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>&nbsp;</p>
<p>This particular function looks up a control by it’s content type (a string) in the Dictionary that I have already built. If it finds a match then it takes the type instantiates it via the type’s constructor (essentially doing a “new” on the class). The only problem is that WinRT’s type doesn’t have a way to get the constructor. Instead there is a different mechanism you have to use.</p>
<h2>Enter TypeInfo</h2>
<p>I did some BINGing and I found the answer. There is a mechanism called TypeInfo. It’s apart of System.Reflection, so you will have to add a “Using System.Reflectiomn;” to the top of your file. Now you can get TypeInfo for you class. Here’s the rewritten function for WinRT:</p><pre class="csharpcode">        <span class="kwrd">public</span> UserControl GetAndInitControlFor(<span class="kwrd">string</span> targetType, SectionInfo data) 
        {
            UserControl result = <span class="kwrd">null</span>;
            var typ = (from item <span class="kwrd">in</span> Catalog 
                             <span class="kwrd">where</span> item.Key.Equals(targetType, 
                                           StringComparison.OrdinalIgnoreCase)
                             select item).FirstOrDefault();

            <span class="kwrd">if</span> (!typ.Equals(<span class="kwrd">null</span>))
            {
                TypeInfo typeInfo = typ.Value.GetTypeInfo();
                var ctor = typeInfo.DeclaredConstructors
                                    .Where(c=&gt;c.GetParameters().Count() == 0)
                                    .Select(c=&gt;c).FirstOrDefault();
                result = ctor.Invoke(<span class="kwrd">new</span> <span class="kwrd">object</span>[0]) <span class="kwrd">as</span> UserControl;
                <span class="kwrd">if</span> (result != <span class="kwrd">null</span> )
                {
                    ((ISUAFContentControl)result).SetData(data);
                }
            }
            <span class="kwrd">return</span> result;
        }</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>It’s very similar, but about midway down you can see where I create a TypeInfo for the type, and then using that type I have to write a Linq query to pull out the paramerless constructor that I am going to use to new up an instance. </p>
<p>I didn’t like having to change things, but I do like the new mechanism a lot better. These things should have been properties all along.</p><br /><a href='http://www.jaykimble.net/winrt-quick-tip-1-get-the-constructor-for-a-type.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/KzzGXrGT3Qo/winrt-quick-tip-1-get-the-constructor-for-a-type.aspx</link>
      <comments>http://www.jaykimble.net/winrt-quick-tip-1-get-the-constructor-for-a-type.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/winrt-quick-tip-1-get-the-constructor-for-a-type.aspx</guid>
      <pubDate>Thu, 19 Jan 2012 16:57:52 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/winrt-quick-tip-1-get-the-constructor-for-a-type.aspx</feedburner:origLink></item>
    <item>
      <title>Mobile Apps and Legal issues</title>
      <description><![CDATA[<p>One of the guys on the local Florida Windows Phone List asked a question about his app which is a medical app. He was becoming worried that he might have legal issues with his app. This resulted into a really nice thread on legal issues and your app (and your business).</p> <p>I decided to go ahead and make a quick write up (for me as well as for anyone else).</p> <p><strong>Rule # 1 cover yourself at all times!</strong> <br>Think about the lady who got burnt by McDonald’s coffee who sued because they didn’t say it was hot! You might think the lawsuit was frivolous, but it illustrates the problem. Someone using your app ends up setting their device (and house) on fire, you could get blamed (Ok, that’s extreme, but you get the idea). You can never be too careful!</p> <p>This advice sounds scary, but there are solutions here.. <strong>Don’t give up just yet! <strong>Lawyers exist for this very reason.</strong> </strong></p> <p>[<a href="http://social.msdn.microsoft.com/profile/keith%20kabza%20%5Bmsft%5D/" target="_blank">Keith Kabza</a> had the best bit of info on this -- I have to credit the source as the info is good, and much of the post from here comes from Keith’s knowledge] To the specifics of <strong>medical related apps</strong>, you need to make sure you aren’t violating any laws related HIPAA (In my personal experience you need to find someone that knows those laws and walk them through what you are doing – if you don’t know someone, come to a local user group and ask if anyone there knows anything about HIPAA). You also need to avoid exposing data their data without using encryption and basic security principals. The good news is there is limited risk in selling mobile apps.</p> <p>Next <strong>operate as an LLC!</strong> This protects you to a point. Form there <strong>get at least limited liability insurance</strong>. It will cost you about $800 a year, but it will cover you for $1 million. [these next 3 nuggets from from <a href="http://blog.toetapz.com/" target="_blank">Henry Lee</a>] Additionally you may want to get Errors and Omission insurance which really covers the scenario where someone burns down their house while using their app (that’s extreme, but has happened). Also, getting umbrella insurance to cover anything not covered by the previous two insurances. The short is that you want to cover yourself on all legal aspects because you don’t want your spare time building an app to cause you to lose your house.</p> <p>You want an attorney when you are crafting your licensing agreements. You want it to be written to protect you from frivolous lawsuits.This is something that gets overlooked by many of us! The lawyer Keith recommended (who specializes in this stuff) charges about $3000.</p> <p><strong>Resources</strong></p> <p>A few additional resources came up in the thread, and here they are:</p> <p><a href="http://www.techinsurance.com">www.techinsurance.com</a> – they are an insurance company who simply finds the best rate for you. (via <a href="http://blog.toetapz.com/" target="_blank">Henry Lee</a>)<br><a href="http://legalzoom.com">legalzoom.com</a> – offers a whole suite of legal solutions and you can get liability coverage for about $450 a year. (via <a href="http://www.gregleonardo.com/" target="_blank">Greg Leonardo</a>)</p><br /><a href='http://www.jaykimble.net/mobile-apps-and-legal-issues.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/uBwxBMqKUz8/mobile-apps-and-legal-issues.aspx</link>
      <comments>http://www.jaykimble.net/mobile-apps-and-legal-issues.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/mobile-apps-and-legal-issues.aspx</guid>
      <pubDate>Fri, 13 Jan 2012 15:57:27 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/mobile-apps-and-legal-issues.aspx</feedburner:origLink></item>
    <item>
      <title>Mango Live Tile Helper</title>
      <description><![CDATA[<p>I’m in the process of unveiling a new app on the marketplace (it’s actually ready to publish right now, but I’m waiting to publish a blog post on it later). During the process of creating this app (really it’s a framework), I needed/wanted to enable a Live Tile. While the whole Live Tile thing is not all that complex, I decided to make it even simpler with a single class.</p> <p>I had been told Live Tiles can be created in 6 lines of code; with my helper I have reduced that number by 66% (so 2 lines of code). I also used this code to produce a new version of my comic reader that let’s you pin a single comic to the desktop (and of course it shows a portion of the cover/first page in the Live Tile).</p> <h1>The Code</h1> <p>I created a class that is called LiveTileTempate. It’s all you need in your projects. All you need to do is create a LiveTileTemplate Instance with the proper values set and then call the UpdateApplicationTile, or CreateSecondaryTile methods. So here’s some example code for updating the application’s pinned/Live Tile:</p> <p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:e6ef5fa8-f5a8-4769-9a70-9aa7d5124da8" class="wlWriterEditableSmartContent"><pre class="brush: c#;">     LiveTileTemplate tileCreate = new LiveTileTemplate
     {
          FrontSideTileTitle = "Live Tile Demo",
          FrontSideTileCountContent = (new Random()).Next(100),
          BackSideTileTitle = "Back Side",
          BackSideTileContent = "My Content on back of tile"
     };
     tileCreate.UpdateApplicationTile();</pre></div></p>
<p>So let me explain all this, we create a LiveTileTemplate and then simply call the instance’s UpdateApplicationTile method. Most of this is pretty self-explanatory. We set both the front and back titles that appear under the tile, we set a number which appears on the front, and we set the back to have a message on the tile (we go through all the properties further down this post).</p>
<p>This same code could be used to produce a Secondary tile with 2 changes:</p>
<ol>
<li>We have to set the NavigationUri property of the LiveTileTemplate instance</li>
<li>The last line would need to call CreateSecondaryTile instead of UpdateApplicationTitle</li></ol>
<p>Let’s see an example of a Secondary Tile:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:65c2e0cd-e805-4db2-8493-b1162280f57b" class="wlWriterEditableSmartContent"><pre class="brush: c#;">     LiveTileTemplate tileCreate = new LiveTileTemplate
     {
          FrontSideTileTitle = "2nd Live Tile",
          FrontSideTileCountContent = (new Random()).Next(100),
          FrontSideBackgroundImage = "/Koala.jpg", // this would never fly in the Marketplace process (icon needs to reflect app)
          BackSideTileTitle = "2nd Back Side",
          BackSideTileContent = "This is the backside of the second tile",
          NavigationUri = "/Page2.xaml?value1=content+in+uri&amp;randomNumber=" + randomNumber.ToString()
     };
     tileCreate.CreateSecondaryTile();
</pre></div>
<p>So this example has a few more elements in it. We are now setting the NavigationUri to a relative path to a xaml page in our app and can include a querystring. We also set the Front’s image using content inside the XAP. This can also be a URI pointing to an image on the Internet (and can even come from IsolatedStorage, but more on that in a later blog post). </p>
<p>Finally we call CreateSecondaryLiveTile(). The naming of that method is not 100% accurate. It actually will detect changes and apply an update to your tile instead. The big thing is that when updating a secondary tile you have to provide all the information (not just changes), because we aren’t given the ability to reload the content that was previously entered, so we don’t really know, for instance, what was originally the Content of the back of the tile. We can only really detect that there was a tile there before pointing at a specific URI in our XAP. </p>
<h1>Additional Functions/Methods</h1>
<p>Speaking of existing tiles there are a couple additional static methods that are exposed. You can call LiveTileTemplate.GetExists(“/path/to/aPage.xaml?querystring=somevalue&amp;qs2=someValue&amp;etc”) and it will return to you whether a SecondaryTile already exists for that Uri. This is useful because when you create a secondary tile the OS automatically takes the user to the start screen. If the Tile already exists then they stay in the app. You want to be able to let the user know that the tile was updated instead of created in this second instance and now you can know what is going to happen next before proceeding with the action. My comic reader throws up mock toast notifications in the case where the tile has been updated instead of created.</p>
<p>Finally there is one more static method that you might be interested in. LiveTileTemplate.DeleteSecondaryTile(“/path/to/aPage.xaml?querystring=somevalue&amp;qs2=someValue&amp;etc”) deletes a previously created tile using the Navigation Uri.</p>
<p>There are also one more additional method and a constant that are pertinent to using an image from IsolatedStorage, but that will wait for another post.</p>
<h1>LiveTileTemplate Properties</h1>
<p>Here’s the properties (and their meaning and additional info) that you can set in the LiveTileTemplate Class:</p>
<ul>
<li>FrontSideTileTitle – The title that appears on the front side of a tile (If this value is null then class will try to infer the name of your app from the Assembly’s name)</li>
<li>FrontSideBackgroundImage – Set’s the image for the front side of the tile (the default is to use the Background.png file that is part of your XAP. Also, I’m not sure if you are allowed to radically change this and get accepted into the marketplace, so change this with caution would be my advice)</li>
<li>FrontSideUriType – sets whether FrontSideUri is a relative or an absolute Uri. (We default to relative, but if we detect an isolated storage Uri we switch to an absolute Uri).</li>
<li>FrontSideTileCountContent – (optionally) sets the number that will appear on the front side of the tile. (We default to null which means no number)</li>
<li>BackSideTileTitle - The title that appears on the back side of a tile (If this value is null then we grab the title of the front side of the tile or if that is null we use the name of the Assembly)</li>
<li>BackSideTileContent – This is the text that will appear on the back side of your tile.</li>
<li>BackSideBackgroundImage – Set’s the image for the back side of the tile (leaving this blank will use the user’s accent color)</li>
<li>BackSideUriType – sets whether BackSideUri is a relative or an absolute Uri. (We default to relative, but if we detect an isolated storage Uri we switch to an absolute Uri).</li>
<li>NavigationUri – sets the Navigation Uri that is used when the user clicks the live tile. (this should be a deep link into your app and may even be a link that in a place in your app that is inaccessible in other ways; it’s pretty cool that you can do this)</li></ul>
<h1>Download</h1>
<p>You can get the class and a sample project from my <a href="https://bitbucket.org/DevTheo/wp7livetileincode/overview" target="_blank">source code repo for this</a>. I have a couple more things I will be doing with this (and another article.. hopefully soon).</p>
<ul><br></ul><br /><a href='http://www.jaykimble.net/mango-live-tile-helper.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/sNspmLyzxWA/mango-live-tile-helper.aspx</link>
      <comments>http://www.jaykimble.net/mango-live-tile-helper.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/mango-live-tile-helper.aspx</guid>
      <pubDate>Fri, 21 Oct 2011 08:39:18 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/mango-live-tile-helper.aspx</feedburner:origLink></item>
    <item>
      <title>Download Queue code&amp;hellip;</title>
      <description><![CDATA[<p>Here’s code/slides to my recent talks (I thought I already posted this)</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:b0f9ab7f-00bc-4a3b-a412-67ed2e7eafaa" class="wlWriterEditableSmartContent"><div><a href="http://jaykimble.net/Data/Sites/1/Windows-Live-Writer/52a964de0fe2_C620/WP7-Strategies.For.Transferring.Data.Files.pptx" target="_blank">WP7-Strategies For Transferring Data Files.pptx</a></div></div> <p><br><a href="https://bitbucket.org/DevTheo/wpdownloadqueue/overview" target="_blank">Repo for the Source code</a></p><br /><a href='http://www.jaykimble.net/download-queue-code-hellip.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/c7H0JmvB98U/download-queue-code-hellip.aspx</link>
      <comments>http://www.jaykimble.net/download-queue-code-hellip.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/download-queue-code-hellip.aspx</guid>
      <pubDate>Sat, 01 Oct 2011 18:13:02 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/download-queue-code-hellip.aspx</feedburner:origLink></item>
    <item>
      <title>Intradynamics, LLC: Open For Business (again)!!</title>
      <description><![CDATA[<p>I just wanted to throw out a quick post letting the world know that I went independent again. Today is the first day in my business’ new start! I’m totally psyched! I’m going to be doing a variety of things: Silverlight (of course), Mobile, ASP.NET, and Javascript (aka HTML5 aka Ajax/Web2.0 aka DHTML… etc.). (and this is just my plan for the first week &lt;grin/&gt;).</p> <p>One word of warning, I will be interspersing some content in here that isn’t purely Silverlight (and yes, this blog is about to be back in full motion again.. well, I hope so). I will try to keep the content pertinent to Silverlight though (but some of this stuff might be just off the corner.. for instance I have an upcoming Orchard CMS post coming very soon).</p><br /><a href='http://www.jaykimble.net/intradynamics-llc-open-for-business-again.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/DdKr-H9mYy0/intradynamics-llc-open-for-business-again.aspx</link>
      <comments>http://www.jaykimble.net/intradynamics-llc-open-for-business-again.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/intradynamics-llc-open-for-business-again.aspx</guid>
      <pubDate>Sat, 01 Oct 2011 18:02:29 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/intradynamics-llc-open-for-business-again.aspx</feedburner:origLink></item>
    <item>
      <title>Silverlight/WP7 tip: Detecting when in VS Design Mode</title>
      <description><![CDATA[<p>I have struggled with dealing with this for sometime, and ultimately gave up. Today, I happened across something interesting. I’m doing some intense Isolated Storage stuff with WP7, and I’m using ViewModel. I analyzed one of the errors I was getting in the VS XAML designer, and discovered what in my ViewModel VS didn’t like. So here’s what I discovered.</p> <h3>The Technique</h3> <p>You can detect Visual Studio Design Mode by checking isolated storage. It throws an error when you try to access it from within Visual Studio. This is immensely useful when working with ViewModels that you are instantiating in either XAML or CodeBehind or even some kind of locator class. I wrote a little class in the vein of some of the code in MVVM Light (hopefully I can get Laurent to add this to the next version).</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">using</span> System.IO.IsolatedStorage;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">namespace</span> AmazingPocketComicsViewer.Model</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> VSDesignDetector</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">static</span> <span style="color: #0000ff">bool</span>? isInDesignModeStatic = <span style="color: #0000ff">null</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">bool</span> IsInDesignModeStatic <span style="color: #008000">// Convenient method that can be accessed out of an inherited class</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            get</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">if</span> (isInDesignModeStatic.HasValue)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    <span style="color: #008000">// only do the check once and use the last value forever</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    <span style="color: #0000ff">return</span> isInDesignModeStatic.Value;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">try</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    var isoStor = IsolatedStorageSettings.ApplicationSettings.Contains(<span style="color: #006080">"asasdasd"</span>);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    isInDesignModeStatic = <span style="color: #0000ff">false</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    <span style="color: #0000ff">return</span> isInDesignModeStatic.Value;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">catch</span> (Exception ex)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                    <span style="color: #008000">// Toss out any errors we get</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// If we get here that means we got an error</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                isInDesignModeStatic = <span style="color: #0000ff">true</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">return</span> isInDesignModeStatic.Value;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">bool</span> IsInDesignMode</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            get</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">return</span> IsInDesignModeStatic;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div>
<p>And that is it! Enjoy!</p><br /><a href='http://www.jaykimble.net/silverlightwp7-tip-detecting-when-in-vs-design-mode.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/HDwZEm24vlw/silverlightwp7-tip-detecting-when-in-vs-design-mode.aspx</link>
      <comments>http://www.jaykimble.net/silverlightwp7-tip-detecting-when-in-vs-design-mode.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/silverlightwp7-tip-detecting-when-in-vs-design-mode.aspx</guid>
      <pubDate>Sat, 01 Oct 2011 18:01:31 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/silverlightwp7-tip-detecting-when-in-vs-design-mode.aspx</feedburner:origLink></item>
    <item>
      <title>Solving the Storage Problem in WP7 (for CF Developers)</title>
      <description><![CDATA[<p>There are a couple apps I would like to write for Windows Phone 7 that don’t currently exist right now. One of which is a Z-Machine emulator (that would be the same engine used in the Infocom text adventure games like the Zork Trilogy). The problem is getting files onto the device. You can’t sync them from the Zune software. You could create a browser to a site and then download the files that way (but sites tend to change).</p> <p>If only there was a way to take advantage of some kind of custom user storage, but the average user really isn’t technical enough to manage a web server, etc. I have been searching a solution to this problem and I now have a solution to the problem. </p> <p>I decided that I needed to go ahead and release a test version of my DropBox Client. You can get a compiled version here - <a href="http://sharpdropbox.codeplex.com/">http://sharpdropbox.codeplex.com/</a></p> <p>I have tried a few others (WP7 Drop Box Clients) and none really were far enough along for me to use. Mine really needs some good testing, but it is far enough along that you can probably use it for browsing a user's DropBox folders/files and can download/open files from there (and they end up on the device in Isolated Storage).</p> <p>It uses Isolated Storage for a file cache and it also caches the calls in a SterlingDB instance (also living in Isolated Storage). The only thing I haven’t fixed/tested yet is it needs to detect that there is no network and it then needs to use the SterlingDB for everything (skipping network calls).</p> <p>I am at the point where I was last trying to implement Delete and Upload (upload keeps failing, so I have given up on that for the moment).</p> <p>I'm may end up implementing a couple of these types of services and creating some kind of loose wrapper/interface around them so you could let the user choose his/her preferred repo. I really wish SkyDrive was accessible through an official SDK in WP7.</p><br /><a href='http://www.jaykimble.net/solving-the-storage-problem-in-wp7-for-cf-developers.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/KtmtLb0cNXc/solving-the-storage-problem-in-wp7-for-cf-developers.aspx</link>
      <comments>http://www.jaykimble.net/solving-the-storage-problem-in-wp7-for-cf-developers.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/solving-the-storage-problem-in-wp7-for-cf-developers.aspx</guid>
      <pubDate>Sat, 01 Oct 2011 18:01:04 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/solving-the-storage-problem-in-wp7-for-cf-developers.aspx</feedburner:origLink></item>
    <item>
      <title>Service-Related APIs and Synchronous/Asynchronous Calls</title>
      <description><![CDATA[<p>I have a small rant today. It relates to APIs that consume some service like Facebook or Dropbox (the latter being the one on my radar). </p> <h2>Some Service Call Guidance</h2> <p>When calling a service directly, you want to use asynchronous methods in all but one case and that one case is during the processing in a web process or a Service (so within an MVC Actrion or Web Form page process, or during processing within your own service). In all other cases that I can think of you want to use Asynchronous calls; these include JavaScript running in browser, Silverlight in or out of browser, Windows Forms app, WPF app, and WP7 application. This is because you keep the app responsive. You can even go so far as to provide a way for the user to cancel a call, but regardless the user can continue using the app while data is being retrieved.</p> <h2>Now the Rant</h2> <p>If you have created a set of APIs that work synchronously retrieves data or makes a service call, this will work with a number of the scenarios I outlined above where I suggested asynchronous was the preferred way (for instance WinForms, WPF, JavaScript all have mechanisms to do Synchronous). But don’t do this. First of all when you go to support Silverlight you will quickly discover that Synchronous calls don’t exist. There are some hacks you can use, but from my experience they make the app unresponsive (and buggy) while calls are happening (so DON’T DO IT!). In fact when I see those hacks it makes me think that you don’t understand Async (and I don’t want to feel that way). </p> <p>In some places I have seen where someone has turned the callbacks into events (so you call the api, and get events to fire). This isn’t terrible, but it assumes that I will always want to do the same thing every time a call comes back. You are better off not doing this.</p> <p>I thought I would show you how to turn a synchronous call into an asynchronous one with minimal effort on your part. Well, you still will need to wrap your head around something like HttpWebRequest, BUT my advice here will help you make it a snap to add Asynchronous callback methods.</p> <h2>My Preferred Signature</h2> <p>First off, I want to show you what I personally like to see (and will give you a couple examples):</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> iCallbackExamples</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">   <span style="color: #008000">// Standard mechnaism that MS APIs typically give you</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">   ServiceResultObject CallSomeServiceSync(</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #0000ff">int</span> param1 <span style="color: #008000">// Insert your service paramters here</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">   <span style="color: #008000">// Standard mechnaism that MS APIs typically give you</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">   <span style="color: #0000ff">void</span> CallSomeServiceAsyncMSWay(</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #0000ff">int</span> param1, <span style="color: #008000">// Insert your service paramters here</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         Action&lt;ServiceResultObject, <span style="color: #0000ff">object</span>&gt; callback, <span style="color: #008000">// success callback</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         Action&lt;Exception, <span style="color: #0000ff">object</span>&gt; errorCallback, <span style="color: #008000">// error callback</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #0000ff">object</span> state <span style="color: #008000">// this is some variable that help you keep track of the call</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                      <span style="color: #008000">// state is the "object" parameters in the Action callbacks</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">     );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">&nbsp;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #008000">// DevTho's preferred variation (with state) of an Async call</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">void</span> CallSomeServiceAsyncWithState(</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">           <span style="color: #0000ff">int</span> param1,   <span style="color: #008000">// Insert your service paramters here</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">           <span style="color: #0000ff">object</span> state, <span style="color: #008000">// this is some variable that help you keep track of the call</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                         <span style="color: #008000">// state is the "object" parameters in the Action callbacks</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">      Action&lt;ServiceResultObject, <span style="color: #0000ff">object</span>, Exception&gt; callback <span style="color: #008000">// callback</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">     );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #008000">// DevTho's preferred variation of an Async call</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">void</span> CallSomeServiceWithoutStateAsync(</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">int</span> param1,   <span style="color: #008000">// Insert your service paramters here</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">        Action&lt;ServiceResultObject, Exception&gt; callback <span style="color: #008000">// callback</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">     );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">     </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #008000">// variation that I can live with</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">void</span> CallSomeServiceAsyncAlternateWithState(</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #0000ff">int</span> param1,   <span style="color: #008000">// Insert your service paramters here</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         Action&lt;ServiceResultObject, <span style="color: #0000ff">object</span>, Exception&gt; callback, <span style="color: #008000">// callback</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #0000ff">object</span> state, <span style="color: #008000">// this is some variable that help you keep track of the call</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                       <span style="color: #008000">// state is the "object" parameters in the Action callbacks</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">     );</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div>
<p>BTW, this is all just to give you an idea of what I think is an acceptable signature. I often don’t use any kind of state object because I typically use an inline anonymous functions (aka Closures), so when I get a callback my local values are all intact and any class level changes have also taken place. (this let’s me return from a call, check the class’ state to see if the data is still valid or not). That callback action will vary depending upon what else I might need back. I have for instance returned the calling parameters in the callback and I will use those as a state check.</p>
<p>Here’s what a call of mine might look like using the “CallSomeServiceWithoutStateAsync” method:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">void</span> needsData(<span style="color: #0000ff">int</span> param1) <span style="color: #008000">// Sorry Stan Schultes only a C# example.. someday I will create an auto convertor for my blog..</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">this</span>.currentParam = param1;  <span style="color: #008000">// class level field value that we'll use to make sure that the request </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                                 <span style="color: #008000">// that is returning matches what is currently being requested (Async calls might return out of order)</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    var someLocalValue = <span style="color: #0000ff">true</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    MyServiceHandler.CallSomeServiceAsyncWithoutState(param1, (result, error) =&gt;{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #008000">// See we are handling the request inline (so this is a closure, it holds the original value of the someLocalValue and can</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #008000">// see the class level variable</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #0000ff">if</span>(error == <span style="color: #0000ff">null</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            <span style="color: #008000">// we have data but is it the data we want</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            <span style="color: #0000ff">if</span>(<span style="color: #0000ff">this</span>.currentParam == param1)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// there might be 2 requests going on because one was taking too long</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// during that time the user might have clicked on something else, so now </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// we need something else. </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// Put the data some place or process it, etc. In Silverlight/WP7 you would</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// Typically be putting this data into a class-level property that is data bound</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// to the XAML. In that case you would need to use the Dispatcher (aka the UI thread) </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">                <span style="color: #008000">// to do this.</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         } </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         <span style="color: #0000ff">else</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">            <span style="color: #008000">// Do something with the error here</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">         }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">      });</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div>
<h2><br>&nbsp;</h2>
<p>I wll do a part 2 to his post (shortly to show you how to easily implement Asynchronous from your synchronous calls). Stay Tuned.</p><br /><a href='http://www.jaykimble.net/service-related-apis-and-synchronousasynchronous-calls.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/leOfltcseyw/service-related-apis-and-synchronousasynchronous-calls.aspx</link>
      <comments>http://www.jaykimble.net/service-related-apis-and-synchronousasynchronous-calls.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/service-related-apis-and-synchronousasynchronous-calls.aspx</guid>
      <pubDate>Sat, 01 Oct 2011 18:00:43 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/service-related-apis-and-synchronousasynchronous-calls.aspx</feedburner:origLink></item>
    <item>
      <title>The Perf Tweak to my WP7 App that turned it from &amp;ldquo;ho hum&amp;rdquo; to &amp;ldquo;Wow!&amp;rdquo; (it works in Silverlight3+ OOB too)</title>
      <description><![CDATA[<p>[If you are in a hurry then the answer is CacheMode=BitmapCache. If you want to read the story/know more then read on]</p> <p>I have been working on a Windows Phone 7 <a href="http://social.zune.net/redirect?type=phoneApp&amp;id=516bb21a-a345-e011-854c-00237de2db9e" target="_blank">comic book reader</a> over the last couple months. It’s actually done and has seen a few revisions. During the testing of my original release, my friend (and fellow member of the Florida WP7 developer’s club) <a href="http://briankassay.com/blog/" target="_blank">Brian Kassay</a> suggested that I should use a different library for my image gestures. </p> <p>You see when you are viewing a comic book page with my reader you are actually looking at a single image which you can move around on the screen as well as can zoom into/out of, and change pages. The page/image viewer was really sluggish on the device. Brian thought it was the gesture library I was using, but nope. after wiring up a different library (the same one Brian uses), the performance was absolutely identical. No change whatsoever.</p> <p>After listening to a bunch of performance podcasts and finally got my head wrapped around the problem. I turned on redraw regions (which is another tip I can give you), and saw that my image was re-rendering everytime I touched it with my finger (panned it around the screen)</p> <p>Back in the Silverlight3 timeframe Microsoft added the ability to create an out of browser app that takes advantage of GPU Acceleration.. One of the things that surrounded this feature was a little property that I had totally ignored: CacheMode. I kind of thought the whole GPU acceleration thing was more about building games and ignored the topic. BUT, GPU Acceleration is on by default in WP7 (and I don’t think there is a way to turn it off). It’s on because guys at Microsoft knew we would need to take advantage of the GPU in WP7 apps more often then in standard Silverlight apps (because we are dealing with a CPU-limited phones). So, I switched this property from the default to “BitmapCache” on my image which was rendering constantly. Instantly I went from slow to fast when panning/zooming the image. </p> <p>You may be wondering “should I turn this on for everything thjen?" Just cache the entire LayoutRoot?” Well, MSDN suggests to “Set the CacheMode property when you need to increase performance for content that is time consuming to render.” CacheMode=BitmapCache simply causes the element it is applied to to render a single time. The resulting Bitmap is cached and re-used for later render cycles (this is probably taking up some memory somewhere). This is great to use on elements that to don’t animate. I would suggest that you look at your WP7 UI and turn on redraw regions. Watch your app you will see what is rendering excessively. Try setting the CacheMode on these elements and see if your performance increases.</p><br /><a href='http://www.jaykimble.net/the-perf-tweak-to-my-wp7-app-that-turned-it-from--ldquoho-hum-rdquo-to--ldquowow-rdquo-it-works-in-silverlight3-oob-too.aspx'>Jay Kimble</a>]]></description>
      <link>http://feedproxy.google.com/~r/DevTheoSL/~3/UwzgkJ2aVho/the-perf-tweak-to-my-wp7-app-that-turned-it-from--ldquoho-hum-rdquo-to--ldquowow-rdquo-it-works-in-silverlight3-oob-too.aspx</link>
      <comments>http://www.jaykimble.net/the-perf-tweak-to-my-wp7-app-that-turned-it-from--ldquoho-hum-rdquo-to--ldquowow-rdquo-it-works-in-silverlight3-oob-too.aspx</comments>
      <guid isPermaLink="false">http://www.jaykimble.net/the-perf-tweak-to-my-wp7-app-that-turned-it-from--ldquoho-hum-rdquo-to--ldquowow-rdquo-it-works-in-silverlight3-oob-too.aspx</guid>
      <pubDate>Thu, 07 Apr 2011 13:00:00 GMT</pubDate>
    <feedburner:origLink>http://www.jaykimble.net/the-perf-tweak-to-my-wp7-app-that-turned-it-from--ldquoho-hum-rdquo-to--ldquowow-rdquo-it-works-in-silverlight3-oob-too.aspx</feedburner:origLink></item>
  </channel>
</rss>
