Archive

Archive for the ‘Uncategorized’ Category

Ix Operators

June 12, 2011 Leave a comment

[Updated on 02 Jul 11 after the Rx official release: Renamed Run to ForEach]

[If you don’t know what Ix (Interactive Extensions for .NET) is, then I recommend reading my earlier post.]

There are very good resources (like this video) on Ix operators so I am not going to spend too much time on this but I am going to talk about a few of these operators (my top three) to show how the interactive extensions can make your code easier to write and read.

I will use unit tests to express the functionality I am expecting and will then provide potential solutions without using Ix, and finally showing how Ix would simplify the implementation.

For the code snippets, assume that all methods (excluding the test methods) live in a static class named MyEnumerableScrathPad.

EnumerableEx.Return

You have an object of type T and want an enumerable sequence of T, which includes that object only.

Test
[TestMethod]
public void ReturnTest()
{
    var item = new object();
    var returnedItem = MyEnumerableScratchPad.Return(item).Single();
    Assert.AreSame(item, returnedItem);
}
 

Legacy implementation
public static IEnumerable<T> Return<T>(T item)
{
    return new T[] { item };
}
 

Using Ix
public static IEnumerable<T> Return<T>(T item)
{
    return EnumerableEx.Return(item);
}

 


EnumerableEx.StartWith

You have an enumerable sequence of T and you want to add an instance of type T to the beginning of that sequence.

Test
[TestMethod]
public void StartWithTest()
{
    var count = 10;
    var zero = 0;
    var originalRange = Enumerable.Range(1, count);
    var newRange =  MyEnumerableScratchPad.StartWith(originalRange, zero);
    Assert.AreEqual(zero, newRange.First());
    Assert.AreEqual(count + 1, newRange.Count());
}
 
Legacy implementation #1
public static IEnumerable<T> StartWith<T>(IEnumerable<T> originalSequence, 
  T first)
{
    var list = originalSequence.ToList();
    list.Insert(0, first);
    return list.AsEnumerable();
}

This will make the test pass but this implementation may force you to iterate through the items unnecessarily because of the call to ToList. We were also lucky that this implementation passed the test. If you change the value of count from 10 to int.MaxValue – 1, the test will horribly fail with an OutOfMemoryException. So the idea of converting the enumerable to a list is not a good one.

 
Legacy implementation #2
public static IEnumerable<T> StartWith<T>(IEnumerable<T> originalSequence, 
  T first)
{
    yield return first;
    foreach (var item in originalSequence)
        yield return item;
}

This implementation does not suffer from the problem shown above and passes the test after a fairly long delay (around 10 seconds on my laptop), which is expected as a result of the call to Count, which will iterate through the sequence and one can argue that this is not a good test but it fits the purpose here.

 
Using Ix
public static IEnumerable<T> StartWith<T>(IEnumerable<T> originalSequence, 
T first)
{
    return originalSequence.StartWith(first);
}

Ix also has another overload for StartWith, which takes a param array of items to be inserted at the beginning of the sequence, which can be handy.

 

EnumerableEx.ForEach

You have an enumerable sequence and you want to perform an action for each item of the sequence.

[TestMethod]
public void ForEachTest()
{
    var list = new List<int>();
    var range = Enumerable.Range(1, 10);
    MyEnumerableScratchPad.ForEach(range, list.Add);
    CollectionAssert.AreEqual(range.ToList(), list);
}
 
Legacy implementation #1
public static void ForEach<T>(IEnumerable<T> sequence, Action<T> action)
{    foreach (var item in sequence)
    {
        action(item);
    }
}
Clearly this is a valid solution but we are looking for a more compact solution.
 
Legacy implementation #2
public static void ForEach<T>(IEnumerable<T> sequence, Action<T> action)
{
    Array.ForEach(sequence.ToArray(), action);
}
 
Legacy implementation #3
public static void ForEach<T>(IEnumerable<T> sequence, Action<T> action)
{
    sequence.ToList().ForEach(action);
}

 

Implementations #2 and #3 are not ideal as they both force the enumeration of the sequence before the iterating through the items begins. This is not necessarily a problem but there are some cases where you want to perform the action as soon as the sequence yields a new value.

 
Using Ix
public static void ForEach<T>(IEnumerable<T> sequence, Action<T> action)
{
    sequence.ForEach(action);
}
 

Because most of the Ix operators including ForEach are ported back from the Rx world, there are some interesting additional overloads for ForEach. For example, there is one that takes action of T (the action that needs to be performed on each item) and then another action that will be performed when the iteration over the sequence is completed.

 

These three operators (Return, StartWith and ForEach) are among the simplest of the long list of Ix operators but nonetheless they are the ones I use most as they make code more concise and easier to read.

XMind: Great Mind Mapping Tool

July 30, 2010 Leave a comment

I have been looking for a usable and affordable mind mapping tool for a while. I looked at some popular tools in this area but their price tag and licensing policy put me off. For example, Mind Manager costs £233.83 per machine and I use three machines I use regularly.

