Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...
 


Wednesday, January 26

Short-ski Courchevel

Tomorrow-evening (after work - hopefully I can fix all remaining bugs assigned to me) I'm leaving with some friends for a short-ski trip to Courchevel. Conditions are looking great for the moment : lots of snow and a nice weather-forecast for the coming days!

It will surely be a long day : a normal working-day and afterwards more than 900km to travel by car, but I really look forward to it ...

Returning Monday-afternoon means that no much sleep will be left for the start of DevDays on Tuesday. Hopefully I won't fall asleep during the keynote-session of Bill Gates ;-).

Courchevel : here I come!

Update : I've uploaded some pictures on my MSN Space. No doubt about it : the short-ski was great!!

Tuesday, January 25

Geek Dinner Pictures

Last Friday-evening I went to the 3rd geek dinner. If you want to see some geeks in action : David has posted some pictures on his MSN Space. Some nice pictures David and thanks to Roy for the organization!

There are rumors that Patrick is planning to organize a Geek Party next time! Where can I order my tickets Patrick?

Monday, January 24

Voice over IP by Google?

Enterprise Library : coming very soon!

In the coming days, the next generation of the patterns & practices Application Blocks will be released : Enterprise Library. All blocks will be delivered into 1 integrated package.

The Enterprise Library will offer the following advantages (click here for more details).
  • Consistency : all blocks look and behave similarly
  • Extensibility : customize and extend blocks
  • Ease of use : GUI-based configuration editing tool
  • Integration : all blocks work together
Usually I don't like to use code that is wrapped up into separate objects ... Especially if these objects cannot be modified (black box). Code blocks are frequently used to speed up development without knowing what's really going on inside, but my opinion is that it is also very important to know what exactly happens inside. If something goes wrong, you always should be able to fix the problem(s) and so you have to be in charge of the code. Speeding up the development phase with the use of code blocks doesn't automatically mean that performance will be improved (be careful with that assumption). Code-generators are also very tricky because they can create a lot of garbage and debugging generated code can be very annoying ...

Having said that, I really look forward to take a closer look at the Enterprise Library. In the past I've worked already with some blocks (Data Access, Logging [Enterprise Instrumentation Framework], UIP) and they were quite useful, but configuration (xml-files) was not always straightforward. At the MSDN event "Unleashing the Potential of the Microsoft Platform" at the end of 2004, Rudi and David gave a sneak preview of EntLib where could be seen that a lot of work was done to prevent the configuration-troubles, but we still have to wait a little bit to see this in action. Also the integration and consistency of all blocks will be an asset. I believe that EntLib will give developers a lot of extra possibilities from scratch, without having coded one single line of code - it can act as an out-of-the-box start-solution.

Thursday, January 20

Batch update of controls on Winforms

Recently I've (re)viewed a lot of GUI-code during the refactoring phase of my project at the client. Today I noticed for example that a lot of User Controls we use contain many of the same control-types like Textboxes, Labels, ... Most of the time these controls are bound to a datasource - no need for a manual update - but in some scenario's these controls must be reset to an empty string for instance. After you set the datasource to null (remove the databinding), you still need to set the Text-property to an empty string. Instead of setting all these Text-properties separately, I've used the following generic method :

        private void clearTextBoxes()

        {

            //Declare type

            Type type = typeof(TextBox);

 

            //Loop into controls on form

            foreach (Control ctrl in this.Controls)

            {

                //check if type of control is TextBox

                if (ctrl.GetType() == type)

                {

                    ctrl.Text = "";

                }

            }

        }


The method above loops into all controls of the form and sets the Text-properties of all TextBoxes to an empty string.

Pff, no big deal really ... but this can be quite powerful (and handy!) if you are able to organize your control-types in some kind of categories so they are subject for a batch update! You can check on the type of control, the name (or substring of the name) of a control, ...

Another example where databinding for textboxes is done in batch may give you more an idea of what I mean :

        private void setDataBindingForTextBoxes()

        {

            //Declare type

            Type type = typeof(TextBox);

 

            //Loop into controls on form

            foreach (Control ctrl in this.Controls)

            {

                //check if type of control is TextBox

                if (ctrl.GetType() == type)

                {

                    //Add DataBinding assuming that name of TextBox is the same as ColumName

                    ctrl.DataBindings.Add("Text", this.myDataSet.Names, ctrl.Name);

                }

            }

        }


