Tim Hibbard

Software Architect for EnGraph software
posts - 608, comments - 430, trackbacks - 507

My Links

News



Add to Google





Twitter












Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

EnGraph Blogs

Links

Other

Roll

Monday, January 05, 2009

Simple class to parse Twitter with LINQ

In ParaPlan 4.0, we use twitter to maintain a change log.  I wanted to display this information to our users, so I wrote a little class that calls the RSS feed and uses LINQ to parse the data.  All I need is the message and the date, so that is all it pulls out.

Here is the class:

public class Twitter
{
    public string Message { get; set; }
    public DateTime PubDate { get; set; }
 
    public static List<Twitter> Parse(string User)
    {
        var rv = new List<Twitter>();
        var url = "http://twitter.com/statuses/user_timeline/" + User + ".rss";
 
        var element = XElement.Load(url);
        foreach (var node in element.Element("channel").Elements("item"))
        {
            var twit = new Twitter();
            var message = node.Element("description").Value;
            //remove username information
            twit.Message = message.Replace(User + ": ", string.Empty);
            twit.PubDate = DateTime.Parse(node.Element("pubDate").Value);
            rv.Add(twit);
        }
 
        return rv;
 
    }
}

Our calling code looks like this:

var changes = new List<string>();
 
var fromTwitter = Twitter.Parse("ParaPlan");
fromTwitter.ForEach(t =>
    changes.Add(t.PubDate.ToString("MM/dd/yy") + " - " + t.Message));
 
var list = new ListBox();
 
list.ItemsSource = changes;

 

Technorati Tags: ,,,,

posted @ Monday, January 05, 2009 2:53 PM | Feedback (0) | Filed Under [ .NET Goldstar WPF ]

Friday, January 02, 2009

Benjamin Allan Hibbard

On 12-20-2008, my wife Chelsea, gave birth to our beautiful baby boy Benjamin.  It’s been a crazy exciting and busy couple of weeks so far.  I’ve tried to respond to all the many people that have congratulated us on twitter and facebook, but if I forgot, thank you so much.  All of your kind words and well wishes have been very appreciated!!

Many more pictures here.

Technorati Tags:

posted @ Friday, January 02, 2009 10:26 AM | Feedback (3) |

Tuesday, December 09, 2008

WPF – Hide a listbox when it doesn’t have any items

This code example will show how to hide a listbox from the user when it doesn’t have any items. 

It involves binding the Visibility of the listbox to the Items.Count of the listbox.  We run the Items.Count through a converter that will return a Visibility.Visible object if the Item.Count is not zero.

Here is the converter class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
 
namespace HideAListBox
{
    public class ZeroCollapsedNonZeroVisible : IValueConverter
    {
 
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var rv = Visibility.Visible;
            var val = 0;
            int.TryParse(value.ToString(), out val);
            if (val == 0)
            {
                rv = Visibility.Collapsed;
            }
            return rv;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
 
    }
}

Here is the window code:

<Window x:Class="HideAListBox.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:converter="clr-namespace:HideAListBox"
        Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <converter:ZeroCollapsedNonZeroVisible x:Key="hideListBox"/>
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <Button Content="Add Item" Click="addItemClick" DockPanel.Dock="Top"/>
        <Button Content="Clear Items" Click="clearItemsClick" DockPanel.Dock="Top"/>
        <ListBox Margin="3" BorderBrush="Blue" Name="myListBox" 
                 Visibility="{Binding ElementName=myListBox, 
                              Path=Items.Count, 
                              Converter={StaticResource hideListBox}}"/>
    </DockPanel>
</Window>

The entire project can be downloaded here.

Technorati Tags: ,,

posted @ Tuesday, December 09, 2008 3:48 PM | Feedback (0) |

Tuesday, November 25, 2008

Visual Studio Team System Unit Testing Keyboard Shortcuts

I try to use keyboard shortcuts as much as possible.  Here are some that are handy when unit testing with Visual Studio:

Ctrl + R, A – Run all tests
Ctrl + R, T – Run tests in context (based on if cursor is in function, class, or namespace)
Ctrl + R, F – Runs all tests that are checked in Test Results – very handy because that window is impossible to navigate without a mouse

Ctrl + R, Ctrl + A – Run all tests in debug mode
Ctrl + R, Ctrl + T – Run all tests in context in debug mode
Ctrl + R, Ctrl + F – Run all checked tests in debug mode

 

posted @ Tuesday, November 25, 2008 11:24 AM | Feedback (3) |

Friday, November 21, 2008

Google Sync for Blackberry now syncs contacts

The newest version of Google Sync adds a great new feature of syncing contacts.  Now your Gmail contacts will stay up to date with your Blackberry contacts and vice versa.

Very nice!

Download page here.

Technorati Tags: ,

posted @ Friday, November 21, 2008 9:52 AM | Feedback (1) |

Wednesday, November 19, 2008

TFS - Publish Web Service with TeamBuild

TeamBuild is such a powerful tool.  We use it to run our unit tests and publish our apps using ClickOnce.  Recently we started using it to publish a web service.  This code depends on MSBuildTasks from Tigris.

<PropertyGroup>
  <DeploymentFolder>**SHARED FOLDER ON WEB SERVER**</DeploymentFolder>
  <DeployServerName>**WEB SERVER NAME**</DeployServerName>
  <ApplicationPoolName>ReportingWS</ApplicationPoolName>
  <VirtualDirectory>ReportingWS</VirtualDirectory>
  <WebBinariesLocation>$(BuildDirectoryPath)\Binaries\Release\_PublishedWebSites\ReportingWS</WebBinariesLocation>
</PropertyGroup>
 
<Target Name="AfterCompile">
  <RemoveDir Directories="$(DeploymentFolder)" ContinueOnError="true" />
 
  <Exec Command="xcopy /y /e /i $(WebBinariesLocation) $(DeploymentFolder)"/>
 
  <WebDirectoryDelete VirtualDirectoryName="$(VirtualDirectory)"
                      ContinueOnError="true"
                      ServerName="$(DeployServerName)"/>
  <WebDirectoryCreate VirtualDirectoryName="$(VirtualDirectory)"
                      VirtualDirectoryPhysicalPath="$(DeploymentFolder)"
                      ServerName="$(DeployServerName)"/>
</Target>

Essentially, we just copy the executable files from the Web Service to a shared folder on our web server and map a virtual directory to that shared folder.

posted @ Wednesday, November 19, 2008 5:39 PM | Feedback (0) |

Tuesday, November 18, 2008

VS2008 code snippet for Properties that support INotifyPropertyChanged

This code snippet extends the functionality found in prop code snippet.  It will populate the backing field in the property, check for equality in the setter and call PropertyChanged.  It assumes you have a base class that handles the implementation of INotifyPropertyChanged.

When the snippet is called, it will generate code that looks like this:

private int myVar;
 
public int MyProperty
{
    get { return myVar; }
 
    set
    {
        if (!myVar.Equals(value))
        {
            myVar = value;
            base.OnPropertyChanged("MyProperty");
        }
    }
}

To use this snippet, create a new text file at:
C:\users\<your user name>\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets

Call it “propINP.snippet”

Populate the contents of the file with this:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>propINP</Title>
      <Author>Microsoft Corporation</Author>
      <Description>Code snippet for property and backing field and INotifyPropertyChanged</Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>propINP</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>type</ID>
          <ToolTip>Property type</ToolTip>
          <Default>int</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>property</ID>
          <ToolTip>Property name</ToolTip>
          <Default>MyProperty</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>field</ID>
          <ToolTip>The variable backing this property</ToolTip>
          <Default>myVar</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>