#Google Analytic Tracker

Pages

Sep 8, 2007

In Love with ReSharper Again

 

It was awhile ago that I had given up on using ReSharper 2.5. Mostly it was due to its memory usage and performance.  I can't really blame ReSharper developers. This is party because the files and classes that I work with have over 1000 LOC (i.e. an indication of bad programming design).

However, after begging asking for more RAM from my team lead, I finally upgraded my computer to 3GB of RAM. In fact, my company was nice enough to pay for a license of ReSharper 3.0, C# version. Now I am back on more refactoring and making my code nice and clean.

Features that I like the most

Usage Search and Go to

Simple Visual Studio reference search is just isn't enough. Resharper provides many advance search functions to help you navigate and search your codes. For example. Shift + F12 bring you a list of references of your selected type, which can be sorted by projects, files, or namespaces. Alt + Home to jump to the type Base class, and Alt + End list all the Inheritor that you can go to.

Navigation is very important for me to analysis the unfamiliar code.

Importantly, Shift + Alt + F11, which highlight usage of your selected Type or Variable, which is similar to the Google search highlight, but it is search by highlight by usage, not text.

Refactoring

A powerful feature that ReSharper provides is Refactoring. Refactoring is a term that describes modifying the code without change its functionality. The goal of refactoring is to make the code easier to read, maintain, understand, and extent its function.

For example, using the "Move" refactoring function, I can move a class from one namespace to another namespace with a couple of clicks. Resharper will update the usages references for the rest of the code, so that you don't have to update them manually.

Code Correctness Check

The most attractive feature ReSharper has is that it constantly checks if your code is correct. If you are missing a variables, incorrectly passing parameter in different type, ReSharper would highlight the error for you, or warn you. So that you don't have to "try" compile your code to find out and fix your compiling error.

Other Features

Other Features like code completion, Resharper NUnit GUI, Live Templates are very useful.

Performance, Performance and Performance...

With 3 GB of RAM, I haven't encountered much performance issue as before. However, ReSharper still causes issue when I do the following:

  1. Dynamically generating a very large XML file - In my solution project, there is XML file that we store all the hardcoded string. The file is a couple thousand line of code. If you have this file opened, and use another program update its content, ReSharper would take a long time to parse.

    It appears that it would be faster for ReSharper to re-analysis the file instead of trying to updates its in-memory code.
  2. Renaming is slower than VS's Renaming function. If you have a type that is used in many places, using VS's Renaming is actually faster than using ReSharper. I am guessing Resharper has to updates its in-memory code by looping though code DOM, while VS simply find and replace using its reference search.
  3. Memory usage is high - even with 3GB of RAM, my devenv.exe still used up to 600MB (plus an other 600MB of Virtual Memroy).
  4. Get latest Visual Source Safe may causes Visual Studio to hang for awhile because ReSharper will reanalysis the code.

However, these performance issues are trade-off in the end, because ReSharper provides you instant update of the your code status.

I have been Trying to Convert Others

When I introduce this tool to my colleagues when I started working in the my company, I thought I bought a tool that would help them a lot. However, because of its performance, everyone of them uninstalled it.  I

I have tried to get them using ReSharping again after our computer is upgraded, but they still resisted. This tells me even ReSharper is a great product, first impression is very important. I did convert a new developer to use ReSharper :)

3.0 Improvements from Resharper 2.5

...that I experience

One thing I notice is that ReSharper is much more responsive. In the past, typing code while while Resharper is analysis code is painful and slow.  However, with 3.0, it seems like ReSharper stop analyzing while I type, which is much better.

I have encounter way less exception compare to 2.5. In the past, whenever I encounter an exception, ReSharper was bounded not going to work.

Conclusion

Resharper is by far the most intelligent tool that increase coding productive. I recommend C#, or VB developers should give it a try. Of course, it will help if you have more RAM in your computer.

BuzzNet tags: ,

Aug 31, 2007