These simple procedures also do a lot to the readability of your code and are easy to maintain. I'm sure that this "method" can be used in many more straightforward situations.

Experimenting ...

The last couple of evenings I've been busy with installing new software on my laptop to experiment a little more. DevPartner SecurityChecker and DevPartner Fault Simulator are installed on my main OS (Windows XP Professional) and I'm looking forward to test these applications with a couple of projects in Visual Studio 2003.

I've also created a new virtual machine [Virtual PC] with OS Windows Server 2003, together with Visual Studio 2005 (Beta 1). This evening I still have to install SQL Server 2005 (Beta 2) and then I'm ready to check out some new cool features. In the near future I also want to take a closer look at Windows SharePoint Services (WSS). A lot to do!

To be continued ...

Update : SQL Server 2005 (Beta 2) should be installed prior to Visual Studio 2005 (beta 1)! The other way around does not work! Grr!

Wednesday, January 19

Longhorn-version for everyone

The next version of the Windows operating system, Longhorn, will be ready for manufacturing in May 2006 and will ship to the public in 7 (yip, seven!) different versions. Read more.

While surfing Paul Thurott's SuperSite for Windows I ran into a lengthy overview of Windows XP Media Center Edition 2005. Interesting reading if you're planning to get a Media Center PC. The operating system is very similar to other versions of Windows XP but adds a second interface, where users can display pictures, play music, watch videos or record TV shows using a remote control.

Other Links

Monday, January 17

Microsoft Developer IT Pro Days

Time flies! Yes indeed : only two more weeks and it's time for the yearly Belgian DevDays. Last year I couldn't make it because of too much work at the customer-site for a go-live, but this year I will definitely be there.

My Agenda
  • Day 1
    • Keynote "The Human Spirit" by Bill Gates
    • Closing The Gap Between Development And Operations: A Developer's Perspective
    • Sneak Preview Of The Future Of Web Development
    • Accessing Your Business' Data Through Information Bridge Framework
    • Best Practices For Windows Forms Development
  • Day 2
    • Keynote "SQL Server 2005" by Kimberly Tripp
    • Visual Studio 2005 (Part 1)
    • Visual Studio 2005 (Part 2)
    • Visual Studio 2005 Team System (Part 1)
    • Visual Studio 2005 Team System (Part 2)
I always feel that choosing the sessions I want to attend on an event is like losing. Especially for day 2 because the sessions about "Distributed .NET Applications" by Ingo Rammer look very promising, but for the moment Visual Studio 2005 has my full attention on Day 2!

I'm also curious about the Community Evening on Day 1. Read the Community Evening Update on the blog of Tom Mertens.

Sunday, January 16

New Compuware Products [RTM]

  • DevPartner Fault Simulator DevPartner Fault Simulator is a unique new developer tool using fault simulation to emulate real-world application errors. This allows developers to work in a predictable, repeatable environment to proactively analyze and debug application error-handling code—leading to a better end-user experience and eliminating the loss of revenue that comes with unplanned application downtime.
  • DevPartner SecurityChecker DevPartner SecurityChecker is a powerful security analysis tool that helps quickly scan, locate and fix known and potential security vulnerabilities in ASP.NET applications written in either C# or Visual Basic .NET. DevPartner SecurityChecker automates detection processes through a combination of runtime, compile-time and integrity analyses that pinpoint the exact location of vulnerable source code and hard-to-find security problems.
Update [News Release] : Compuware Launches New DevPartner Products

Saturday, January 15

RSS Feeds

