Sunday, February 26, 2006

Visual Studio .NET plugin for Workspaces source control

A good practive to organize the solution and projects when working with VS.Net is you should always locate the solution file at a level higher in the directory hierarchy than any of the projects in contains. If we create proj1 in c:\temp\test1, we should always put the solution file one level higher, such as c:\temp.

This is very important, otherwise, the OK button will be disabled and you won't be able to add the projects into the workspace. This takes me a while to figure it out.

A good resources for Visual Studio .Net plugin.

Visual Studio .NET plugin for Workspaces source control

Saturday, February 25, 2006

Control the look and feel in Asp.Net.

1> Add a folder called "App_Themes" under the website.
2> Create a different folder under the App_Themes, and each one is a different theme name.
something like this
App_Themes
---- Default
-----Summer
-----Winter
3> In the web configuration file,
, this will associate a theme with the webpage.
4> Add the css files and skin files under the different folder.

Thursday, February 23, 2006

Dispose pattern in C#.

I reviewed some chapters on the dispose pattern on Jeff's book. I really enjoyed reading this book, everytime I read it, it gave me some new thoughts.

A couple of points :

1. If you class has unmanaged resources, you have to implement IDispose pattern to ensure that resources are cleaned up properly. The GC only takes care of the memory, not the other nasty resources issues.

2. The way to implement it:
2-a. Implement a private/protecte methods like Dispose(bool disposing), if the disposing is true, you can access both managed resources which are not collected by GC yet and unmanaged resources. If it's set to false, you cannot access other managed resources since they have the possiblity to have been collected by GC already.
2-b. Implement a Dispose() method, and call Disposing(true), since we are sure it's an explicitly cleaning up.
2-c. Implement a Dispose() method optianlly,and call Disposing(true), since we are sure it's an explicitly cleaning up.
2-d. Implement the finalize() method, and call Disposing(false) . In C#, this finalize method is implemented as a destructor format, though it's not a destructor by any means.

Unraveling Delegates & Events - The Code Project - .NET

Nice explanation about the difference between delegates and events.



Some properties that Events exhibit:

1) Events can only be invoked by the class that defined it.

2) Events can be included in interfaces whereas interfaces cannot contain fields of type delegate.

3) Events cannot reset the delegate invocation list by using “=” outside its class definitions. Events can only add/remove to the handler by using “+=” and “-=” respectively.
Conclusion:

Including Event modifier to the delegate declaration only lets the adding/removing the target to the invocation list and constraints its invocation from outside the class that defines it.

Unraveling
Delegates & Events - The Code Project - .NET

Monday, February 20, 2006

Page.IsPostBack Property

I have to admit I am pretty new to the Asp.Net since most of my work are server-side service programming, or components programming. I get exposed to the Asp.Net since a couple of our freinds want to design a restaurant webiste where people can search enough information before going to a restaurant.

One thing which confused me a bit is when I designed a dropdownlist control to let people select the item, it appears to me that the selection is always get reset when I click on the button. The symptom is that the first item is selected everytime.

It seems that when the page is posted back, the drop down list is always get reset, so the simple trick is to check this :
if (!Page.IsPostBack)
{
//do the actual data binding.
}

Interface implementation in C#.

I read a chapter about interface implemenation in "Applied Microsoft .Net framework programming" and gain some more understanding on this interface topic.

There are basic two types of interface implementation, one is the implicit implementation, in which case, the public/private/protected modifier have to be specified on the implementation. It is the recommended way to implement the interface. Another type of implementation is explicit implementation, in which case, the modifier cannot be added, but the method has to be preceded with the interface name. This will sometimes hide the implementation details, and IS NOT recommended in most cases.

To call the methods in the "explicit implementation", the object has to be casted to the interface type before calling the actual method.

A good example is the Int32 type in the .Net framework, it implements an interface called IConvertible , but you cannot call the ToDouble(), ToByte().. methods until you have to cast the integer to IConvertible.

Thursday, February 16, 2006

DisplayIndex trick.

I spent a couple of hours try to figure out a trick in DisplayIndex of the DataGridView. The trick is that I put the datagridview on a tab page of the tab control, however, when I selected the tab, the display index I set was invalidated. That means, it still shows the original display index, not the index I have set.

I have to put the display index set code in the Tab_SelectedIndexChanged event handler, and set it every time whne the tab is selected. It was not very efficient, but at leat it takes care of the issue.

Quite confusing.

Tuesday, February 14, 2006

Data Mapping in SQL Server Data in C# with ADO.NET

