Friday, September 25, 2009

Interesting Interview Code Question

My colleague sent me an interesting interview code question and it's pretty fun.

using System;

namespace SomeNamespaceName {

class A {

public void DoAStuff( ) { Console.WriteLine( "A::DoAStuff()" ); }

}

class B {

public void DoBStuff( ) { Console.WriteLine( "B::DoBStuff()" ); }

}

class C {

A _innerA = new A();

B _innerB = new B( );

public static implicit operator A (C c ) {

return c._innerA;

}

public static implicit operator B( C c ) {

return c._innerB;

}

public void DoAStuff( ) { ( ( A )this ).DoAStuff( ); }

public void DoBStuff( ) { ( ( B )this ).DoBStuff( ); }

}

class Program {

static void PassA( A a ) { a.DoAStuff( ); }

static void PassB( B b ) { b.DoBStuff( ); }

static void Main( string[ ] args ) {

C c = new C( );

PassA( c );

PassB( c );

c.DoAStuff( );

c.DoBStuff( );

}

}

}

Question:

1) What does the code print out?

A: A::DoAStuff()
B::DoBStuff()
A::DoAStuff()
B::DoBStuff()

2) Why does it work?

Op A: Operator Overloading

3) Why would I write code like this?

Mu A: Multiple Inheritance Workaround

4) Explain how it works?

A: Using operator overloading A and B to achieve the “type casting” A and B (not the same instance).

Upgraded my home PC from Vista to Windows 7

Finally I upgraded my Vista from home premium to ultimate. It took more than 3 hours to finish. The process was smooth. After I hit upgrade button then hands-off. I started the Windows 7 upgrade (in-system) it warned me that Vista will no longer available and a few programs or drivers will be no longer compatible. In deed, after the upgrading, my Visual Studio 2008 can't work and have to reinstall.

The upgrade process were divided into the following stages.
  • Copying files (fast)
  • Gathering files, settings, and programs (slow)
  • Expanding Windows
  • Installing features and updates
  • Transferring files, settings, and programs (slow)
So according to my colleague, the installation process is much faster if you are doing a fresh installation.

I am pretty happy with the speed of the operating system. The time of waiting has been significantly reduced comparing to Vista. Visual Studio seems much faster to launch now. IE works much faster and the frequency of hanging is significantly reduced. The interface is much easier to use.

Wednesday, February 11, 2009

Use Visual Studio 2008 SDK to customize TFS


Recently I got a chance to assist someone in the other project of my client to generate a report from TFS. He needed a report of all the details of the changeset in certain period of time. I managed to write some sample code for him with Visual Studio 2008 SDK 1.1 which provides API to query TFS history and get the change-set details.

The code is in C#. The test was very successful; I could query the history; then I got changeset list; then I used the changesetid to get all the objects (change instances). There are two main methods you can find in the attached solution. –QueryHistory [1] and GetChangeset[2].

[1]: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.queryhistory(VS.80).aspx
[2]: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.getchangeset(VS.80).aspx

Sample code:

        private static IEnumerable QueryHistory()
{
TeamFoundationServer tfs = new TeamFoundationServer(tfsName);

// Get a reference to Version Control.
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
string path = @"$/YOUR-TEAM-PROJECT-NAME";
VersionSpec version = VersionSpec.Latest;
int deletionId = 0;
RecursionType recursion = RecursionType.Full;

string user = "YOUR-USER-NAME";
// VersionSpec versionFrom = VersionSpec.ParseSingleSpec("115894", "mahesh_lambe");
//keep it 'null' for first version
VersionSpec versionFrom = null;

// VersionSpec versionTo = VersionSpec.ParseSingleSpec("109014", "mahesh_lambe");
//keep it 'null' for latest version
VersionSpec versionTo = null;

int maxCount = Int32.MaxValue;

bool includeChanges = true;

bool slotMode = true;

bool includeDownloadInfo = true;

IEnumerable enumerable = versionControl.QueryHistory(path, version, deletionId, recursion, user, versionFrom, versionTo, maxCount, includeChanges, slotMode, includeDownloadInfo);

return enumerable;
}


        // Get a reference to our Team Foundation Server.              
private static String tfsName = @"http://YOUR-TFS-SERVER-NAME:8080/";

internal static Changeset GetChangeset(int _changesetNumber)
{
TeamFoundationServer tfs = new TeamFoundationServer(tfsName);

// Get a reference to Version Control.
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
Changeset ch = versionControl.GetChangeset(_changesetNumber, true, true);

Console.WriteLine(ch.ToString());
return ch;
}

Monday, December 15, 2008

WiX 3.0 Integration with VS 2005 or 2008

Here are some good things about WiX3.0 I found out. The WiX 3.0 is supported on both VS2005 and VS2008. We could setup both VS2005 and VS2008 solution to include WiX 3.0 project, or *.wixproj file. I have VS2005 and VS2008 installed on my local and I can edit the WiX project in either of them.

