Monday, 14 May 2012

ASP.NET MVC Web Sites (for study)


Today found out Suteki Shop at this address: http://code.google.com/p/sutekishop/

Since it is open-source and uses the technologies such as ASP.NET MVC3, MVC Contrib, NHibernate, Windsor; it would be interesting to look at.

Another one is Nerd Dinner. http://www.nerddinner.com/. Its source can be found here: http://nerddinner.codeplex.com/

Happy MVCing! 

Wednesday, 2 May 2012

WPF: Dynamic Menu

In one of projects I am working on, we have a requirement of showing ‘recent files’ used by the application. The files used by the application are XML files – no custom extension.

Our goal is:

 image

For this task we need the following things:
- a RecentFiles class:
    - should contain the list of recent files
    - should have methods to load/save the list to disk (persistence)
    - should have methods to add a recent file used or delete a non-existing file
- a MenuItem (with children) to show the list

Here is the RecentFiles class:

public partial class RecentFiles
    {
          private ObservableCollection<string> filesField;
          public ObservableCollection<string> Files
          {
              get
              {
                   return this.filesField;
              }
              set
              {
                  this.filesField = value;
          }

          //members for persistence – Load, Save
         //you can find the full class definition in attachments
}

In the Windows.cs, we have a view model WindowViewModel having a property named AppRecentFiles.

Code in WindowViewModel:
      public RecentFiles AppRecentFiles { get; set; }

Code in Windows.cs:
     this._mainWindowViewModel = new MainWindowViewModel();
      this.DataContext = this._mainWindowViewModel;

Now the XAML part:

<MenuItem x:Name="mnuRecentFiles" Header="_Recent Files" ItemsSource="{Binding AppRecentFiles.Files}">
    <MenuItem.Resources>
        <Style TargetType="MenuItem">
            <Setter Property="Command" Value="{Binding ElementName=mnuRecentFiles, Path=DataContext.RecentFileChosenCommand}" />
            <Setter Property="CommandParameter" Value="{Binding}" />
        </Style>
    </MenuItem.Resources>
</MenuItem>


And you are done with the basic infrastructure.

Now all we have to do is:
- add an item to the AppRecentFiles.Files list whenever we load a new file (from the Load option in menu). Tip: add the new item at top of list so that it shows as first item on the menu.
- remove file from list if the user selects a file from 'recent files’ is not found, perhaps after a confirmation message box
- load the recent files by using RecentFiles.LoadFromFile() method – usually done during Window load or app start
- and save (persist) the list by calling RecentFiles.SaveToFile() on App close or window close

Friday, 20 April 2012

There is a new pattern in town!

Just read this MSDN article about how the LightSwitch team modified (or extended) the MVVM pattern. Hold your breath it is called - MVVMVMMD or MV3.

Interesting approach, but if we want to change the view let's say add color - do we go back and change the IPropertyViewModel interface?

Article here:
 http://msdn.microsoft.com/en-us/magazine/hh965661.aspx

Wednesday, 11 April 2012

Slow TFS Performance

Recently the build time of one of our core projects on CruiseControl build server increased substantially. It went from ~8 min to ~20 min.

Upon investigation we found that the "get latest" step by CruiseControl was the bottleneck. I was also facing this problem in Visual Studio 2008, the IDE would hang for about a minute or two when ever get latest was issued. I thought the problem is with VS - probably the general (bad) impression of VS led me to this conclusion. But it was wrong to assume, the problem was with the TFS and how we map the several projects to our local folder.

We removed all unnecessary workspace mappings and also the root mapping. Now there is no local folder mapped for $. And the results are too good. Accessing TFS has become faster and overall performance of Visual Studio 2008 has also improved a lot.

Links which helped:
http://zouak.com/2010/03/24/tfs-slow-in-source-control-operations-workspace-mapping-to-blame/
and the original source: http://blogs.msdn.com/b/granth/archive/2009/05/21/large-team-foundation-server-performance-characteristics.aspx


Saturday, 7 April 2012

Wednesday, 4 April 2012

What to focus on?

Today during the daily commute I was thinking about what technologies I should focus on. After thinking for a while I couldn't keep count of all things, so here it is in writing. :)

These are the areas I want to learn...but prioritization is needed otherwise I would end up learning nothing:

- WPF: In my day job most of the apps I develop are Windows (WPF) applications. So it makes sense for me to dig deeper into WPF. Going deeper into various MVVM frameworks is something I want to pursue.

- ASP.NET: We do have one BIG web application here. It's written nicely and architecture is quite cool. But it is still using WebForms approach, so I need get upto speed with ASP.NET MVC applications (also jQuery).

- .NET 4.0: Specifically parallel and async features - parallel LINQ, parallel task library, async/await. Dynamic feature.

- Unit Testing: especially Mocking tools

- Entity Framework: Although I am comfortable working with LinqToSql, EF is getting better with each new release. Need to get deeper into this (version 5.0 beta released last week.)

- Silverlight: No one is sure about its future, but in my view it is still a formidable option to consider in local-intranet scenarios

Performance / debugging: Go deeper into WinDbg, DebugDiag, performance issues (general and COM)

- iPhone/iPad dev using MonoTouch

- Windows 8 dev: Dip toes in the WinRT development using C# and build Metro applications (registered with a boot camp on May 10)

- Learn more about these concepts: Dependency inversion techniques, Test driven development, SOLID principle

- F#: In some scenarios F# fits very well. Need to at least have "intermediate" level of knowledge.

- Cloud computing, virtualization: This has gathered pace and it can longer be ignored as future of tech. This is in the 'now'. Plan to look into what other vendors offer. Application virtualization is also getting very interesting.

- Scripting: I like what I see in PowerShell, want to get started with it. Using it can be huge time saver in some scenarios.

- Kinect/XBox: Microsoft released Kinect for Windows SDK and the hardware will be launched in Singapore in June. Another exciting technology which can have a huge impact.

- Project management:  This is something big, but necessary. The target is not just to become a better programmer but a manager as well sometime in future.

- Architecture: TOGAF certification


Sunday, 1 April 2012

The cloud is here.

Just read an article about the jobs that will be eliminated because of companies moving to cloud. My initial guess before reading the article was correct - the IT infrastructure support ppl. like network admins, mail server maintenance would be affected first. In fact, the company where I consult recently migrated to Gmail from Outlook and I already see less calls being made to support guys.

So the support group will be affected first and then the "custom development" teams would be affected. Companies whose core function is not IT or where it is treated as a cost center would more readily use cloud.

So how does it affect Microsoft developers like us? We do not have many options. If we want to stick to Microsoft then the only option is to learn about Azure. But I think it is time for a MS developer to leave his comfort zone and start evaluating technologies from other vendors.

Once again 'change' is on horizon. I guess this is how C++/VB developers might have felt circa 2000 when world was changing with .NET release. .NET lasted for a decade and I suspect its time is up. With Windows 8 WinRT exposing its API to C#, bypassing .NET it is a hint of big changes to come. The tablet and mobile will perhaps kill .NET. .NET was built for PC and with PC fading away perhaps its time too has come to go.

I like the closing remarks of the article "Embrace the cloud, don't fight it".

Friday, 30 March 2012

Code snippets in Visual Studio

I must admit I was not a big user of snippets in programming. I used a few because they popped out in intellisense - for example while writing a for-each loop the snippet "foreach" comes up and we intuitively use it.

Never looked deeper to find other snippets. Today I realized I was at a big loss by not using them! Now I am never going to declare a property with all the key-strokes or writing if-else without using snippets. The no. of key strokes required are so less that it will improve developer's productivity by a good margin.

A few I like:
- mbox: If I use only this one it will save a lot of time for me.
- else: This one popped up in intelli sense but still didn't use it. 3 key strokes with snippet and 11 without
- prop: for automatically implemented properties
- ctor: for spitting out the constructor
- svm: for static void main

Other useful ones are 'surrounds with' snippets. Among these I like "try" which surrounds a code block with try-catch statement. What a time saver!

And another cool thing is we can add our snippets, it's just editing an XML file some where. I will see which ones are missing and add on my own. Should be fun.

(This reminds me there is so much still to learn and that even the smallest of things can be of BIG use)

Tuesday, 13 March 2012

Xsd2code

http://xsd2code.codeplex.com/

A tool which helps generate C# code from a XSD file. It can be very useful to generate classes which have a long list of properties - and you want to add WCF DataContract attributes, INotifyProperty code on these properties.

It also can be used when your application has lots of reference data. We can manually create XSD file with the reference data as enumeratio, then generate the class - and use this class in application. The class can be serialized and loaded back again if new items can be added by user.

There is also an option to auto-generate the classes if XSD file changes, I believe this requires installing a VS plug-in. The classes generated are partial classes, we can create another partial classes with same name if we want to add our own business rules.

#read: Code Generation in the .NET Framework Using XML Schema
http://msdn.microsoft.com/en-us/library/aa302301.aspx

Monday, 12 March 2012

Books (currently reading and to read)

Currently reading:
- Advanced MVVM
- LINQ in Action
- Pro LINQ
- WPF Unleashed

To read:
- Software Requirements:



- Pragmatic Programmer
http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X


- The Passionate Programmer: Creating a Remarkable Career in Software Development (Pragmatic Life)
http://www.amazon.com/The-Passionate-Programmer-Remarkable-Development/dp/1934356344/ref=pd_sim_b_6

- Code generation in .NET


Refactoring: Improving the Design of Existing Code






Shorts - week 3, 2022

Post with links to what I am reading: 1. A very good post on different aspects of system architecture: https://lethain.com/introduction-to-a...