<?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>Sander van Vliet &#187; LINQ To Twitter</title>
	<atom:link href="http://barad-dur.nl/tag/linq-to-twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://barad-dur.nl</link>
	<description>Land Rovers, .Net en meer!</description>
	<lastBuildDate>Fri, 11 Nov 2011 07:46:15 +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>TwitCast</title>
		<link>http://barad-dur.nl/net/twitcast/</link>
		<comments>http://barad-dur.nl/net/twitcast/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 16:28:22 +0000</pubDate>
		<dc:creator>Sander</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[LINQ To Twitter]]></category>
		<category><![CDATA[TwitCast]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://barad-dur.nl/?p=147</guid>
		<description><![CDATA[What started it Are you using Twitter? Do you like it or absolutely loathe it? I do like it but one thing I don’t like is constantly checking twitter.com to see if someone tweeted something interesting. So a new idea was born and the wasting of time began. The idea Actually it’s pretty simple, I <a href="http://barad-dur.nl/net/twitcast/" class="more-link">Meer &#62;</a>]]></description>
			<content:encoded><![CDATA[<h3>What started it</h3>
<p>Are you using Twitter? Do you  like it or absolutely loathe it? I do like it but one thing I don’t like is  constantly checking twitter.com to see if someone tweeted something interesting. So  a new idea was born and the wasting of time began.</p>
<h3>The idea</h3>
<p>Actually it’s pretty simple, I  wanted an application that showed a pop-up of some kind that shows me the latest  tweet for a minute or so and then disappear, similar to the new e-mail popup  of Outlook. Another feature I wanted to make is that when I mouse over on  the pop-up the app shows me the last 10 tweets from my timeline.</p>
<h3>Problem #1</h3>
<p>First things first, how to get  the last tweets from Twitter? As all programmers are lazy (see <a href="http://blogoscoped.com/archive/2005-08-24-n14.html">http://blogoscoped.com/archive/2005-08-24-n14.html</a>) I’ve started looking for a library that could do this  for me. Lo’ and behold: <a title="LINQ To Twitter" href="http://linqtotwitter.codeplex.com/" target="_blank">LINQ To Twitter</a>. A wrapper around the Twitter web services written by <a title="Joe Mayo's blog" href="http://geekswithblogs.net/WinAZ/Default.aspx" target="_blank">Joe Mayo</a> (Microsoft  MVP) in C#.</p>
<p>So, problem #1 was solved.</p>
<h3>Problem #2</h3>
<p>The next problem was one of UI.  How to display a nice pop-up that gives access to the rest of the application?  What I wanted to do is create a window that slides in from the top of the  screen when a new Tweet is posted and when the mouse is over it, expand to show the  last 10 tweets. Because a default window border doesn’t look all that nice I’ve  decided to use a transparent window:</p>
<table style="height: 316px;" border="0" cellspacing="0" cellpadding="0" width="700">
<tbody>
<tr>
<td width="307" valign="top"><a href="http://barad-dur.nl/wp-content/uploads/2010/03/twitcast-screen.png" rel="lightbox[147]"><img class="alignnone size-full wp-image-148" title="twitcast-screen" src="http://barad-dur.nl/wp-content/uploads/2010/03/twitcast-screen.png" alt="" width="304" height="191" /></a></td>
<td width="307" valign="top"><strong>XAML:</strong></p>
<pre>&lt;Window

 Background="Transparent"
 AllowsTransparency="True"&gt;
 &lt;Grid&gt;
  &lt;Border&gt;
   &lt;ScrollViewer&gt;
    &lt;ItemsControl /&gt;
   &lt;/ScrollViewer&gt;
  &lt;/Border&gt;
 &lt;/Grid&gt;
&lt;/Window&gt;
</pre>
</td>
</tr>
</tbody>
</table>
<p>As you can see it’s a pretty  simple UI but that’s exactly what I wanted. What you see is a transparent Window with a Border and ScrollViewer (the green bit) that hosts an ItemsControl,  nothing fancy so far. The next step was to set the initial position of the  window. A simple RenderTransform took care of that:</p>
<p><strong>XAML:</strong></p>
<pre>&lt;Border.RenderTransform&gt;
&lt;TranslateTransform Y="-360"  /&gt;
&lt;/Border.RenderTransform&gt;
</pre>
<p>The ItemTemplate of the tweets  is also quite straightforward:</p>
<p><strong>XAML:</strong></p>
<pre>&lt;DataTemplate&gt;
  &lt;Border&gt;
    &lt;StackPanel Orientation="Vertical"&gt;
      &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Left"&gt;
        &lt;TextBlock Text="{Binding Path=User.Name}" /&gt;
        &lt;TextBlock Text=" at " /&gt;
        &lt;TextBlock Text="{Binding Path=CreatedAt}" /&gt;
      &lt;/StackPanel&gt;
      &lt;TextBlock Text="{Binding Path=Text}" TextWrapping="Wrap" /&gt;
    &lt;/StackPanel&gt;
  &lt;/Border&gt;
&lt;/DataTemplate&gt;
</pre>
<p>The result looks like this:</p>
<p><a href="http://barad-dur.nl/wp-content/uploads/2010/03/image002.jpg" rel="lightbox[147]"><img class="alignnone size-full wp-image-152" title="image002" src="http://barad-dur.nl/wp-content/uploads/2010/03/image002.jpg" alt="" width="375" height="66" /></a></p>
<h3>Fancy UI</h3>
<p>The important part of the  application was to “popup” (or down actually) when a new tweet is available and when the  mouse enters the application so all tweets are shown. To do this three  storyboards are needed:</p>
<p>1.       Animate to the new tweet view</p>
<p>2.       Animate to the full view</p>
<p>3.        Animate to the hidden view</p>
<p>The storyboards all animate the RenderTransform of the Border that hosts the controls.</p>
<p><strong>XAML:</strong></p>
<pre>&lt;Storyboard  x:Key="Hidden"&gt;
  &lt;DoubleAnimation
    Storyboard.TargetProperty="Opacity"
    To="0.4"
    Duration="0:0:0.2" /&gt;
  &lt;DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
    To="-370"
    Duration="0:0:0.2"
    BeginTime="0:0:0.2" /&gt;
&lt;/Storyboard&gt;
&lt;Storyboard x:Key="NewTweet"&gt;
  &lt;DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
    To="-295"
    Duration="0:0:0.2" /&gt;
   &lt;DoubleAnimation
    Storyboard.TargetProperty="Opacity"
    To="1"
    Duration="0:0:0.2" /&gt;
&lt;/Storyboard&gt;
&lt;Storyboard x:Key"AllTweets"&gt;
  &lt;DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
    To="-20"
    Duration="0:0:0.2" /&gt;
  &lt;DoubleAnimation
    Storyboard.TargetProperty="Opacity"
    To="1"
    Duration="0:0:0.2" /&gt;
&lt;/Storyboard&gt;
</pre>
<p>These storyboards are started  by various events in the application. For example: MouseEnter and MouseLeave on the  Border trigger the AllTweets and Hidden Storyboards.</p>
<h3>Timeline</h3>
<p>So far so good, the UI is  basically finished and all that remains is to fill the application with the tweets  from my timeline. For this I’ve created a Timeline class that contains the TwitterContext and a simple timer for the refresh action. The grunt of  this class is the following LINQ statement:</p>
<p><strong>LINQ:</strong></p>
<pre>var statusTweets =
from tweet in  this.context.Status
where tweet.Type == statusType
            &amp;&amp; tweet.ScreenName == this.screenName
            &amp;&amp; tweet.Count == maximumTweetsPerRefresh
            &amp;&amp; tweet.CreatedAt &gt; lastTweetDate
select tweet;
</pre>
<p>This statement will retrieve all tweets from the timeline specified with  screenName that have been created  since the last refresh.  If this results in 1 or more tweets the Timeline class will raise the NewTweetsAvailable event to notify the application that new tweets are  available to display.</p>
<p>The event handler simply pushes the new tweets to the ItemsControl and starts the NewTweet storyboard to  pop-down the window so the latest tweet is visible.</p>
<h3>Wrap up</h3>
<p>As you can see it’s really  simple to build an application that shows the latest tweets in your Twitter timeline. Of  course there are a few features that are missing, for example the storyboards,  but I’ll blog about them a bit later. Be sure to check <a title="TwitCast on Twitter" href="http://twitter.com/#search?q=%23TwitCast" target="_blank">#TwitCast</a> for updates</p>
<p><strong>Update:</strong></p>
<p>TwitCast is now listed on Codeplex at <a title="TwitCast CodePlex project page" href="http://twitcast.codeplex.com/" target="_blank">http://twitcast.codeplex.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://barad-dur.nl/net/twitcast/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

