<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Elegant Code &#187; Live Framework</title>
	<atom:link href="http://elegantcode.com/category/live-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Connecting to Live Mesh with the Live ID Client SDK</title>
	<atom:link href="http://elegantcode.com/category/live-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Elegant Code &#187; Live Framework</title>
	<atom:link href="http://elegantcode.com/category/live-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Connecting to Live Mesh with the Live ID Client SDK</title>
		<link>http://elegantcode.com/2009/03/14/connecting-to-live-mesh-with-the-live-id-client-sdk/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=connecting-to-live-mesh-with-the-live-id-client-sdk</link>
		<comments>http://elegantcode.com/2009/03/14/connecting-to-live-mesh-with-the-live-id-client-sdk/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 21:29:48 +0000</pubDate>
		<dc:creator>Sean Timm</dc:creator>
				<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[Live Framework]]></category>
		<category><![CDATA[Live ID]]></category>
		<category><![CDATA[Live Mesh]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/03/14/connecting-to-live-mesh-with-the-live-id-client-sdk/</guid>
		<description><![CDATA[Microsoft’s Live Framework team recently released the April CTP update of the Live Framework SDK and Tools.&#160; This update has been released publicly on the Download Center, so you can grab it and get started right away. If you want to run the Live Mesh Client beta and the Live Framework Client side by side, [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft’s Live Framework team <a href="http://blogs.msdn.com/liveframework/archive/2009/03/11/live-framework-updated.aspx">recently released</a> the April CTP update of the Live Framework SDK and Tools.&#160; This update has been released publicly on the <a href="http://go.microsoft.com/fwlink/?LinkID=145417">Download Center</a>, so you can grab it and get started right away.</p>  <p>If you want to run the Live Mesh Client beta and the Live Framework Client side by side, you’ll want to make sure and <a href="http://social.msdn.microsoft.com/Forums/en-US/liveframework/thread/2fa9d3f1-029e-44af-9568-1cea81ca78a9">follow the instructions</a> prior to installing the April CTP Update.&#160; Note that you will actually be developing against the Live Framework Client and cannot currently target the Live Mesh Client.&#160; I assume these will merge at some point, and you’ll be able to play in both the live runtime as well as the development runtime, but for now, you’re stuck in the developer playground, so we’ll technically be connecting to the Live Framework Client (not the Live Mesh Client) for now.</p>  <p>I’ve been working on a Live Mesh demo rich client application, and I figured I may as well use the <a href="http://go.microsoft.com/fwlink/?linkid=86974">Live ID Client SDK</a> rather than worry about secure credential storage.&#160; This proved to be a bit challenging for a number of reasons, so I thought I’d post my working formula for those that might follow this dark path.</p>  <p>It turns out that the Live ID Client SDK only supports the x86 platform, so the first thing you’ll run across is the installer blows up while installing it on the x64 platform.&#160; It turns out that it still manages to drop the DLLs you’ll need in <strong>%CommonProgramFiles(x86)%\Microsoft Shared\WLIDClient</strong>.</p>  <p>Create a WPF Application project and add references to Microsoft.LiveFX.Client, Microsoft.LiveFX.ResourceModel, and Microsoft.WindowsLive.Id.Client (found in the aforementioned path as well as <strong>%ProgramFiles(x86)%\Microsoft SDKs\Live Framework\v0.91\API Toolkits\.Net Library</strong>).&#160; Since the Live ID Client SDK will only work for x86, you’ll need to change your Project Settings for the project that will be utilizing the SDK (highlighted below):</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2009/03/image1.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="241" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/03/image-thumb1.png" width="499" border="0" /></a> </p>  <p>While you’re here, add a DefaultUserName setting to store the user’s Live ID name.&#160; We’ll use this later for automatic sign-in:</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2009/03/image2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="257" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/03/image-thumb2.png" width="491" border="0" /></a> </p>  <p>Now that all that’s out of the way, we can get on with writing code.&#160; Throw a button on the default layout, rename it, and add a click handler.&#160; Inside the click handler, add the following code:</p>  <div style="font-size: 10pt; background: white; color: black; font-family: courier new">   <p><span style="color: #2b91af">IdentityManager</span> manager = <span style="color: #2b91af">IdentityManager</span>.CreateInstance(</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; <span style="color: #a31515">&quot;Sean Timm;thread@gmail.com;Live Mesh Demo&quot;</span>,</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; <span style="color: #a31515">&quot;Live Mesh Demo&quot;</span>);</p>    <p style="margin: 0px; padding-top: 0px">&#160;</p>    <p style="margin: 0px; padding-top: 0px"><span style="color: blue">string</span> currentUser = <span style="color: #2b91af">Settings</span>.Default.DefaultUserName;</p>    <p style="margin: 0px; padding-top: 0px"><span style="color: #2b91af">Identity</span> identity;</p>    <p style="margin: 0px; padding-top: 0px"><span style="color: blue">if</span>(<span style="color: #2b91af">String</span>.IsNullOrEmpty(currentUser))</p>    <p style="margin: 0px; padding-top: 0px">{</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; identity = manager.CreateIdentity();</p>    <p style="margin: 0px; padding-top: 0px">}</p>    <p style="margin: 0px; padding-top: 0px"><span style="color: blue">else</span></p>    <p style="margin: 0px; padding-top: 0px">{</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; identity = manager.CreateIdentity(currentUser);</p>    <p style="margin: 0px; padding-top: 0px">}</p> </div>  <p>This code creates the Identity instance that will provide your authentication token.&#160; <font face="Courier New">IdentityManager.CreateInstance</font> takes two parameters: an application ID and an application name.&#160; The application ID is composed of three parts: <em>Company Name</em>;<em>Email Address</em>;<em>Application Name</em>.&#160; In practice, I’ve found I can set this to whatever I want, but the documentation and examples call it out this way, so you’re probably best to stick with this format.&#160; The application name passed in as the second parameter is used during display of the sign in dialog.</p>  <p>If a <font face="Courier New">DefaultUserName</font> has previously been saved, it will instantiate the instance using the value to take advantage of any stored credentials for automatic sign in.&#160; Now add the logic to do the actual sign in:</p>  <div style="font-size: 10pt; background: white; color: black; font-family: courier new">   <p><span style="color: blue">if</span>(identity.SavedCredentials == <span style="color: #2b91af">CredentialType</span>.UserNameAndPassword)</p>    <p style="margin: 0px; padding-top: 0px">{</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; identity.Authenticate(<span style="color: #2b91af">AuthenticationType</span>.Silent);</p>    <p style="margin: 0px; padding-top: 0px">}</p>    <p style="margin: 0px; padding-top: 0px">&#160;</p>    <p style="margin: 0px; padding-top: 0px"><span style="color: blue">if</span>(!identity.IsAuthenticated)</p>    <p style="margin: 0px; padding-top: 0px">{</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; identity.Authenticate();</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; <span style="color: #2b91af">Settings</span>.Default.DefaultUserName = identity.UserName;</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160; <span style="color: #2b91af">Settings</span>.Default.Save();</p>    <p style="margin: 0px; padding-top: 0px">}</p> </div>  <p>This logic checks if both the username and password have been stored from a previous login (based on the <font face="Courier New">DefaultUserName</font> passed into the instance).&#160; If they are available, it authenticates silently.&#160; Otherwise, you’ll get the standard sign in dialog:</p>  <p><a href="http://elegantcode.com/wp-content/uploads/2009/03/image3.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="479" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/03/image-thumb3.png" width="444" border="0" /></a> </p>  <p>Notice the application name above the blue guy.&#160; That’s the value you passed in during creation of the <font face="Courier New">IdentityManager</font>.&#160; Once you log in, the username is saved for future automatic sign-in (if you checked Remember my Password).</p>  <p>To connect to the <font face="Courier New">LiveOperatingEnvironment</font> in the Live Framework Client, you’ll need an authentication token.&#160; You can retrieve an authentication token from your authenticated identity via the following:</p>  <div style="font-size: 10pt; background: white; color: black; font-family: courier new">   <p><span style="color: blue">string</span> token = identity.GetTicket(<span style="color: #a31515">&quot;user-ctp.windows.net&quot;</span>, <span style="color: #a31515">&quot;MBI_SSL&quot;</span>, <span style="color: blue">true</span>);</p> </div>  <p>There are a number of other ways to obtain a token.&#160; If you had been using credentials directly (rather than through the Live ID Client SDK), you could have done so via the following:</p>  <div style="font-size: 10pt; background: white; color: black; font-family: courier new">   <p><span style="color: blue">string</span> token = <span style="color: blue">new</span> System.Net.<span style="color: #2b91af">NetworkCredential</span>(<span style="color: #a31515">&quot;myliveid&quot;</span>, <span style="color: #a31515">&quot;mypassword&quot;</span>).GetWindowsLiveAuthenticationToken();</p> </div>  <p>Now that you have a token, it’s time to connect to the <font face="Courier New">LiveOperatingEnvironment</font>:</p>  <div style="font-size: 10pt; background: white; color: black; font-family: courier new">   <p><span style="color: blue">var</span> uri = <span style="color: blue">new</span> <span style="color: #2b91af">Uri</span>(<span style="color: #a31515">&quot;https://user-ctp.windows.net&quot;</span>);</p>    <p style="margin: 0px; padding-top: 0px"><span style="color: blue">var</span> loe = <span style="color: blue">new</span> <span style="color: #2b91af">LiveOperatingEnvironment</span>();</p>    <p style="margin: 0px; padding-top: 0px">loe.Connect(token,</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">AuthenticationTokenType</span>.UserToken,</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; uri,</p>    <p style="margin: 0px; padding-top: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">new</span> <span style="color: #2b91af">LiveItemAccessOptions</span>(<span style="color: blue">true</span>));</p> </div>  <p>Once this returns, you’re good to go.&#160; It will automatically connect to either the local or cloud environment depending on what’s available, and you can start playing around with the Mesh!</p>  <p>There are a number of asynchronous call alternatives that you can use when it makes sense.&#160; I opted to throw it all in a thread to avoid an unresponsive UI.&#160; Here’s the completed class:</p>  <pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 550px; padding-top: 5px; border-bottom: #cecece 1px solid; background-color: #fbfbfb"><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">using</span> System;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">using</span> System.Threading;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">using</span> System.Windows;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">using</span> MeshDemo.Properties;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">using</span> Microsoft.LiveFX.Client;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">using</span> Microsoft.LiveFX.ResourceModel;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">using</span> Microsoft.WindowsLive.Id.Client;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"><span style="color: #0000ff">namespace</span> MeshDemo
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">{
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  <span style="color: #808080">/// &lt;summary&gt;</span>
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  <span style="color: #808080">/// Interaction logic for MainWindow.xaml</span>
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  <span style="color: #808080">/// &lt;/summary&gt;</span>
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  <span style="color: #0000ff">public</span> partial <span style="color: #0000ff">class</span> MainWindow : Window
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    <span style="color: #0000ff">readonly</span> LiveOperatingEnvironment loe = <span style="color: #0000ff">new</span> LiveOperatingEnvironment();
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    <span style="color: #0000ff">public</span> MainWindow()
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      InitializeComponent();
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> signInButton_Click(<span style="color: #0000ff">object</span> sender, RoutedEventArgs e)
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      signInButton.IsEnabled = <span style="color: #0000ff">false</span>;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      var thread = <span style="color: #0000ff">new</span> Thread(
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">        () =&gt;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">        {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          IdentityManager manager = IdentityManager.CreateInstance(
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            &quot;<span style="color: #8b0000">Sean Timm;thread@gmail.com;Live Mesh Demo</span>&quot;,
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            &quot;<span style="color: #8b0000">Live Mesh Demo</span>&quot;);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">string</span> currentUser = Settings.Default.DefaultUserName;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          Identity identity;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">if</span>(String.IsNullOrEmpty(currentUser))
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            identity = manager.CreateIdentity();
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">else</span>
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            identity = manager.CreateIdentity(currentUser);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">if</span>(identity.SavedCredentials == 
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            CredentialType.UserNameAndPassword)
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            identity.Authenticate(AuthenticationType.Silent);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">if</span>(!identity.IsAuthenticated)
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            identity.Authenticate();
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            Settings.Default.DefaultUserName = identity.UserName;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            Settings.Default.Save();
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">string</span> errorMessage = String.Empty;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">bool</span> isConnected = <span style="color: #0000ff">false</span>;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">if</span>(identity.IsAuthenticated)
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            <span style="color: #0000ff">string</span> token = identity.GetTicket(
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">              &quot;<span style="color: #8b0000">user-ctp.windows.net</span>&quot;, &quot;<span style="color: #8b0000">MBI_SSL</span>&quot;, <span style="color: #0000ff">true</span>);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            var uri = <span style="color: #0000ff">new</span> Uri(&quot;<span style="color: #8b0000">https://user-ctp.windows.net</span>&quot;);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            <span style="color: #0000ff">try</span>
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">              loe.Connect(token, AuthenticationTokenType.UserToken, uri,
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">                    <span style="color: #0000ff">new</span> LiveItemAccessOptions(<span style="color: #0000ff">true</span>));
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">              Action signInComplete = OnSignInComplete;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">              Dispatcher.BeginInvoke(signInComplete);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">              isConnected = <span style="color: #0000ff">true</span>;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            <span style="color: #0000ff">catch</span> (Exception ex)
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">              errorMessage = ex.Message;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">else</span>
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            errorMessage = &quot;<span style="color: #8b0000">Failed to authenticate</span>&quot;;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          <span style="color: #0000ff">if</span>(!isConnected)
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            Action&lt;<span style="color: #0000ff">string</span>&gt; signInFailed = OnSignInFailed;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">            Dispatcher.BeginInvoke(signInFailed, errorMessage);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">        });
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      thread.SetApartmentState(ApartmentState.STA);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      thread.Start();
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> OnSignInComplete()
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      signInButton.Visibility = Visibility.Collapsed;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"></pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> OnSignInFailed(<span style="color: #0000ff">string</span> message)
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      signInButton.IsEnabled = <span style="color: #0000ff">true</span>;
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      <span style="color: #0000ff">if</span>(String.IsNullOrEmpty(message))
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">        MessageBox.Show(&quot;<span style="color: #8b0000">Sign in failed for some frustrating reason.</span>&quot;);
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      <span style="color: #0000ff">else</span>
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      {
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">        MessageBox.Show(String.Format(
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">          &quot;<span style="color: #8b0000">Sign in failed for this frustrating reason: {0}</span>&quot;, message));
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">      }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">    }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  }
</pre><pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">}</pre></pre>

<p>Notice I explicitly set the thread to single-threaded apartment.&#160; The Live ID Client SDK COM dependencies require this.</p>

<p>Now that you can connect, it’s time to go forth and make a Mesh of things!</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/03/14/connecting-to-live-mesh-with-the-live-id-client-sdk/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