Cool thing to specify output file in GUI and you don't need to remember candle and light any more. Now it is much either to support pre-build and post-build events like normal .NET projects. If you have noticed that in order to replace the Version in the MSI I actually used the pre-build to replace and used post-build to restore the original file.

Tuesday, November 18, 2008

Visual Studio 2008 SP1 + CodeRush XPress 3.2.1 = Awesome

I happened to use Eclipse before and I can understand why someone will be disappointed to use Visual Studio as per C# editor features. But after I started to use Visual Studio 2008 with CodeRush XPress 3.2.1, I am really impressed that Microsoft has been catching up in terms of the editor part with the partnership with CodeRush. It is definitely a Free Productivity Tools for Visual Studio.

Check it out here:
http://msdn.microsoft.com/en-us/vcsharp/dd218053.aspx


Handy shortcuts:

F12 to definition. Ctrl + Shift + 7/ 8 get back.
Shift + F12 : Find all references

Metadata as source
F8
Ctrl + Tab ===== Ctrl Alt Down
Sourcecode outliner power liner

Quick Information
CodeRush Xpress

Quick Navigate
Go to file: Ctrl+Alt +F
Go to symbol: Ctrl+Shift+Q
Highlight usages: Ctrl +Alt +U

Code snippets
-Double tab to build the static

Smarttag
Ctrl .

Refactoring
Ctrl+ '

SP Background Squiggles

Camel-Case navigation
Alt+ Left and Alt Right

Expand /Shrink Selection
Ctrl+Alt+= / Ctrl+Alt+-

Friday, November 14, 2008

A Lap Around VSTS 2010

This is the gist for the a lap around VSTS 2010.
  • No more no Repro
    • Test Recorder
    • Stack-trace for exceptions
  • No more broken builds
    • Gated build
    • Buddy build
  • No more butterfly effects
    • Layers for build
    • Architecture Explorer
    • Sequence Diagram
  • No more regression test
  • Build
    • Workflow for build definition
Other videos

TL03

Microsoft Visual Studio Team System: Software Diagnostics and Quality for Services

TL04

Microsoft Visual Studio Team System Team Foundation Server: How We Use it at Microsoft

TL09

Agile Development with Microsoft Visual Studio

TL15

Architecture without Big Design Up Front

TL24

Improving .NET Application Performance and Scalability

TL37

Microsoft Visual Studio Team System: Leveraging Virtualization to Improve Code Quality with Team Lab

TL45

Microsoft Visual Studio Team System Database Edition: Overview

TL47

Visual Studio Team System: A Lap Around VSTS 2010 (Strongly recommended)

TL51

Research: Contract Checking and Automated Test Generation with Pex

TL52

Team Foundation Server 2010: Cool New Features

TL60

Improving Code Quality with Code Analysis

TL61

Panel: The Future of Unit Testing

PowerShell Free Editor - PowerGUI

You can download from here PowerGUI.

Common Commands

Get-Command Get*

Get-Command -Name Get-PSDrive -Syntax

Get-Help about*

Get-Alias Set-Alias

Get-ChildItem –Path C:\Windows\System32 Out-Host –paging

Remove-Item C:\temp\New.Directory –Recurse

Invoke-Item C:\boot.ini

Copy-Item -Path C:\New.Directory -Destination C:\temp -Recurse -Force –Passthru

Get-Process Get-Member -MemberType Properties Out-Host –Paging

Get-Process Format-Table

Get-Location

Set-Location -Path c:\Windows –PassThru

Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ComputerName . Get-Member -MemberType Property

New-Object -TypeName System.Diagnostics.EventLog -ArgumentList Application

New-Object -ComObject WScript.Shell

New-Object -ComObject WScript.Network

New-Object -ComObject Scripting.Dictionary

New-Object -ComObject Scripting.FileSystemObject

$lnk=$WshShell.CreateShortcut("$Home\Desktop\PSHome.lnk")

Where-Object –FileterScript ($_.Value -lt 3)

ForEach-Object –Process ()

Sort-Object –Property –Descending

$env:PATH

Rem ---- List MSI

Get-WmiObject -Class Win32_Product -ComputerName . Format-Wide -Column 1

Rem ---- To install MSI

(Get-WMIObject -ComputerName PC01 -List Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).InvokeMethod("Install","\\AppSrv\dsp\NewPackage.msi")

Rem ---- To uninstall MSI

(Get-WmiObject -Class Win32_Product -Filter "Name='ILMerge'" -ComputerName . ).InvokeMethod("Uninstall",$null)

Is High Quality Software Worth the Cost?

I can't agree more with Martin Fowler's post on "Is High Quality Software Worth the Cost?". Here is just a repost. https:/...