More and more websites are nowadays offering their content in RSS Feeds (Really Simple Syndication of Rich Site Summary - what's in a name?!). I noticed recently that De Standaard - my favorite Belgian newspaper - delivers RSS feeds for their separate news-sections! Bravo!

Pretty much anything that can be broken down into separate items can be syndicated via RSS. For example :
  • news-items / columns
  • blog-postings
  • recent changes of a website
  • ...
Many weblogs make already their content available in RSS (my RSS). A news aggregator (newsreader) - currently I'm using newsgator - can help you keep up with all your favorite weblogs by checking their RSS feeds and displaying only the new items from each of them. This really helps you to save a lot of time because you don't have to surf to all your favorite webpages to check if there's something new.

The future is RSS! This reminds me that I - as a self-respecting webmaster - should offer RSS feeds on our company website, starting with our event-section and our job-section.

Update : Rss feeds are available for the job- and event-section. Wooha!

Friday, January 14

Belgian Geek Dinner

The 3rd Belgian Geek Dinner is taking place in Brussels [February, 21 - 8PM] : La Maison d'Attila. More details on Roy's blog. I'll be there!

Thursday, January 13

DataBinding DataSet to ListView

Why do I want to databind a ListView-control and not use the DataGrid-control? Well, I think that the ListView-control is more suitable for displaying readonly data and the look and feel is also customizable (see previous post). I regret that DataBinding is not possible for the base ListView-control ...

.NET allows us to create custom controls by using inheritance. In my example I will inherit from the ListView-control and add functionality to this base control to create a custom databound ListView-control.



In the form above a listView is used for displaying all data (stored in a dataset "MyDataSet") and Textboxes are set for updating the data. Binding Textboxes to a dataset is simple :

            //DataBinding for TextBoxes

            this.txtFirstName.DataBindings.Add("Text", this.myDataSet.Names, "FirstName");

            this.txtLastName.DataBindings.Add("Text", this.myDataSet.Names, "LastName");


Binding more complex controls is done via the DataSource property :

                //DataBinding for DataGrid

                this.myDataGrid.DataSource = myDataSet.Names;


So for building a Databound ListView we need to implement a custom DataSource Property [+ DataMember for name of DataTable] and focus on the interaction with the DataSource to retrieve the data for display (DataBinding) in the listView.

I've created a separate project for storing the new databound ListView. In the constructor some defaults are already set for my ListView and I've also created two Properties (DataSource and DataMember).

using System;

using System.Data;

using System.Drawing;

using System.Windows.Forms;

using System.Collections;

 

namespace DataBoundListView

{

    public class MyListView : ListView

    {

        //Variables

        private string dataMember;

        private DataSet dataSource;

        private int columnWidth = 100;

        private CurrencyManager cm;

 

        //Constructor

        public MyListView()

        {

            //set default settings for listView

            this.View = View.Details;

            this.FullRowSelect = true;

            this.MultiSelect = false;

            this.BackColor = Color.Wheat;

            this.ForeColor = Color.Brown;

            this.HideSelection = false;

 

            this.SelectedIndexChanged += new EventHandler(MyListView_SelectedIndexChanged);

        }

 

        //Properties

        public string DataMember

        {

            get { return this.dataMember; }

            set { this.dataMember = value; }

        }

 

        public DataSet DataSource

        {

            get { return this.dataSource; }

            set

            {

                this.dataSource = value;

                this.dataBindControl();

                this.setCurrencyManager();

            }

        }

 

        //Methods

        private void setCurrencyManager()

        {

            //Assign CurrencyManager [from BindingContext]

            this.cm = (CurrencyManager) this.BindingContext[this.dataSource.Tables[dataMember]];

        }

 

        private void dataBindControl()

        {

            this.Clear();

 

            ListViewItem newItem;

 

            //Add columns to ListView

            foreach (DataColumn col in this.dataSource.Tables[dataMember].Columns)

            {

                base.Columns.Add(col.ColumnName, columnWidth, HorizontalAlignment.Left);

            }

 

            for (int i=0; i < this.dataSource.Tables[dataMember].Rows.Count; i++)

            {

                newItem = new ListViewItem();

                //First Column

                newItem.Text = this.dataSource.Tables[dataMember].Rows[i].ItemArray[0].ToString();

                //SubItems

                for (int subItems=1; subItems < base.Columns.Count; subItems++)

                {

                    newItem.SubItems.Add(this.dataSource.Tables[dataMember].Rows[i].ItemArray[subItems].ToString());

                }

 

                this.Items.Add(newItem);

            }

        }

 

        private void MyListView_SelectedIndexChanged(object sender, EventArgs e)

        {

            if (this.SelectedItems.Count > 0)

            {

                //set Position of CurrencyManager to selectedIndex of ListView

                cm.Position = this.SelectedItems[0].Index;

            }

        }

    }

}


In the method "dataBindControl", the databinding is set for the dataSet. First, the columns are added to the listView and afterwards, the rows (item + subItems) are added. This method is called each time the "DataSource" Property is set. "setCurrencyManager" assigns the CurrencyManager and the EventHandler "MyListView_SelectedIndexChanged" sets the position of the CurrencyManager so that other controls bound to myDataSet can be updated.

That's all for coding the custom ListView. The control is now ready to use in a new project ...

            //Using the custom control

            this.myListView = new MyListView();

            this.myListView.DataMember = "Names";

            this.myListView.DataSource = this.myDataSet;


The EventHandlers of the textBoxes are looking after the DataBinding with myDataSet and so for updating the ListView.

        private void txtFirstName_Validated(object sender, System.EventArgs e)

        {

            this.renewDataBinding();

        }

 

        private void txtLastName_Validated(object sender, System.EventArgs e)

        {

            this.renewDataBinding();

        }

 

        private void renewDataBinding()

        {

            this.myListView.DataSource = this.myDataSet;

        }


Useful links

Friday, January 7

Blue Screen for Bill

Bill Gates apparently had a blue screen [Out of system memory] during the yearly Consumer Electronics Show where he did a keynote-presentation. A friend read it this morning in the Belgium Metro newspaper and I found the article back on-line. Read it here [Dutch]. It can happen to everyone of us ;-)