Calgary .NET Usergroup Sliverlight Presentation

 

Yesterday, my collogues and I went to the Sliverlight Presentation, just 15 minutes late due to traffic. All the pizza were gone with 15+ empty boxes laying on the tables and the floor. I wasn't too happy since there weren't any free food left!

So, what is Sliverlight?

You can either go to Sliverlight Website and find out yourself, or read my own explanation. Basically Sliverlight is a plug-in technology for Web browser which allows browser to execute a stripped-down version of .NET Framework and stream HD contents to the web browser.

Idea behinds SliverLight

From what I understand, Sliverlight's goal is to provide a rich media interactive ability for the web application. With VC1 high definition video format, HD content can be easily stream to the client on the web. Since it is a browser plug-in, it is not OS-dependent (sort of), MAC user will also able to use this technology as long as there is a runtime plug-in for the web browser.

What does Sliverlight Provide?

  • Support HD video format streaming
  • Provide vector graphic manipulation
  • Contains WPF Rendering function
  • Using XAML (similar to WPF) so that business logic can be separated
  • higher fidelity (the presenter likes this word a lot...) I am guessing it means the accuracy or detail of the media and its content SliverLight can provide
  • Seamless and easily plugin installation (don't need to click a lot to install it)
  • Small file size (Sliverlight 1.0 ~ 1.0MB, Sliverlight 1.1 ~ 3.0MB)
  • Isolated storage technology is included (System.IO.IsolatedStorage)
  • JavaScript can still be executed
  • HTMLDom manipulation is provided

And obviously, you can write integrate business logic and graphic manipulation using C# code :)

Comparable Product

As the presenter had said in the beginning, there are many other products out there to help developers deliver rich media contents to the end user though web. One competitive product is Adobe Flash.  From what the presenter said, Adobe Flash has added actionable programming logic so that developer can now do more with Flash application.  I agreed that Flash is designed from top-down approach because it came from the graphic design world, while SliverLight is designed from down to top because it comes from a programming development world.  Which tool is better? I can't say, it really depends on the type of person. But surely for a guy like me who knows more about an abstract class more then a masking layer, there is no debate on what tool I will use.

What the different between Sliverlight 1.0 and Sliverlight 1.1 (Alpha)?

Sliverlight 1.0 only supports video streaming and probably provide the media related manipulation ability, while Sliverlight 1.1 comes with a stripped-down (of sub set of ).NET Framework. So, if you want user to have more interaction than just watching video on the web, then you will need to develop your web app using 1.1.

How much stuff is missing in this .NET? The presenter said Sliverlight supports most of the essential functions. So I guess instead of having 20 some overload of ToString(), you only left a couple. Then again, as a developer, you can always work around it if you need more functions.

What does Visual Studio 8 combining with Sliverlight tool provided?

The best part in the presentation is obviously the coding part, RIGHT!. I mean who would pay attention to webpage that plays 12 videos with no lose of frame per second! If I remember right, even SliverLight is a plug-in for the browser, however, if your machine has DirectX, the video processing will speed up.

Anyway, since I am not sure what Visual Studio 8 has without the Sliverlight SDK, I will explain what I saw during the demo.

  • SliverLight Project Template
    • it is very simple to start up a SliverLight Project. Each time when you run the app (F5), a browser is loaded up and you can test your result
  • Allows User to add WebService debugging
    • you can added a WebService project and execute your Sliverlight application to perform debugging. However, there are some set up needed before you can debug the WebService, Since I don't have much experience in WebService, you will have to find more info about this.
  • Intellisense is supported in XAML
  • Remote Debugging on client machine,
    • you can see how your managed code is being executed on the client browser.
    • too bad you can't do on-the-fly code changes during debugging. I am guessing that because the assembly is sent to the client and can't be modified.

Remote debug on Mac?

The fun part of Visual Studio 2008 is that you can attach to processes on a Mac... well, mac developers will need to download some special installation file to do that, But none of the less, this is indeed a very useful feature. The only things I am worry is security issue and network issue.  I have been trying to do some remoting debugging within my workplace but haven't get it to work.

Current Browser Supports

Goto here for Windows

Goto here for Mac

Goto there for Linux

Some unknown factors

Although so far everything sound great, there is still many pieces of SliverLight the team need to figure out. For example, how does your client communicate between server client with no postback (in asp.net). Is it possible for the Server to push data to the client?  To prevent cross-site scripting (XSS) attacked, the presenter said that the team still researching on what is the best solution to do the communication. So, streaming is fine, but talking between server and client may not be simile. However, from this article Sliverlight can communicate with ASP.NET application service using WCF.

Final Thoughts

Sliverlight currently look very promising of enrich the web application user experience while giving the developer the flexibility to developer or integrate their web application with Sliverlight.  However, since everything is still in development, it is hard to say what this technology will become.

May 30, 2007

InternalsVisibleTo and Strong-Name signed assemblies

 

By now I am guessing only newbie like me would encounter this issue.  Today I was working on my project for my friend. Basically I am writing some kind of user name checking tool that can be call externally by a unmanaged program.  So, I figured that I need to expose my assembly as a COM object. I haven't test out my class yet, but hopefully it works.

Based on the article from my favorite CodeProject website:

Calling Managed .NET C# COM Objects from Unmanaged C++ Code

I need to accomplish 3 things

My class must be implement a specific interface

Both the interface and the class must have a GUID attribute to identify themselves

The assembly must be a strong-name type. (This is the part I am not sure why it has to be a strong-name type, but I am guessing it is because the writer decided to add the assembly to the GAC in his example from the article)

So, to ensure that I have a strong-name type, I followed the article procedure to create a snk (Strong Name Key) file.

Using Visual Studio 2005 Command Prompt,

> sn -k TestKeyPair.snk

The article suggested to do add "[assembly: AssemblyKeyFile("TestKeyPair.snk")]". After trying it, VS2005 warned me that I should added the snk file thought the Project->Properties->Signing tab, which I did

Now, here comes the tricky part, I have a UnitTests that test my internal method of my class.

SO, LET COMPILED

Error: Friends assembly must be strong-named signed (some error like that)

Ok, so it looks like I need to make sure that my UnitTests assembly need to be strong named too. So, I created another snk file call UnitTestsKey.snk, and added this file to my UnitTest project

Try again

   1:  
   2: [assembly: InternalsVisibleTo("UnitTests"]
   3:  
   4: // Compiling Error
   5: // Error 1 Friend assembly reference 'UnitTests' is invalid. 
   6: // Strong-name signed assemblies must specify a public key in 
   7: // their InternalsVisibleTo declarations.

What the heck is this "Public Key" I am missing? After hitting the F1 (for help, really I used F1 for help). Once again, MSDN helps doesn't explain much, especially for newbie like me. Let's GOOGLE it.

Ok, somehow I need to retrieve the public key from either the compiled DLL, or from the snk file.

This blog explains what I need to do, but it missing explain one important thing!

Which DLL's or SNK public key I need? My class, or my UnitTest class? It is important to know because I was confused on how this strong name type work.

After trials and errors, obvious it is the UnitTests's public key that I want.  The idea is that since my UnitTest is strong named and it is encrypted with this special snk file, to allow My Class shares its internal method, it needs to know the UnitTests assembly's public key.

Following the blog's explanation, I obtained the public key though the UnitTests.snk file. I can't get public key from the UnitTest assembly because it didn't compiled.

3rd Try

   1: [assembly: InternalsVisibleTo("UnitTests, PublicKeyToken=8c40a2440ba23747")]
   2:  
   3: // Compiling Error
   4: // Error 1 Friend assembly reference 'UnitTests, PublicKeyToken=8c40a2440ba23747' 
   5: // is invalid. Strong-name signed assemblies must specify a public key in their 
   6: // InternalsVisibleTo declarations.
   7:  

WTF? Let's Google it again.... hmmm... interesting some site is using PublicKeyToken, but some other doesn't, it uses PublicKey in the parameter string. Let use PublicKey

4th Try

   1: [assembly: InternalsVisibleTo("UnitTests, PublicKey=8c40a2440ba23747")]
   2:  
   3: // No compiling Error
   4: // but with Warning
   5: // Warning 1 Assembly reference 'UnitTests, PublicKey=8c40a2440ba23747' 
   6: // is invalid and cannot be resolved

Well, better, but when I compile my UnitTests project, it still failed. My UnitTests doesn't see the internal method of my Class....must be something do with the warning.

Finally, after reading more from an webpage (which unfortunately the webpage link is no longer working), it turns out that in Visual Studio 2005, you need to get the hex value for your public key.

5th Try

   1: [assembly: InternalsVisibleTo("LicenseKeyGeneratorExtendedTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000735a079d1bc7b8ea2b3e6706544e7396e4f3110b49c6529361d83ed66111c2fa4b38bbfb3d074d8ce76ed0a2813a2b9901ae0a88b79c85712e3ec4852fef4435426269f1009e2d79dc90644db171ec0566919f4945b06bce3603cc7af098d2774ec80b79bd182d4394bf75f775d0fecbf1b4ecb21a53aa6b0d9e218a1c223d0")]
   2:  
   3: // No Errors or Warnning

Finally, my solution compiled!

-------------------------------------

Update - Feb 11, 2009

If you still having trouble of making an assembly visible to another, check if you have the following line in your assembly.cs file and remove them:

[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

Recently I tried to expose internal methods in a project to a unit test project.  My solution wouldn't compile, and after checking the assembly.cs in the project, I found these two line. Initially I thought it doesn't really do anything, but after I removed it, the solution compiled. I don't know why it was there in the beginning, but in any case, it works now.

Update – Mar 11, 2009

Some of the references were broken and they are now fixed.

Other References

Strong Names Explained

May 8, 2007

Goodbye ReSharper (at least for now)

 

ReSharper is a very intelligent tool and I like it a lot. It helps me analyze unfamiliar code much easier.

Unfortunately its performance slows down a lot when your project that has large data model and other code generated classes.

I have classes that contain more than 10,000 LOC due to code generation. Even a 4000 LOC file takes a while for ReSharper to parse on my machine, which only has 1GB of ram.

In my case, ReSharper is a memory hog. I often have to check my memory usage so that I know when it is a good time to restart VS2005. Restarting VS2005 is no fun at all. It takes time to shutdown and load the solution.

For some reason, ReSharper memory usage keep increasing as time pass. I am not sure if there is a bug, memory leak, or it caches all the parsed data.

I see the memory of devenv.exe Mem Usage goes as high as 700MB and 1500MB VM size. Page Fault is so high that my computer basically is thrashing.

The memory issue is a big issue since the first time I used ReSharper 2.0 in another company. However, because the project I worked on doesn't involve much code generation, ReSharper performance is fairly alright. Even so, I occasionally unload ReSharper (though registry importing), so that I can quickly open up a solution and inspect the code.

My colleague suggested if ReSharper has a button to stop code analyzing, or skip parsing certain classes for increase in performance, he would like to install ReSharper again. I just hope that next release of ReSharper would have a better perform.

SQLServer "IS NULL", "IsNull()" and "= null"

Today, I ran into something very interesting.. well.. to me at least.

After coding a lot with C#, the NOT EQUAL "!=" syntax is pretty much embedded into my dairy operation in my brain.

Anyhow, surprised to me, when I run the following:

select * from someTable where someKey != null;

is not the same as:

select * from someTable  where someKey IS NOT NULL;

It turns out that I forgot using != performs a comparison operation instead of checking if the value is null. Hence, it try to test if someKey contain a value that matches the value that represent the database "null".

The comparison operation returns UNKOWNOW if either of both operands is null.

Moreover, after digging more about this issue, if you use UDT (User Define Type) in SQL Server, you can also use columnName.IsNull property to check if the column value IS NULL or not. I am not an expert of UDT, so I will stop talking about it here. Just something to know.

References:
IS [NOT] NULL (T-SQL)
MSDN Blogs on SQL Server IS NULL vs. IsNull

Apr 16, 2007

Model View Presenter (MVP) Design Pattern Introduction

As a software developer, I often think how am I able to test my User Interface. There are many business logic that I really what to test, yet, they are embedded with the user interface class which makes it very hard to write automated test.

From one of my old project, I came across this design pattern call Model View Presenter. It is a derivative of Model View Controller.  There a number of articles regarding this design pattern. What I decided to do is put my own explanation on the blog, which reinforce my understand of MVP and hope helps others to understand.

What is MVP?

Typical UI - Data Model

[UI Control (i.e. DataGrid) ] ----> [Data Model (i.e. Database Model)]

Basic Model View Presenter

[UI Control] <-----> Presenter ----->[Data Model]

As  you can see, there is a Presenter Layer in MVP. This layer separate the business logic from your UI Controller. The Presenter will handle the business logic and your UI will focus on the user interaction.

The Goals of MVP

  1. Reduce complexity in a UI by extracting the business logic
  2. Help developer write automated unit test for your business logic
  3. Increase business logic reusable for other UI Controls.

Ask your application grow, your UI complexity increases as time goes. It is a good idea to extract the business logic out so that your UI can focus on the user interactions.

Since the Presenter is not a UI, you can write unit tests for your Presenter class, instead of clicking your UI.

Once you have your Presenter, you can create other UI Controls that uses the same Presenters.

For example:

[UI Control One (e.g. DataGrid)] <------------> [Presenter] ---> [Data Model]

[UI Control Two (e.g. custom ListView]<---------^

So, if one day you don't like your old UI Control, you can create a new one without worrying about the business logic by using the Presenter. Or, if your application allows different view of the same data, you can have multiple UI that uses the Presenter.

MVP Setup

UIControl ----> IView <----Presenter ----> Data Model
     |                                       ^
     |-------------------------------|

IView - an interface which state the contract that what the UIControl needs to have in order to support the Presenter

UIControl - your typical user interface, that must inherit from IView, so that the Presenter can control this UIControl. It should contain no or minimum business logic if possible.

Presenter - the class that can manipulate class that inherits IView . It should contain all the business logic allow us to write tests on it.

Data Model - your database access, file access class, or service access. The idea is to have your Presenter deal with your Data Model, and not your UIControl

MVP Example

I have to apologize that I didn't upload my solution since I just got a new ISP, and I didn't have time to find out what it has to offer! so I will use code snippet

This is a very simple Feedback Controller.

  • Interface IUserFeedBack is our IView
  • MyFeedBackControl is our UIControl
  • UserFeedBackPresenter is our Presenter

IUserFeedBack - this specify what the presenter can do with your UIController. As you can see, this a very basic method that a typical UI will do. However, instead of letting your UI decided when these actions are to be done, your presenter will decide, and your UI just need to do what the function name suggested

   1: using System;
   2:  
   3: namespace MVPExample
   4: {
   5:     /// <summary>
   6:     /// Any control that support IUserFeedBack can work with the UserFeedBackPresenter
   7:     /// </summary>
   8:     public interface IUserFeedBack
   9:     {
  10:         void ClearUserInput();
  11:         void DisplayMessage(String savedMessage);
  12:         void PopulateFeedBackType(String[] data);
  13:         void PopulateItemList(String[] data);
  14:         void SetDefaultFeedBackType(int defaultFeedBackTypeIndex);
  15:         void SetDefaultSelectedOption(int[] defaultSelectedOptions);
  16:     }
  17: }

 

UserFeedBackPresenter - please excuse my poor English spelling and grammar. I have a very simple Presenter which has two important methods: Submit, and Cancel. The Submit() function is called when user submit their feed back though the UI Controller. Once submit is completed, the function will display a message and clear user input. These are the business logic that you may need to do in your presenter, and not your UI Control.

Important: If you look at the constructor, you have to pass a IUserFeedBack object.

   1: using System;
   2: using System.Collections.Generic;
   3:  
   4: using MVPExample;
   5:  
   6: namespace MVPExample
   7: {
   8:     /// <summary>
   9:     /// The presenter is the link between the IUserFeedBack control and your data model
  10:     /// </summary>
  11:     public class UserFeedBackPresenter
  12:     {
  13:         IUserFeedBack userFeedbackControl = null;
  14:         List<String> feedBackTypeList = new List<string>();
  15:         List<String> itemList = new List<string>();
  16:  
  17:         public UserFeedBackPresenter(IUserFeedBack someControl)
  18:         {
  19:             userFeedbackControl = someControl;
  20:  
  21:             feedBackTypeList.Add("Satisfied");
  22:             feedBackTypeList.Add("Alright");
  23:             feedBackTypeList.Add("Unsatisfied");
  24:             feedBackTypeList.Add("No Idea");
  25:  
  26:             userFeedbackControl.PopulateFeedBackType(feedBackTypeList.ToArray());
  27:             userFeedbackControl.SetDefaultFeedBackType(0);
  28:  
  29:             itemList.Add("Customer Service");
  30:             itemList.Add("Product Functionalities");
  31:             itemList.Add("User Interface");
  32:             itemList.Add("Software Defects");
  33:  
  34:             userFeedbackControl.PopulateItemList(itemList.ToArray());
  35:             userFeedbackControl.SetDefaultSelectedOption(new int[] {1,2});
  36:  
  37:         }
  38:  
  39:         public void Submit(string name, string email, string selectedType, string[] selectedOptionList)
  40:         {
  41:             string message = String.Format("Thank you for submitting the following information\nName: {0}\nEmail: {1}\nFeedBack: {2}\nSelected Option:{3}",
  42:                 name, email, selectedType, String.Join(",",  selectedOptionList));
  43:  
  44:             //
  45:             //Save all this information to database, or write stuff to your files
  46:             // 
  47:             //This is where you can access your data model though the presenter, and not the
  48:             //User Interface
  49:             //
  50:  
  51:             //Display message to the user
  52:             userFeedbackControl.DisplayMessage(message);
  53:             userFeedbackControl.ClearUserInput();
  54:  
  55:         }
  56:  
  57:         public void Cancel()
  58:         {
  59:             userFeedbackControl.ClearUserInput();
  60:             userFeedbackControl.DisplayMessage("You have canceled your feedback");
  61:         }
  62:     }
  63: }

 

MyFeedBackControl - this control is derived from UserControl, and IUserFeedBack. It has a combobox that display the type of feedback a user can submit, 2 text boxes that store user name and email,  and a check list box allow user to select what this feedback is related. When user click on the submit, or cancel button, the UI Control doesn't care what the business logic need to do, it lets the presenter deal with it.

Important: If you take a look at the constructor, you see this important part

userFeedBackPresenter = new UserFeedBackPresenter(this);

This passes the control to the presenter, so that presenter can interact with your UIControl.  If we go further from this example, we can have our presenter dictates what field needs to be create during runtime, and the UIControl will only care how to create or what control need to create.

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Windows.Forms;
   4:  
   5: namespace MVPExample
   6: {
   7:     public partial class MyFeedBackControl : UserControl, IUserFeedBack
   8:     {
   9:         //The presenter allows the separation between the UI control and the data model
  10:         private UserFeedBackPresenter userFeedBackPresenter;
  11:  
  12:         #region constructor
  13:  
  14:         public MyFeedBackControl()
  15:         {
  16:             InitializeComponent();
  17:             //passing the control to the presenter
  18:             userFeedBackPresenter = new UserFeedBackPresenter(this);
  19:             FeedBackOptionListBox.CheckOnClick = true;
  20:         }
  21:  
  22:         #endregion
  23:  
  24:         #region event handlers
  25:  
  26:         private void btnCancel_Click(object sender, EventArgs e)
  27:         {
  28:             userFeedBackPresenter.Cancel();
  29:         }
  30:  
  31:         private void btnSubmit_Click(object sender, EventArgs e)
  32:         {
  33:             List<string> selectedOptionList = new List<string>();
  34:             foreach (object item in FeedBackOptionListBox.CheckedItems)
  35:             {
  36:                 selectedOptionList.Add(item.ToString());
  37:             }
  38:  
  39:             userFeedBackPresenter.Submit(
  40:                 this.NameTextBox.Text,
  41:                 this.EmailTextBox.Text,
  42:                 this.FeedBackTypeComboBox.SelectedItem.ToString(),
  43:                 selectedOptionList.ToArray());
  44:         }
  45:  
  46:         #endregion
  47:  
  48:         #region IUserFeedBack Members
  49:  
  50:         /// <summary>
  51:         /// Clears the user input on this control.
  52:         /// </summary>
  53:         public void ClearUserInput()
  54:         {
  55:             FeedBackOptionListBox.ClearSelected();
  56:  
  57:             for (int i = 0; i < FeedBackOptionListBox.Items.Count; i++)
  58:             {
  59:                 FeedBackOptionListBox.SetItemChecked(i, false);
  60:             }
  61:  
  62:             FeedBackTypeComboBox.SelectedItem = FeedBackTypeComboBox.Items[0];
  63:             NameTextBox.Clear();
  64:             EmailTextBox.Clear();
  65:         }
  66:  
  67:         public void DisplayMessage(string message)
  68:         {
  69:             MessageBox.Show(message);
  70:         }
  71:  
  72:         public void PopulateFeedBackType(string[] data)
  73:         {
  74:             //Clear all item in combobox
  75:             this.FeedBackTypeComboBox.Items.Clear();
  76:  
  77:             //populate our combobox with Feedback types
  78:             foreach (string item in data)
  79:             {
  80:                 this.FeedBackTypeComboBox.Items.Add(item);
  81:             }
  82:         }
  83:  
  84:         public void PopulateItemList(string[] data)
  85:         {
  86:             this.FeedBackOptionListBox.Items.Clear();
  87:  
  88:             foreach (string item in data)
  89:             {
  90:                 this.FeedBackOptionListBox.Items.Add(item);
  91:             }
  92:         }
  93:  
  94:         public void SetDefaultFeedBackType(int defaultFeedBackTypeIndex)
  95:         {
  96:             this.FeedBackTypeComboBox.SelectedItem = this.FeedBackTypeComboBox.Items[defaultFeedBackTypeIndex];
  97:         }
  98:  
  99:         public void SetDefaultSelectedOption(int[] defaultSelectedOptions)
 100:         {
 101:             this.FeedBackOptionListBox.ClearSelected();
 102:  
 103:             foreach (int index in defaultSelectedOptions)
 104:             {
 105:                 this.FeedBackOptionListBox.SetItemChecked(index, true);
 106:             }
 107:         }
 108:  
 109:         #endregion
 110:     }
 111: }

Conclusion

As I remember someone has said from the Microsoft, they help the developers to write software by providing abstract layer so that developer don't have to worry about the back end stuff. MVP is similar in a sense that the UIControl doesn't need to care what the presenter does behind. You can have 2 developers in a team. One of them only care about what need the UI have to do (Presenter), and the other only care how the UI display and interact with the user (UIControl). As long as they agree on the IView, everything should work!

Where is the Unit Test?

Yea, I am not a big fan of test driven programming methodology YET! I will write another post about testing using mock framework, specifically RhinoMock in the near future. Then I will continue with this example.