Accessing SQL Server Data in C# with ADO.NET: "SQLServer Type SQL-92 Compliant Type C# Type CLS-Compliant Type
binary + * binary byte[] Byte[]
bigint bigint long Int64
bit bit bool Boolean
char * character char Char
datetime ** datetime DateTime DateTime
decimal dec decimal Decimal
float double precision float Float
image *** varchar Image Image
int integer int Int32
money ++++ SqlMoney SqlMoney
nchar +++ * national character char Char
ntext +++ national text string String
nvarchar +++ **** national character varying char ArrayList Char ArrayList
numeric dec decimal Decimal
real double precision float Float
smalldatetime ** smalldatetime DateTime DateTime
smallint smallint short Int16
smallmoney ++++ SqlMoney SqlMoney
sql_variant sql_variant object Object
text text string String
timestamp ++ rowversion byte ArrayList Byte ArrayList
tinyint tinyint byte Byte
varbinary + **** binary varying byte ArrayList Byte ArrayList
varchar **** character varying char ArrayList Char ArrayList
uniqueidentifier uniqueidentifier byte[16] or Guid Byte[16] or Guid"

Copied from mitbbs, not mine.

Just back from Google on-site. I am a fresh minted Ph.D. in computer science.
It was a long dreadful 5 hour interview by 4 Google enginners, plus the fifth
guy asked my thesis.

