Xaml gotya

Here's one I'm ashamed to admit caught me as I was finishing up work this evening, it's been a good few weeks since I've gone near wpf/silverlight given I was on holidays and spend my time playing with WF4 and MVC2.

Anyway in screenshot below.. vs2010 .net 3.5 sp1 I was binding some data to a datagrid.

 I omitted to remove the offending closing xml comment you can see in the xaml "-->"

And low and behold the binding breaks down without any prior warning,,,, infact my object collection is totally ignored and the "-->" is passed to the binding, I know this because I removed the binding paths in the columns and was presented with "-->" in my grid...

Just an interesting one to keep in mind.. If you're like me, u couldn't switch off the computer this evening until this peculiar behaviour was explained..

 

Maybe it will save you some time if you come accross it.

 

Moq

How many of you create your own mocks? I've recently been using Mocq and I give it the thumbs up :-)

 Note it's using .net 3.5; time for an upgrade? I can't stress enough how much I love linq, today worked on a problem for a client that were using 3.0; it's a true saying " you never miss the water till the well runs dry" ! 

I wonder however I ever lived without it. 

 Anyway:

Moq (pronounced "Mock-you" or just "Mock") is the only mocking library for .NET developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, type-safe and refactoring-friendly mocking library available. And it supports mocking interfaces as well as classes. Its API is extremely simple and straightforward, and doesn't require any prior knowledge or experience with mocking concepts.

 

var mock = new Mock<ILoveThisFramework>(); 
 
// WOW! No record/replay weirdness?! :) 
mock
.Setup(framework => framework.DownloadExists("2.0.0.0")) 
   
.Returns(true) 
   
.AtMostOnce(); 
 
// Hand mock.Object as a collaborator and exercise it,  
// like calling methods on it... 
ILoveThisFramework lovable = mock.Object; 
bool download = lovable.DownloadExists("2.0.0.0"); 
 
// Verify that the given method was indeed called with the expected value 
mock
.Verify(framework => framework.DownloadExists("2.0.0.0"));

IE9 Beta

A word of warning:

Don't do it :-)

I'm v.guilty for using all the latest technologies so a few weeks back I installed IE9 Beta.

Problems encountered:

MVC2 projects getting 404 a lot, I did see this discussed in an interview with Phil Hack and there was a debate on wheather IE9 was just too fast for MVC2.... do you buy it??

Also I've been having problems with the editor I use to write my blog posts, been using raw html as it just didnt work, tonight i tried and compatibility mode and it works again :-)

What have I gained... nothing new that i'm using.... until I get some time to run through HTML5  (on a months holiday from work, wedding next week and putting final touches on the new house... time constraints ey! )

MVC Binding restriction

There are a few options when restricting what properties of a type get automatically bound by the framework.

Take the Loler type seen in my other MVC2 blog posts.

[code:c#]

[Bind(Include="ID,Name,Description")]
public class Loler
{  
//entity framework generated
}

[/code]

Notice only the ID Name and Description properties will be bound by MVC Framework.

 

Per Usage restriction

[code:c#]

UpdateModel(loler, new[] { "ID", "Name", "Description" });

[/code]

Action method restrictions

[code:c#]

[HttpPost]
ActionResult Create([Bind(Include="ID,Name,Description")] Loler loler)
{
// implementation
}

[/code]

vs2010 parallelism

Take some time to explore the new vs2010 debugger.

Those of you to have experience with multithreading know that it can be a right old PIA (and i'm not talking Primary interop assembly here!).

Try the parallel tasks/stacks in vs2010 and see just how valuable a friend they become :-)

 

In recent times, CPU clock speeds have stagnated and manufacturers have shifted their focus to increasing core counts.
This is problematic for us as programmers because our standard single-threaded code will not automatically run faster as a result of those extra cores.

Spend some time investigating the new Tasks in .net 4.0

Linq in asp.net

A quick sample of how to use linq in your webpages

 

[code:c#]

<% Model.ToList().ForEach(item =>
{ %>
  <tr>
      <td>
          <%: Html.ActionLink("Edit", "Edit", new { id = item.AlbumId })%> |
          <%: Html.ActionLink("Delete", "Delete", new { id = item.AlbumId })%>
      </td>
      <td><%: Html.Truncate(item.Title, 25)%></td>
      <td><%: Html.Truncate(item.Artist.Name, 25)%></td>
      <td><%: item.Genre.Name%></td>
  </tr>
<% }); %>

[/code]

 

I said quick ey!  :-)

Workflow Arguments how to

So you've started up your very first 4.0 Workflow application.
You've added some arguments and want to know how to pass some information..
You can either use the Dictionary approach that exists since 3.0 or you can use the properites you've just created.

 

Thes scrren shots show a simple workflow with an input string UserName and an output string Greeting.

 

 

 

I added an assignment activity and set the "To" to be the output Arguement "Greeting"

 

And set the Value as follows.

 

 

To prove this works I've added a test fixture and implemented it as follows

 

 

 

So there you go. The quickie for today Smile

Syncronization Context

A sample of using SyncronizationContext to post a message back to the UX thread

 

[code:c#]

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    SynchronizationContext ctx = SynchronizationContext.Current;

    ThreadPool.QueueUserWorkItem(_ =>
    {

        WebClient client = new WebClient();

        string html = client.DownloadString("https://www.briankeating.net");
        ctx.Post(state =>
        {
            tbDetails.Text = (string)state;

        }, html);

    });

}

[/code]