All posts in C#

Have you seen this? Check it out on codeplex !!!

The Microsoft All-In-One Code Framework is a free, centralized code sample library provided by the Microsoft Community team. The goal is to provide typical code samples for all Microsoft development technologies.

The team listens to developers’ pains in MSDN forums, social media and various developer communities and write code samples based on developers’ frequently asked programming tasks. Additionally, there is a free code sample request service you could take advantage in order to request specific code.

Check out the video…

I guess most of you will know by now that ItPro|DevConnections is holding a lottery for two msdn subscriptions for all of those that took advantage of the early bird offer and subscribed for the event before the 30th of September.

Well, I was assigned to perform the lottery which is going to take place today. This got me thinking, What would be the easiest (don’t have time) and geekiest (after all it’s a tech event) way to perform this lottery? And then it stuck me “why don’t I try LightSwitch, it’ll probably take me 10 minutes to prepare a full blown application”? And so it did, here’s what I’ve done:

1. Get the Data

OrdersSchemaSo first I needed the data, meaning the details (first name, last name, email etc.) of all of those that registered before the 30th of September. Luckily this year all the registrations went through a computerized system (that Techaholics made Winking smile) so it was very easy to extract all the data I needed, in a new table “Orders” in a new database.

The “Orders” table schema in the new database looked something like this.

2. Create LightSwitch Project

Next I created a new LightSwitch project using Visual Studio 2010 and the new template that you get when you install the LightSwitch framework. You can watch the video that I’ve made to see how I did it.

LightSwitch Draw application screencast

3. Randomly selecting a winner

The random selection logic that was put inside the button click handler was as shown in the video was:

Timer tm = null;
partial void Button_Execute()
  var orderList = this.OrderCollection.ToList();

  if (tm == null)
    tm = new Timer(new TimerCallback((callbackState) =>
        var list = (List)callbackState;
        Random r = new Random((int)DateTime.Now.Ticks);
        var selectedindex = r.Next(list.Count);
        var winner = list[selectedindex];

        IContentItemProxy proxy = this.FindControl("txtWinner");
        proxy.Invoke(() =>
          var txtWinner = (System.Windows.Controls.TextBox)proxy.Control;
          txtWinner.Text = string.Format("{0} {1} ({2})", 
            winner.Name, winner.LastName, winner.Code);

    tm.Change(Timeout.Infinite, Timeout.Infinite);
    tm = null;


  • None of the selected winners in the above video are the real ones. Winners will be picked later today and officially announced at
  • I don’t guarantee that the winner selection will be made using this application. I just made this one for fun – to explore LightSwitch.
  • The data shown on the screencast are sample data and were deleted once the sample was completed

Last week two security researchers, Thai Duong and Juliano Rizzo, have discovered a bug in the default encryption mechanism used to protect the cookies normally used to implement Forms Authentication in ASP.NET.

Using their tool (the Padding Oracle Exploit Tool or POET), they can repeatedly modify an ASP.NET Forms Authentication cookie encrypted using AES and, by examining the errors returned, determine the Machine Key used to encrypt the cookie. The process is claimed to be 100 percent reliable and takes between 30 and 50 minutes for any site.

Everyone immediately focused on the bug not mentioning what is commonly known as good practice and applied to every production site by any decent software developer “Never expose your production server errors (exceptions) to the client” failing to do so exposes your server to a number of threats not only the one described in the above security vulnerability.

There are several ways you could achieve that and Scott Gu mentions the easiest one in his blog post. An other way you could hide errors from your clients is by handling the Application_Error event in the web app’s Global.asax like this

void Application_Error(object sender, EventArgs e)
    Exception ex = Server.GetLastError();

                //Log any way you feel like

  catch (Exception ex){	}

Last Thursday I was given the opportunity to present my first live meeting. It was part 2 of a live meeting series organized by Microsoft to get people familiar with Visual Studio 2010 and .Net framework 4.0. I spoke about C# 4.0 and Parallel computing.

Things I covered included

  • C# 4.0 Language and compiler features
    Dynamic support, Named and optional parameters, Variance (CoVariants, ContraVariants), Office Programmability
  • Visual C# IDE featues
    Call Hierarchy, NavigateTo, Reference Highlighting, Generate from usage, Intellisence suggestion mode, Live Semantic Errors
  • and Parallel programming in Visual studio 2010
    Parallel API, Parallel Profiling, Parallel debugger, Concurrency visualizer in VS2010

It was a whole different experience from other events I’ve presented since the lack of live audience (they were online) kept me focused to the topics I wanted to present. Overall I think it went very well as people seemed to be very interested and stayed online to listen till the end of the meeting.

As usual I’m posting the slide deck and source code I’ve used in the presentation so that everyone can have a look and play with the new technologies. By the way the meeting was recoded and will be published shortly at, so if you missed it, visit the site.

Protected: Building Facebook applications

Categories: ASP.NET, C#, Great Sites, Popfly, Silverlight, Web
Enter your password to view comments.

This content is password protected. To view it please enter your password below:

As always this time of year I begun thinking on all the things I want to read, listen, view and code during my summer vacation free time, even though I never get the chance to do all the things I plan to ;-).

So I’ve already bought my PSP extra memory (2GB) and plan to fill it with podcasts, webcasts and videos so I can watch on my free time. Technologies and products that I’m especially interested this summer include : Silverlight, WPF, WCF, Visual Studio 2008, Astoria, Jasper, Linq, .Net 3.5, C# 3.0 etc.

I’ve already begun searching for those but I would be grateful if you could give me a hand by proposing stuff you think I should definitely have a look at.

Protected: Restoring Live Writer’s spell checking

Categories: C#, Utils I Like
Enter your password to view comments.

This content is password protected. To view it please enter your password below:

Having been to Mix06 I knew that there were going to be a lot of cool things coming out this year too. So I’ve been following closely Mix07, although I didn’t manage to go this year and I must say that I’m pretty excited with all the things announced (although some were expected 😉 ).

One of the coolest demos I’ve seen so far is the Silverlight Airlines application posted by David Anson. I just hope that it will work for Europe as well as USA soon. Check it out.

Cool silverlight airline demo

In case you’ve didn’t notice Marin has posted a comment regarding my WPFSubsonic project and to be more precise a way I can read my application configuration file through my custom Visual Studio Tool. Now I just need to port it to my solution that supports the INotifyPropertyChanged interface and ObservableCollection class so that SubSonic Object can be bound to WPF controls.

Thanks Martin

Some of you have been asking on my WPFSubsonic project status. Well I have to admit that things have been pretty hectic lately so I haven’t been able to complete it. I still haven’t found a way to pass configuration data on the custom tool but I have thought about it and I’m probably going to use XAML serializer/de-serializer in order to pass a configuration file to the custom tool.

For those of you that you simply can’t wait J, I’m posting a first built. In this build the DAL generation happens through a small executable file so that configuration can be performed through its App.config file.