Then I came across XMind, which is an open source mind mapping and brainstroming tool. I have been using it for a couple of weeks now and I am very impressed with this product. I am not a mind mapping professional and I am sure more advanced users will find limitations but it does the job for me and many others. You can also upgrade to XMind Pro, which has an annual subscription model and provides some additional features like brainstorming support and export to PDF/Word/PowerPoint.

If you are looking for an affordable (or even a free!) mind mapping tool, make sure you give it a try.

Categories: Uncategorized Tags: ,

Microsoft Development Platform Training Resources

July 14, 2010 Leave a comment

This is a link post with links to tutorials, samples and training courses covering the recent releases of Microsoft’s development platform tools and technologies.


Visual Studio 2010 and .NET Framework 4 Training Kit (June 2010)

Covers:

  • C# 4
  • Visual Basic 10
  • F#
  • Parallel Extensions
  • Windows Communication Foundation
  • Windows Workflow
  • Windows Presentation Foundation
  • ASP.NET 4
  • Windows 7
  • Entity Framework
  • ADO.NET Data Services
  • Managed Extensibility Framework
  • Visual Studio Team System

Download Page


Identity Developer Training Kit (June 2010)

Covers:

  • Windows Identity Foundation

Download Page


Windows Azure Training Kit (June 2010)

Covers:

  • Windows Azure
  • SQL Azure
  • Windows Azure AppFabric Service Bus
  • Windows Azure AppFabric Access Control Service
  • Dallas
  • Access and Identity in the Cloud
  • Windows Azure Storage
  • Windows Azure Deployment

Download Page


Windows Server AppFabric Samples (June 2010)

Covers:

  • Windows Server AppFabric Cache
  • Windows Server AppFabric Hosting

Download Page


Silverlight 4 Training (April 2010)

Covers:

  • Silverlight 4
  • WCF RIA Services

Download Page


MSDN Subscriber Downloads is changing

February 1, 2008 Leave a comment

This change is scheduled for late February and improves the user experience by integrating the downloads and product key functionality into the MSDN web site, providing a better navigation model for browsing the product list and filtering the search results. You can find more information on the enhancements (including some screenshots for the new design) here.

Categories: Uncategorized

Halo 3

September 25, 2007 3 comments

How did I forget to take the rest of the week off?!! :)


Categories: Uncategorized

Sysinternals Troubleshooting Utilities

February 14, 2007 Leave a comment

Just noticed (via Ohad’s blog) that the Sysinternals troubleshooting utilities like FileMon, RegMon, ProcMon and ProcExplorer have been rolled up into a single downloadable package (8MB). Having to open every single product page before downloading was a real pain!

Categories: Uncategorized

Free BizTalk Server 2006 eLearning Offer

August 1, 2006 Leave a comment

If you are interested in learning the basics of BizTalk
Server 2006, you can use the following (time-limited: 90 days from activation
date) Microsoft eLearning:


Clinic 2954: First Look: Microsoft® BizTalk® Server 2006
for Developers

(via
MCPMag.com
)

Categories: Uncategorized

A New Era of Technical Leadership at Microsoft

June 15, 2006 Leave a comment

Remarks by Bill Gates


Highlights:


“I have one of the best jobs in the world.” 
Indeed, but let’s say “the best job” :)



“Of course, with the success of Microsoft, I’ve also been given the gift of great wealth. I believe that with great wealth comes great responsibility, a responsibility to give back to society, a responsibility to see that those resources are put to work in the best possible way to help those most in need.”
I hope we start thinking like he does.

Categories: Uncategorized

UK DDD3 Registration Open

May 1, 2006 Leave a comment

here.


Update: Registration is now full but you can add yourself to the waitlist…

Categories: Uncategorized

Long Awaited Update for O2 XDA Exec is out!

April 24, 2006 Leave a comment

From the O2 web site:
—–
Xda Exec ROM – the Xda Exec System Software

The latest Xda Exec System Software is available for you
to download. New and changed in this version of software, v1.30.162 are:

Microsoft AKU 2 (Adaptation Kit Update) featuring:

  • Microsoft Messaging and Security Feature Pack (MSFP)*
    allowing Direct Push Email, Wireless Calendar, Contacts, Tasks, Global Address List
    (GAL) Lookup and Security Policies.

* Requires organisations to be running Microsoft Exchange
Server 2003 and SP2. Please contact your company IT Manager to confirm your infrastructure
and for assistance with setting up your device for direct push email.

  • Updated Comm Manager, providing new buttons for controlling
    Direct Push Mail and active Data connections.
  • Updated Radio v1.09.00
  • Updated CE image v1.30.107

This software is for Xda Exec in UK and Ireland.
—–

I have diverted my mobile to landline as I won’t be able to answer calls
while my phone is going through the update process!

Follow

Get every new post delivered to your Inbox.