A little heads up: be prepare for writing error-free C/C++ code on board given
30 minutes or so. The code has to be generic enough to handle different
platforms and data. Sorry, I can not give out the question in detail here. (as
you know why, please don't ask me) Basically , you must understand from
inside out the memory layout, algorithm and recursion. I prepared for the
interview for about two months, reading algorithm book from cover to cover.
But honestly, none of the interview questions I encountered was what I had
seen before. I wound up digging deep in my old bag of tricks to figure out the
solution. Each interviewer would only ask you one question or two, but hard
enough for you to figure out the solution and possible improvements in 45
minutes. If you screwed, you were done with that Engineer

I don't think I can get the offer. As one of the interviewer said to me, they
turned down a lot of ph.d.s who were not good programmer. The acceptance ratio
is about 1 out of 6, even lower than the best conference in my field.

So take it easy if you are about fly to Google, and enjoy the stay.

Monday, February 13, 2006

NUnit MSBuild Task

A very good resource to include NUnit in MSBuild.

Michael F. Collins, III : NUnit MSBuild Task

My easy work around is like this:

Exec Command="nunit-console.exe $(DeploymentPath)\DDTI.Utilities.UnitTest.dll"
WorkingDirectory="$(PROGRAMEPATH)\NUnit-Net-2.0 2.2.6\bin"

I spent quite a few time to work on the MsBuild today. Honestly, I think I gain more understanding on that. One issue which confused me is that when you embed resource file into the assembly. In Vs.2005, it will append the prefix (such as assemblyname.foldername) before the resource name. But in MsBuild, it won't , so it cause some trouble when trying to reference the resource.

One workaround I figured out is to use "Defined Constants" in the CSC command to control the compiling process. It's kind of like this:

#if MSBUILD
set resourcename= "File.xml"
#else
set resourcename= "AssemblyName.FolderName.File.xml"
#endif

Also, always use $ in front of property name and @ in front of item name.

Friday, February 10, 2006

Edit command file for SSEUtil

SSEUtil is vey powerful, but I have to pay attention when editing those command text file, if you add some extra space , character, or tab... it may cause the SSEUtil unable to parse the command and execute it.

So, please pay attention to edit those command files.

Thursday, February 09, 2006

Good sample to create xml using MSXML in Visual C++

PerfectXML.com - MSXML for C++ Developers :: Creating XML Document Using DOM    

But it’s always painful to check all the HRESULT values in C++ programs, so I end up using the XML class for processing and building simple XML documents.

Std debugging in VS2005

The nice thing about std debugging in vs2005. In previous version of vs2003, the std debugging is not very pleasant, when you define a map object, it’s not very easier to see what it contains in the debugger. Sometimes, I have to write some custom code to loop through the contents to check what it contains. With this new feature in vs 2005, I can see all the contents by just mouse over it. It was so cool….

MSDN

Visual C# Application Development
How to: Use Code Snippets (C#)

The following procedures describe how to use code snippets. Code snippets are available in five ways: through a keyboard shortcut, through IntelliSense auto-completion, through the IntelliSense complete word list, through the Edit menu, and through the context menu.
To use code snippets through keyboard shortcut

1.

In the Visual Studio IDE, open the file that you intend to edit.
2.

In the Code Editor, place the cursor where you would like to insert the code snippet.
3.

Type CTRL+K, CTRL+X.
4.

Select the code snippet from the code snippet inserter and then press TAB or ENTER.

Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.

To use code snippets through IntelliSense auto-completion

1.

In the Visual Studio IDE, open the file that you intend to edit.
2.

In the Code Editor, place the cursor where you would like to insert the code snippet.
3.

Type the shortcut for the code snippet that you want to add to your code.
4.

Type TAB, TAB to invoke the code snippet.

To use code snippets through the IntelliSense Complete Word list

1.

In the Visual Studio IDE, open the file that you intend to edit.
2.

In the Code Editor, place the cursor where you would like to insert the code snippet.
3.

Begin typing the shortcut for the code snippet that you want to add to your code. If automatic completion is turned on, then the IntelliSense complete word list will be displayed. If it does not appear, then press CTRL+SPACE to activate it.
4.

Select the code snippet from the complete word list.
5.

Type TAB, TAB to invoke the code snippet.

To use code snippets through the Edit menu

1.

In the Visual Studio IDE, open the file that you intend to edit.
2.

In the Code Editor, place the cursor where you would like to insert the code snippet.
3.

From the Edit menu, select IntelliSense and then select the Insert Snippet command.
4.

Select the code snippet from the code snippet inserter and then press TAB or ENTER.

Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.

To use code snippets through the context menu

1.

In the Visual Studio IDE, open the file that you intend to edit.
2.

In the Code Editor, place the cursor where you would like to insert the code snippet.
3.

Right-click the cursor and then select the Insert Snippet command from the context menu.
4.

Select the code snippet from the code snippet inserter and then press TAB or ENTER.

Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.

Saturday, February 04, 2006

Method Resolution

Method Resolution

When the Select method is called, the data fields from the data-bound control, the parameters that were created declaratively in the SelectParameters element, and the parameters that were added in the Selecting event handler are all merged. (For more information, see the preceding section.) The ObjectDataSource control then attempts to find a method to call. First, it looks for one or more methods with the name that is specified in the SelectMethod property. If no match is found, an InvalidOperationException exception is thrown. If a match is found, it then looks for matching parameter names. For example, suppose a type that is specified by the TypeName property has two methods named SelectARecord. One SelectARecord has one parameter, ID, and the other SelectARecord has two parameters, Name and Number. If the SelectParameters collection has only one parameter named ID, the SelectARecord method with just the ID parameter is called. The type of the parameter is not checked in resolving the methods. The order of the parameters does not matter.

If the DataObjectTypeName property is set, the method is resolved in a different way. The ObjectDataSource looks for a method with the name that is specified in the SelectMethod property that takes one parameter of the type that is specified in the DataObjectTypeName property. In this case, the name of the parameter does not matter.
this page

MSBuild frustration.

MSBuild frustration.

I spent a lot of time trying to figure out a way to edit the MSBuild project file in the VS 2005. When I referred to the xml schema file, I cannot add the custom properties in the property group, VS kept giving me the annoying warnings. I searched online, not many posts, but there are some people who experienced the same issue with me. But I am sure it’s probably not a common issue. I submitted the post to the MSDN newsgroup, and hopefully, I can get an answer from there.

I am not surprised when I opened the .xsd file, because I know if I add those elements in the schema definition. It was OK. But that just cannot be the issue, and it contradicts with the MSDN documentation.

I ended up editting those xsd file, and hopefully, I can find a satisfactory answer from somewhere.

Friday, February 03, 2006

Projection Concepts

Projection Concepts
1. Ellipsoid: WGS84 (Wordl Geodetic System 1984) and GRS80 () are ellipsoid names.
2. Datum: A paticular datum (like NAD 27 and NAD 83) will use the relevant ellipsoid.
3. Coordiante System: The datum will be used as a base to do the coordinate transfer, the following concepts are coordiantes.
* US State Plane 1927 (both original and exact solutions)
* US State Plane 1983
* UTM (Universal Transverse Mercator) North and South zones
* Gauss-Kruger Modified, 3TM, and 6TM
* XYZ Cartesian ECEF
* XYZ Cartesian Eath-Centered Earth Fixed (ECEF)
* New Zealand Map Grid
* Grids for Argentina, Australia, Austria, Bahrain, Belgium, Borneo, Columbia, Cuba, Egypt, England, France, Ghana, Greece, India, Iraq, Ireland, Italy, Japan, Minnesota, Netherlands, New Brunswick, New Zealand, Nigeria, Peru, Phillipines, Qatar, Quebec, Rumania, Veracruz, and many more. More are being added all the time!
4. Map Projections: formulas used to do the projection
* Albers Equal-Area Conic
* Azimuthal Equal Area
* Azimuthal Equidistant
* Bonne
* Cassini
* Double Stereographic
* Equal-Area Cylindrical
* Equidistant Conic
* Equidistant Cylindrical
* European Stereographic
* Gnomic
* Hotine Oblique Mercator (Rectified Skew Orthomorphic - with the Skew Angle parameter)
* IMW Polyconic
* Lambert Conformal Conic (1 parallel)
* Lambert Conformal Conic (2 parallel)
* Mercator
* Miller Cylindrical
* Mollweide
* Orthographic
* Polar Azimuthal
* Equal Area
* Polar Azimuthal Equidistant
* Polar Stereographic
* Polyconic
* Robinson
* Sinusiodal
* Space Oblique Mercator
* Stereographic
* Stereographic 70
* Transverse Mercator (Gauss-Kruger)
* Two-Point Fit (a special polynomial projection)
* Van der Grinten

Wednesday, February 01, 2006

Bootstrapper for the VC++ 2005 Redists (with MSI 3.1) - The Code Project - C++ / MFC

Bootstrapper for the VC++ 2005 Redists (with MSI 3.1) - The Code Project - C++ / MFC: "including "

I had some difficulty to register my dll on a co-worker's machine until I found this vcredist_x86.exe under C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86