Microsoft Windows AntiSpyware (Beta)

Microsoft just released a beta version of its Windows AntiSpyware application.

Windows AntiSpyware (Beta) is a security technology that helps protect Windows users from spyware and other potentially unwanted software.

Microsoft AntiSpyware HomePage

Tuesday, January 4

Model-View-Controller Pattern

Model-View-Controller (MVC) is a classic design pattern often used by large/complex applications that need the ability to maintain multiple views of the same data. The MVC pattern relies on a clean separation of objects into one of three classes.
  • models for maintaining state [data]
  • views for displaying data [display logic] - forms
  • controllers for handling events that affect the model or view(s) [business logic]
What interests me here is the interaction between these three classes. I'm in the middle of refactoring the user-interface of a quite complex Windows Forms application with lots of usercontrols and the interaction between the classes has been an interesting point of discussion in our development-team.

But let me first explain why we decided to refactor. As I mentioned earlier, the application consists of many complex views and in the beginning all "actions" towards the GUI (top-down) occurred through events. While the application was growing, this event-handling-system became more and more the bottleneck of our application because some events were firing more than desired and a lot of events fired on their turn other events and so on ... Bottomline : we didn't have full control anymore over our event-handling-system (bad performance) and debugging this was a real disaster! That's the reason why we wanted to refactor and to move to a solid implementation of the MVC pattern.

After many brainstorm-sessions we've decided the following interactions between the 3 classes :
  • user input occurs on the View(s)
  • the View notifies the Controller of a change by raising an event to the Controller.
    Example (code for controller)
    //ButtonClick event is handled on controller
    //Property MyButton is defined on myView
    myView.MyButton.Click += new System.EventHandler(this.myButton_Click);
  • the Controller modifies the Model directly using its properties
    Example (code for controller)
    //Property of model is set to true
    myModel.DoProcessing = true;
  • the Controller initiates method calls (actions) on the Views to update the GUI
    Example (code for controller)
    //Call method "RefreshListView" on myView
    //Pass Property (Dataset) of Model
    myView.RefreshListView(myModel.MyDataSet);
The most important decision was to eliminate eventhandling for top-down interaction : Controller --> View. All these events are now being replaced by direct method calls. Eventhandling is now only possible bottom-up : View --> Controller. In that way we hope to gain back full control over our GUI. Debugging will also become more attractive. Our implementation of the MVC-pattern is maybe not appropriate for other projects, but we believe that it is the best way to solve our problems.

After implementation a lot of (manual) testing will be needed to be sure that everything that worked before is still working! MVC does not eliminate the need for user interface testing. Creating automated tests for user interfaces is generally more difficult and time-consuming than for business logic. Therefore, reducing the amount of code that is directly tied to the user interface will also enhance the testability of the application.

Saturday, January 1

Happy 2005

My best wishes for everyone in 2005! May all your dreams come true!

I spent the last evening of 2004 together with my best friends and I must congratulate Marie-Laure and Jackie (and his mother!) for preparing such a delicious meal! I enjoyed it a lot and I look forward to see some pictures of our party!

What will 2005 bring for me personally? Cu you all in 2005! Enjoy!