Wednesday, December 28, 2005

MSTest.exe Command-Line Options


I designed a test program using the visual studio 2005 testing suites, but i will prefer doing some automated testing using the command line.

After some research online:
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\MSTest.exe is the right tool to launch the test.

Then , it will be easier to add this into the automatic testing in the IDE.

Monday, December 26, 2005

Using the Windows Headers - a good reference

Using the Windows Headers


Platform SDK: Windows API
Using the Windows Headers

The header files for the Windows API enable you to create 32- and 64-bit applications. They include declarations for both Unicode and ANSI versions of the API. For more information, see Unicode in the Windows API. They use data types that allow you to build both 32- and 64-bit versions of your application from a single source code base. For more information, see Getting Ready for 64-bit Windows. Additional features include Header Annotations and STRICT Type Checking.

Microsoft Visual C++ includes copies of the Windows header files that were current at the time Visual C++ was released. Therefore, if you install updated header files from an SDK, you may end up with multiple versions of the Windows header files on your computer. If you do not ensure that you are using the latest version of the SDK header files, you will receive the following error code when compiling code that uses features that were introduced after Visual C++ was released: error C2065: undeclared identifier.

Conditional Declarations

Certain functions that depend on a particular version of Windows are declared using conditional code. This enables you to use the compiler to detect whether your application uses functions that are not supported on its target version(s) of Windows. To compile an application that uses these functions, you must define the appropriate macros. Otherwise, you will receive the C2065 error message.

The Windows header files use macros to indicate which versions of Windows support many programming elements. Therefore, you must define these macros to use new functionality introduced in each major operating system release. (Individual header files may use different macros; therefore, if compilation problems occur, check the header file that contains the definition for conditional definitions.) For more information, see Sdkddkver.h.

The following table describes the preferred macros in use by the Windows header files.
Minimum system required Macros to define
Windows Vista and Windows Server "Longhorn" NTDDI_VERSION >=NTDDI_LONGHORN
Windows Server 2003 SP1 NTDDI_VERSION >=NTDDI_WS03SP1
Windows Server 2003 NTDDI_VERSION >=NTDDI_WS03
Windows XP SP2 NTDDI_VERSION >=NTDDI_WINXPSP2
Windows XP SP1 NTDDI_VERSION >=NTDDI_WINXPSP1
Windows XP NTDDI_VERSION >=NTDDI_WINXP
Windows 2000 SP4 NTDDI_VERSION >=NTDDI_WIN2KSP4
Windows 2000 SP3 NTDDI_VERSION >=NTDDI_WIN2KSP3
Windows 2000 SP2 NTDDI_VERSION >=NTDDI_WIN2KSP2
Windows 2000 SP1 NTDDI_VERSION >=NTDDI_WIN2KSP1
Windows 2000 NTDDI_VERSION >=NTDDI_WIN2K

The following table describes the legacy macros in use by the Windows header files.
Minimum system required Macros to define
Windows Vista and Windows Server "Longhorn" _WIN32_WINNT>=0x0600

WINVER>=0x0600
Windows Server 2003 _WIN32_WINNT>=0x0502

WINVER>=0x0502
Windows XP _WIN32_WINNT>=0x0501

WINVER>=0x0501
Windows 2000 _WIN32_WINNT>=0x0500

WINVER>=0x0500
Windows NT 4.0 _WIN32_WINNT>=0x0400

WINVER>=0x0400
Windows Me _WIN32_WINDOWS=0x0500

WINVER>=0x0500
Windows 98 _WIN32_WINDOWS>=0x0410

WINVER>=0x0410
Windows 95 _WIN32_WINDOWS>=0x0400

WINVER>=0x0400
Internet Explorer 7.0 _WIN32_IE>=0x0700
Internet Explorer 6.0 SP2 _WIN32_IE>=0x0603
Internet Explorer 6.0 SP1 _WIN32_IE>=0x0601
Internet Explorer 6.0 _WIN32_IE>=0x0600
Internet Explorer 5.5 _WIN32_IE>=0x0550
Internet Explorer 5.01 _WIN32_IE>=0x0501
Internet Explorer 5.0, 5.0a, 5.0b _WIN32_IE>=0x0500
Internet Explorer 4.01 _WIN32_IE>=0x0401
Internet Explorer 4.0 _WIN32_IE>=0x0400
Internet Explorer 3.0, 3.01, 3.02 _WIN32_IE>=0x0300

Note that some features introduced in the latest version of Windows may be added to a service pack for a previous version of Windows. Therefore, to target a service pack, you may need to define _WIN32_WINNT with the value for the next major operating system release. For example, the GetDllDirectory function was introduced in Windows Server 2003 and is conditionally defined if _WIN32_WINNT is 0x0502 or greater. This function was also added to Windows XP SP1. Therefore, if you were to define _WIN32_WINNT 0x0501 to target Windows XP, you would miss features that are defined in Windows XP SP1.

You can define these symbols by using the #define statement in each source file, or by specifying the /D compiler option supported by Visual C++. To specify compiler options, go to the Projects menu and click Properties. Go to Configuration Properties, then C++, then Command Line. Enter the option under Additional Options.

Faster Builds with Smaller Header Files

You can reduce the size of the Windows header files by excluding some of the less common API declarations as follows:

* Define WIN32_LEAN_AND_MEAN to exclude APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets.
* Define one or more of the NOapi symbols to exclude the API. For example, NOCOMM excludes the serial communication API. For a list of support NOapi symbols, see Windows.h.

Friday, December 23, 2005

Property settings to generate debug information in a release mode.





A couple of points from a book (Debugging applications fro MS.Net and MS Windows) I am currently read.

/OPT:REF tells the linker to bring in only functions that your program calls directly. OPT:ICF switch will combine identical data COMDAT recrods when ncessary so that you'll have only one constant data variable for all reference to that constant value.

Thursday, December 22, 2005

Walking the stack, pdb file location.

The service I programmed reports some winsock error message and I want to be able to trace the stack to see where the error comes out.

I keep getting meaningless stack :

Stack Testing
(0) : DDTIE911Attribute.exe at ?()
(0) : DDTIE911Attribute.exe at ?()
(0) : DDTIE911Attribute.exe at ?()
(0) : kernel32.dll at IsProcessorFeaturePresent()

I suspected everything, maybe, the version of the debug dll was not right, and I tried to use a sample small program from Several classes for exception handling, and it worked.

Finally, I found that I had to put the .pdb file in the system32 folder, since that was the directory where the service runs. Even the actual executable was in another directoy.

After I put the .pdb file in the system32 folder, yes, I can read the stack trace now.

The way of learning.

Tuesday, December 20, 2005

No pait for you in a single thread application.

If the application has a single thread of execution, so when the thread is doing something, it can't also draw the UI.

After the user puts the application into the background and then the foreground again, the main form must paint the entire client area, and that means processing the Paint event. Because the no other event until the the thread finished the executing, the user will se a white UGLY interface until all the processing finished.

Monday, December 19, 2005

Gunjan Doshi: Using Visual Studio.Net to edit NAnt build files

Gunjan Doshi: Using Visual Studio.Net to edit NAnt build files

Good reference.

IntelliSense for NAnt .build files

IntelliSense for NAnt .build files

Enterprise .NET Community: Managing .NET Development with NAnt

Enterprise .NET Community: Managing .NET Development with NAnt

A very good NAnt tutorial.

Database checking thread

Database checking thread.


One of the issues that E911 server faces is the database connection. Since the database is sitting on another box, so it’s possible that the server reboots, or network goes down.

I posted this question in the atl newsgroup since I know there are a couple of gurus there.

Here is the question I posted.
[
Hi, dear gurus in this group, I have a question about a design to check a valid database connection in my service application. My service is caching a database connection on another server. If for some reason, the database server is rebooted, then my connection become invalid, and any operations will cause an error. 1> Is there any way to get some event that the other database is available after rebooting? if that is the case, I can just simply catch that event and reopen my connection. 2> Another way is that I have to keep polling to check the database connection. Which I cannot run it in main thread since it may take long time, and I don't want to block other work. So I would think creating another thread just dedicated to check the database availability. Do you guys have any good suggestions. Thanks, Jianwei
]

Then , I got a couple of answers from Brian Muth and one answer from Alexander Nickolov, who are both gurus on the group.

[Brain]
Often the simplest solution is the best. If any of your database operations
returns an error indicating the the server is unavailable, then handle the
problem right there (presumably by closing and reopening the connection).

Why wouldn't that work?

[Me]
Hi, Brain, The issue is that the database is sitting on another box,and if I do that way, it may take long time to get some result back (like the connection error), and it will block other work. [Brian]
Ok, first tell me what you anticipate would be the cause of the database to
be offline? Maybe the remote machine has been rebooted, or the disk drive
has overflowed. Perhaps the janitor has tripped over the network cable. Is
pinging the target computer every second going to help your program to
recover any sooner? Of course not.

I'm having trouble seeing how you can make the program more "responsive"
when dealing with a physical connection problem.

Brian

[Alexander]

For example a caching proxy will be affected, e.g. a server that
caches some information and only goes to the database for
cache misses.

The real problem, however, is that the server is single-threaded.

[Brian]

I think it is worth pointing out to the original poster, than connection
pooling comes for free if you package any DB layer as a COM+ object
(assuming OLEDB is being used). One can open the connection object only when
one needs it, and then close it immediately after, and Component Services is
clever enough to look after the connection pooling for you. This "open-late
close-early" strategy is counter-intuitive, but actually scales better in
the long run. I don't know enough of the inner workings to comment on what
CS does when there is a blip in the database server, but I suspect it might
be wiser in the long run to leave the details to CS rather than
"over-engineer" the solution. It probably depends a lot on the requirements,
of which we have heard very little.

Friday, December 16, 2005

How to properly terminate a thread.

The terminating of a thread is a pretty tricky issue, basically, you should never call terminating thread explicitly.

The spawned thread normally runs in Run() method, where it will wait for some shutdown event. In the main thread, when it determeines that the main thread should be terminated, it should set that event, and then wait on the thread handle for it to complete.

void CMainClass::InitiateShutdown()
{
//do some cleaning work.
m_shutdownEvent.Set();
}

After the thread catches that event, it should exits the loop.

And in another Wait() function, the main thread should waits on the Run() to finishe by waiting on that thread object like this:

DWORD result = ::WaitForSingleObject(m_hThread, timeoutMillis);

Then the main thread will be able to exit.

Wednesday, December 14, 2005

Several classes for exception handling - The Code Project - C++ / MFC

When C++ programs crashes, sometimes, it's really hard to figure out where it goes wrong exactly. .Net improved a lot on this aspect, you can find out where it crashes by pritinting out the stack trace.

Konstantin Boukreev's approach allows you to print out the stack trace in the exception hanlder, which is very useful to diagonose the problem.

There is a very similar article also on code project called Walking the callstack , which is also helps you to find out the stack trace in VC++.

Monday, December 12, 2005

/* Rambling comments... */: Testing Windows Services

Len always have some cool idea on how to program effectively. The atl framework my service based on has some good design to debug the OnStart method. In the debug mode, it will be registed as "Local Service", this will make it easier to run it in debug mode.

However, the only way I can stop the servcie is press "shift-F5" , and this cannot help me much in debugging the right clean code.

Inside RunMessageLoop, my service is waiting for the ShutdownEvent , if running as a service, that event will be sent throgh the SCM (The SCM registered the handler function like this:

void Handler(DWORD dwOpcode) throw()
{
T* pT = static_cast(this);

switch (dwOpcode)
{
case SERVICE_CONTROL_STOP:
pT->OnStop();
break;
case SERVICE_CONTROL_PAUSE:
pT->OnPause();
break;
case SERVICE_CONTROL_CONTINUE:
pT->OnContinue();
break;
case SERVICE_CONTROL_INTERROGATE:
pT->OnInterrogate();
break;
case SERVICE_CONTROL_SHUTDOWN:
pT->OnShutdown();
break;
default:
pT->OnUnknownRequest(dwOpcode);
}
}

But in debugging mode, the event can be simulated from a different process. This will rely on a named event, which can communicate between different processes.

Tuesday, October 25, 2005

Return a string in COM methods.

In a typical com function which returns a string, people could make an error easily like the following one:

STDMETHODIMP MyClass::MyFunction(BSTR* pRet)
{
// This is how I return a string - is this incorrect?
std::string myString;
CComBSTR bstr (A2W (myString.c_str()));
*pRet = bstr;
return S_OK;
}

Issue with this is : while pRet points to the bstr , but bstr is defined inside the function scope, so when it goes out of the scope, the CComBSTR destructor will be called like this:

~CComBSTR() throw()
{
::SysFreeString(m_str);
}
which now makes pRet point to a dangling pointer.

An appropriate way is detach the m_str from the CComBSTR , so even when the destructor is called, the m_str won't be destroyed.

BSTR Detach() throw()
{
BSTR s = m_str;
m_str = NULL;
return s;
}

Monday, October 10, 2005

Forward declaration of a template class.

Forward declaration of a template class.

This issue confused me a little bit when I try to declare a template-based class as a friend class of another class.

The issue is like this:

<template class T>
Class A
{
Public:
Private:
}

Class B
{
Public:
Private:
     int m_b;
}

And Class A wants to access the private member m_b in Class B, the forward declaration of A will be like this:
template <class T>  class A

Friday, October 07, 2005

Exception Handling Model

Exception Handling Model /Ehs and /Eha

The exception handling model specifies the model of exception handler used by the computer.

Eha : The exception handler catches the asynchronous structured exceptions and tells the compiler to assume that extern C function do throw an exception.

Ehs: The exception handler doesn’t catch the asynchronous exceptions and tells the compiler to assume that extern C functions do throw an exception.

Ehc: It can be used either with the Eha or Ehs, but it assumes that extern C functions never throw an exception.


XmlDocument.Load and XmlDocument.LoadXml

I was playing around the xml tree view control which I found from the codeproject, but keeping getting "The data at the root level is invalid".

Later on, I find I am confused between XmlDocument.Load and XmlDocument.LoadXml, the former always load an xml file based on the file name, while the later will accept the actual xml document.

JST Robust issue

JTS union may *not* be commutative or associative in the strict sense. In other words, different ordering of the operands may produce slightly different results. This is an unavoidable result of using finite-precision arithmetic to compute operations which inherently require higher precision.

The difference should normally be *very* minor, however. The one time this is not the case is when the first operation produces a robustness error. In this case obviously the two results can be very different (e.g. an exception, versus an actual return value).

> Is this simply a bug that has been fixed?

Yes, this probably reflects an improvement that was made in the intersection calculation.

> Should a union of two valid Geometry's always yield a valid Geometry?

Yes, if the operation completes successfully, the result will always be a valid Geometry. Unfortunately, in the current implementation, sometimes overlay operations can also result in robustness errors. (This is something I'm hoping to fix in a future release).

I notice that your data seems to be fairly limited in precision. You might try using a fixed precision model - this can sometimes alleviate robustness problems.

Martin Davis, Senior Technical Architect
Vivid Solutions Inc. www.vividsolutions.com
Suite #1A-2328 Government Street Victoria, B.C. V8T 5G5
Phone: (250) 385 6040 - Local 308 Fax: (250) 385 6046

Monday, August 08, 2005

BeginInvoke Method

BeginInvoke Method

BeginInvoke is a method of Control, and it executes a delegate asynchronously on the thread that the control's underlying handle was created on.

Sunday, August 07, 2005

How virtual Memory works?

The virtual memory system allows only part of the memory required by the process to be resident in physical memory. Say, if a process requires 500 mb memory, but it may only have 20% memory sitting in physical memory, the other 80% may actually stay on the disk.

Demand Paging

1>When a process requests a block of memory, it check the internal page table for this process to determine whether the reference was a valid or invalid memory access.
2>If the reference is invalid, we terminate the process. If it was valid, but we have not yet brought in that page, we now page it in.
3>We find a free frame by taking one from the free-frame list.
4>We schedule a disk operation to read the desired page into the new allocated frame.
5>When the disk operation is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory.
6>We restart the instruction that was interrupted by the illegal address trap.

Paging

1>Paging allows the logically continuous memory to be scattered through the physical memory out of order.
2>Suppose the logical address space is 2**m, and the page size is 2**n, then the high order m-n bits are designated as page number, while the lower n bits are designated as offset after the particular physical page has been found.
3>The TLB is the quick look up to speed up the page table translation, it will quickly find the entry for the logical address. If the TLB is missing, then we need to look up the page table to find the right entry.
4>If the logical address space is very large, and the page size is relatively small, it will lead to a very large page table. We have to use a couple of techniques such as "multi level page table", "inverted page table" to reduce the size.

Finalizer and Disposer

Finalizer is an implict cleanup, which relies on the GC to clean up the resources, while the disposer is explicit cleanup, which allows to clean up the resources explictly. The .Net supports both patterns, so it is very important to distinguish them. In general, explicit cleanup should be used favorably over the implict cleanup, since the resources are generally more precious than memory, we shouldn't really rely on the GC to hold it for long time and clean it after an unspecified time.

Annotation (Brian Grunkemeyer): There are two different concepts that are somewhat intertwined around object tear-down. The first is the end of the lifetime of a resource (such as a Win32 file handle), and the second is the end of the lifetime of the object holding the resource (such as an instance of FileStream). Unmanaged C++ provided destructors which ran deterministically when an object left scope, or when the programmer called delete on a pointer to an object. This would end the resource’s lifetime, and at least in the case of delete, end the lifetime of the object holding onto the resource. The CLR’s finalization support only allows you to run code at the end of the lifetime of the object holding a resource. Relying on finalization as the sole mechanism for cleaning up resources extends the resource’s lifetime to be equal to the lifetime of the object holding the resource, which can lead to problems if you need exclusive access to that resource or there are a finite number of them, and can hurt performance. Hence, witness the Dispose pattern for managed code, allowing you to define a method to explicitly mimic the determinism & eagerness of destructors in C++. This relegates finalization to a backstop against users of a type who do not call Dispose, which is a good thing considering the additional restrictions on finalizers.

In the Dispose(bool disposing) method, if the diposing passed in is true, it means that we can explicitely use other reference types that refer to other objects knowing for sure that those other objects have not been finalized or disposed yet. If it's false, we cannot refer to other resources since those objects may have already been freed.

When we inherit a class which has already correctly implemented "IDispose" pattern, we need only override the Dispose (bool disposing) class, we don't need to override the Finalize and Dipose class.

Saturday, August 06, 2005

Internal Fragmentation and External Fragmentation.

In the memory allocation model, if the memory is partitioned into the fixed size blocks[M bytes a block], then when a process(N bytes) is allocated into the memory, it will fit the first N/M blocks, and occupy the part of the last block, and this is called "internal fragmentation", since the fragment is internal to a block.

The other model is called "external fragmentation", the memory is NOT partitioned into the fixed size. It will maintain a free list of "available" memory blocks and select the best fit for the waiting process. The fragment is external to any occupied blocks so it is called external fragmentation.

Wednesday, August 03, 2005

What is delegate in C#

Delegate is a class, NOT a method. It is a class inherited from System.Delegate or System.MulticastDelegate, which has two properties called "Target" and "Method". The target is the class instance on which the current delegate invokes the instance method, if it is null, it means it's a "Static" calling. MethodInvoker or EventHander are two special delegates treated in a fast manner by Invoke and BeginInvoke. MethodInvoker takes no parameters and returns no value, and EventHandler takes two parameters and returns no value.

Notifications

Notifications

It takes me a while to figure out why the legend control is not updated correctly until I found this sentence.

The applications that rely solely on WM_VSCROLL (and WM_HSCROLL) for scroll position data have a practical maximum position value of 65,535.


The GetScrollInfo function enables applications to use 32-bit scroll positions. Although the messages that indicate scroll-bar position, WM_HSCROLL and WM_VSCROLL, provide only 16 bits of position data, the functions SetScrollInfo and GetScrollInfo provide 32 bits of scroll-bar position data. Thus, an application can call GetScrollInfo while processing either the WM_HSCROLL or WM_VSCROLL messages to obtain 32-bit scroll-bar position data.

To get the 32-bit position of the scroll box (thumb) during a SB_THUMBTRACK message in a WM_HSCROLL or WM_VSCROLL message, call GetScrollInfo with the SIF_TRACKPOS value in the fMask member of the SCROLLINFO structure. The function returns the tracking position of the scroll box in the nTrackPos member of the SCROLLINFO structure. This allows you to get the position of the scroll box as the user moves it. The following sample code illustrates the technique.

SCROLLINFO si;
case WM_HSCROLL:
switch(LOWORD(wparam)) {
case SB_THUMBTRACK:
// Initialize SCROLLINFO structure

ZeroMemory(&si, sizeof(SCROLLINFO));
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_TRACKPOS;

// Call GetScrollInfo to get current tracking
// position in si.nTrackPos

if (!GetScrollInfo(hwnd, SB_HORZ, &si) )
return 1; // GetScrollInfo failed
break;
.
.
.
}

Wednesday, July 27, 2005

Test the E9-1-1 Server.

It has been pretty stressful for me to write the testing code for the E9-1-1 server these days. Multithreading programming is always challenging, it's hard to debug, the code is flowing all around, and it's easy to make mistakes with those locks, monitors, wait handles. But it's also enjoyful to dig into those codes.

After finishing the test codes, the server part also needs extensively refactoring, the I/O completion port should be used to replace the polling, the so called "virtual multithreading" should be replaced by true multi-threading.

Tuesday, July 26, 2005

Bing will go to Hospitality and Tourism Management Program - College of Charleston

Hospitality and Tourism Management Program - College of Charleston

This blog is a little bit late, but still, I am very proud of him when I heard that he will head to College of Charleston to become a faculty.

Bing inspired me a lot in my life. When I was still at Nanjing University, I saw him get very high score in GRE, go abroad successfully, all of those things have a very good impact on my life.

After coming to states, we have choosing different roads. He is finishing his PH.D. and then go to Cornell , firstly in the CS master program, then transfer to a PostDoc in the Info Lab. I know his road is not smooth, but he goes through this step by step.

I hope he will do well in the future as a faculty, which he could be even 7 years ago in Nanjing University.

Wednesday, July 20, 2005

中文博客.

写写中文试试看.

keyboard shortcut assignment in textbox

keyboard shortcut assignment in textbox
All 2 messages in topic - view as tree


I'm building a form to allow the user to assign a keyboard shortcut.
Basically I have a textbox that I want to work like the "Press shortcut
key(s)" in the Visual Studio keyboard options, the user does the key
combination and it shows up in the textbox. It looks like it works on the
KeyDown event. The KeyDown event has an argument of KeyEventArgs. The docs
say "You can use constants from Keys to extract information from the KeyData
property. Use the bitwise AND operator to compare data returned by KeyData
with constants in Keys to obtain information about which keys the user
pressed. To determine whether a specific modifier key was pressed, use the
Control, Shift, and Alt properties." Unfortunately there is no example and
I don't know how to do bitwise compares in c#. Can someone help me out
here?

thanks
Paul




first, set Form1.KeyPreview value to "true"

then, on Form's KeyDown Event

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
//Note: "T" is a sample designated shortcut key for textbox
if (e.Modifiers.ToString().ToUpper() == "ALT" &
e.KeyCode.ToString().ToUpper() == "T")
this.textBox1.Select();

}

gani

How Static Method works.

[Question:]
What if two users call the static method at the same time? Since the
method is static, is any data within this method (parameters passed in and
local variables declared within the method) also considered static and shared for all users of the class?

[Answer:]
If the method is not accessing other static variables,
and is only working with references/values that are stored on the stack (in
other words, declared in the function), then you should have nothng to worry
about. The only thing you have to worry about at this point is other
resources you might be accessing (for example, the same file, if you are
working with files).

Tuesday, July 19, 2005

Can you find YY on this page?



This picture is supposed to taken by a professional photographer, well, can you tell how professional it is. If you cannot, then you have the same idea as mine, the so-called professional photographer is totally bullshit.

Monday, July 18, 2005

The priorty date issue.

[Email from my attorney:
Jianwei

You are going to create a serious problem for yourself if you continue to try and use multiple avenues to push this along. The DOL and USCIS are going to start to push back. Up to now, I think your calls and actions have been just a question of impatience, but you are about to cross the line to a problem. I have seen cases where the agencies get calls from several sources, dig in their heels, and do nothing just to spite the individual because they feel there is too much pressure.

Please, I am serious. If you want me to work on this, you are going to have to back off and be patient. If you are convinced that you need to call dozens of people and push hard, I will be happy to submit a withdrawal letter, and you can handle it on your own. However, I can't do both. You need to make a decision whether you are going to handle your case on your own, or whether you want me to continue to work on it.

I called John today and left a voice mail. I will talk to him when he calls, and see what I can do to find out where in the process the information is stuck, if in fact it is stuck at all. But if you are going to make calls through Congressional offices, have the lawyer call, have the manager call, and check back a few days later for all, you are going to sabotage the process. I know that the government agencies will ignore the file if they think that is what is going on.
]

Well, I feel a little bit frustrating. I think Rob did a pretty good job on my case, and I don't have any issues with him. After all, the whole thing is not his responsbilty. But it still frustrates me, I have been waiting for this for the last three years, and every step seems to have a lot of pains. I adimit it is an issue because I have limited ability. If I am truley outstanding, I may not have to go through this painful process.

Life is life, you just have to live with it. If you spend more time improve yourself, there will be less pain ahead.

Sunday, July 17, 2005

Columbus, Ohio: Dentist Reviews, Dentist Ratings, Dentist Recommendations and Dentist Help.

Columbus, Ohio: Dentist Reviews, Dentist Ratings, Dentist Recommendations and Dentist Help.

Well, I was suggested by my dentist to get my wisdom teeth out. Since xiaoyi had very bad experiences when she did it two year ago, and I am a little bit worried. I don't want to lie on the bed for two weeks after doing the surgery.

This seems a pretty good place to see other people's reviews about a particular dentist. Unfortunately, it is not very complete.

Tactus Touch Typing Keyboard - Keyboard Posture - Correct Posture

Tactus Touch Typing Keyboard - Keyboard Posture - Correct Posture

I feel a little bit hurt on my back of arms, and I think it is caused by incorrect posture of typing posture. It is very important to keep it right.

Friday, July 15, 2005

A regular expression help from C# newsgroup

: I am trying to parse out the apratment number in a regular expression :
:
: If I use
:
: Regex regex = new
: Regex(@"[...](?\bAPT|#|UNIT\b)[...]",
: RegexOptions.ExplicitCapture);
:
: I will be able to parse out "100 main ST # C)
:
: But if I move "#" position in regular expression, I won't be able to
: parse out the same address anymore.
:
: Regex regex = new
: Regex(@"[...](?\bAPT|UNIT|#\b)[...]",
: RegexOptions.ExplicitCapture);

The latter fails to match because there's no word boundary (\b) between
an octothorpe and a space. Remember, a word boundard occurs between a
\w and a \W or vice versa, but '#' and ' ' both match \W.

A start in the right direction is (line breaks inserted):

(?.+)
(?\b(APT|UNIT)\b|#(?=\s+))
(?.+)

Hope this helps,
Greg

Thursday, July 14, 2005

The powerful unit testing.

The whole idea of unit testing is to ensure that you won't break already-working codes when you refactoring. Address Parsing is a very good example, there are a lot of different situations, and it's very easily that you break some codes when you modify the regular expression rules.

The better way is to put everything into an XML file, and run the parsing through the XML file every time when modifying something. That way, you will always ensure that something already working well won't be broken when regular expression rules are added, modified, or delete.

Another way to learn from JTS, the great library.

Wednesday, July 13, 2005

How JTS cropping works.

JTS is very cool, the algorithm is complex but really powerful. All the intersection/union/difference/symmetry difference operations in all kinds of geometry types could be done in a very generic algorithm.

How the cropping works, here is what I understood:

1> The first step is to get all the intersection points between two geometries. The algorithm used here is the sweep-line algorithm.

2> Then it will need to create the split edges based on those intersection points. The split edge is the edge between two intersection points on the same geometry.

3> For each split edge, we have two directed edge end generated from it. One is starting from the beginning, and the other one is starting from the end. For the labelling, if it starts from the beginning, it will use the parent edge label, if it starts from the end, it will filp the parent edge label.

4> Based on those directed edges, we can create a planar graph, and all the vertices in the graph are made from the starting point of the directed edge end.

5> We need compute the labels (topological relationship) of the directed edge and vertice relative to the two different geometries.
a> Each edge end in the edge end map has a label.
b> The edge end star map has its own label, which will be used to update the label of the node.
c> Get the starting edge in the edge end star map, loop through each edge in the edge end map, and compute the labelling location.
d> We also need to merge the label from one directed edge with its symmentric directed edge.
e> Merge the label of the node with the label of the edge end star map.


6> We can determine whether each edge is in result or not based on the topological relationship with two geometries. For each different operation like intersection / union / difference, the criteria to determine whether it is in result is different.

7> We sort each vertice in the planar graph firstly by X coordinate, then by Y coordinate. By looping each vertice in the graph, we will determine how the edges in each vertice link together.

8>For the polygon building, we must determine which edge will actually qualify for the result polygon. There are generally three conditions which will make it qualify for the polygon edge:
8-a. The label of the edge has to show that it is an area edge to both geometries.
8-b. The edge is not an interior area edge. The interior area ege means that the label is an area label for both geometries and for each geometry, both sides are interior.
8-c. The right sides of the edge to both geometries should be inside.


9>We build the maximal edge ring and minimum edge ring based on linking results.
The maximal edge rings will be built firstly, and then we loop through each node. If there are more than one outgoing directed edge which is in result, we must consider the minimal edge ring too. Because if we have one more outgoing edge in one particular vertice, it means that we cannot simply link the edge to form a polygon, we must do another step to form the minimum edge ring, which is based on the maximum edge ring.

10> The actual geometries are built based on the linking results. If there are only maximum edge rings, then build polygons based on that. If there are minimum edge rings, then we need build polygon based on it instead of maximum edge rings.

11> We will collect the geometries in the following order: polygons firstly, lines second, and points last. The lines could be generated by an input geometry of line, or
two touching polygons.
GISResearch

Monday, July 11, 2005

Very good regular expression site.

Very good regular expression site.

The world of regular expression is very exciting, but it is also very error prone when you try to build those complex rules. A good rule is very helpful to understand and build the rules. Regular Expression Workbench at goddotnet.com is very powerful tool to build the expression rules dynamically.

I mainly use the regular expression rule for the address parsing. The previous method I used is brute-force parsing, it's not very pleasant though it does the work. In the newer version, I hope I can build a much powerful tool to parse the address, and hopefully, publish it to the codeproject.com

Thursday, July 07, 2005

UML Diagrams

UML Diagrams

A simple introduction to UML diagrams.

Obfuscation and Decompilation

Obfuscation and Decompilation

Good Article about Obfuscation and Decompilation.

Thursday, June 16, 2005

Finally get a way out.

The dead hard drive has made me in a disaster in the last three days, thanks for Dave's help, without his help, I may spend much more time to recover the data.

The hard drive we ordered from CompUSA finally came this morning, but it is not what we had hoped. We hoped that there is an internal SATA that we can swap my bad disk in, but it's not the case. Another way dead.

Then Dave suggested that I can try another SATA - IDE bridge card, I went to microcenter to get it, tried it again on his computer. The computer cannot recogize the drive. Another way dead.

The only way left is to run the system on WinPE from CD-ROM based on suggestions from http://www.runtime.org./peb.htm before putting it into the freezer. Dave helped me burn a CD again. You know what, it worked!!!!!

Wednesday, June 15, 2005

Dead hard drive.

I have tried to run the Maxtor Hard Drive Self -checking utility (with Chris's suggestion) , and the drive is not good.

We have tried to put the hard drive in another computer yesterday, it is not even starting.

I also checked the order you made yesterday, and that hard drive is supposed to come tomorrow, I am going to swap my drive into that USB box, and I hope this at least will make the main computer with good drive boot.

I am suggesting the following steps:

1> If the drive is readable , we can simply copy the data out. ( I seriously doubt on that).
2> If the drive is not readable, we can try the GetDataBack, the good thing about this is that you can check how much files you can recover before buying the license code. (Scan is free, and copying needs license).
3> If 2> doesn't work, I read some posts that some people successfully get the data out by freezing the hard drive overnight, I will give it a try.
4> If nono of them work, then I probably have to rewrite some codes. As I told you guys, most of my codes are in source safe, especially important ones, but there are still quite a few recent updates not in source safe , and some utility programs I wrote. I will spend some extra hours to do some code recovering from my brain.

But I think Dave and you have much more experiences on that, so give me hints if you guys have.

I will take this afternoon off, and work on Saturday morning.

Monday, June 06, 2005

Roland Weigelt's GhostDoc

Roland Weigelt's GhostDoc

I have been looking for this plug-in for the whole day. I firstly heard about that in the Day of .Net Columbus meeting, but really didn't pay attention to that. Suddenly today, I find I desperately need this tool to help me write some comments.

It is good that I find it finally.

Microsoft AntiSpyware blocks tests from running.

I had tried using Team System Test in VS2005 to develop test projects, but everytime when I started the test, the result shows "aborted", and Microsoft AntiSpyware pops up a box quickly.

This issuue has driven me nuts for a while until I found a known issue here:

Issue: Microsoft AntiSpyware blocks tests from running.

Details: If Microsoft AntiSpyware's real-time protection is enabled with the default configuration, the running of unit tests will be blocked and all tests will end in Aborted.

Workaround: Deactivate the Script Blocking Checkpoint in Microsoft AntiSpyware.

1. Open Microsoft AntiSpyware.
2. Select Real-time Protection.
3. Click the "Application Agents" link in the Security Agents Status panel.
4. A list of Application Agent Checkpoints will be displayed. Scroll down to find "Script Blocking."
5. Click on the "Script Blocking" checkpoint.
6. From the "Checkpoint Details" pane, choose "Deactivate Checkpoint."

Sunday, May 08, 2005

Instance Constructor vs. The Class Constructor

Instance Constructor vs. The Class Constructor

A good explanation of difference between the instance constructors and the class constructors.

Class constructors are used for static field initialization. Only one class constructor per type is permitted, and it cannot use the vararg (variable argument) calling convention. Normally, class constructors are never called from the IL code. If a type has a class constructor, this constructor is executed automatically after the type is loaded. However, a class constructor, like any other static method, can be called explicitly. As a result of such a call, the global fields of the type are reset to their initial values. Calling class constructor explicitly does not lead to type reloading.

MS Access Application With C#

MS Access Application With C#


I encountered this problem when I wrote the map projection function for the DTMap, since I need to get some data from the EPSG_v66.mdb and write it to the xml file. I think this is a good start.

Thursday, May 05, 2005

Waiting for the I-140 aproval.

Waiting for the I-140 approval is one of the most painful thing in my life, the response to the RFE has been submitted last week, and USCIS records shows that they have received the response on Apr 26. Then in the following three days, 27, 28, 29, the LUD keeps change, so I guess that somebody is working on my case. However, after that, nothing happens. Well, this is also normal, accoridng to the pattern observerd on the immigration.com, a lot of people have the similar experience.

Hopefully, I will have it approved by next week.

God bless me!

Monday, May 02, 2005

Split a string by double pipe.

How to split a string like "TEST1||TEST2".

I raised this question in C# MS newsgroup, and Tim Wilson answered my question that I should use

string[] asTest = Regex.Split(sTest, @"\|\|");

Well, this works beautifully. But it takes ome time for me to fully understand it. Fristly of all, "|" is considered one of the special characters (. $ ^ { [ ( | ) * + ? \) in the regular expression , so \ signals to the regular expression parser that the character following the backslash is not an operator. Then, how about string[] asTest = Regex.Split(sTest, "\|\|"), The compiler complains error CS1009: Unrecognized escape sequence. Will it make sense? According to MSDN , it means that "An unexpected character followed a backslash (\) in a string. The compiler expects one of the valid escape characters", then what is valid escape characters, | is a NOT a valid character following \, by using @ , we mean \| Unicode character 007C, do you understand, I am NOT.

Friday, April 29, 2005

Programming C#: Working with Arrays

Programming C#: Working with Arrays

C# makes working with arrays much easier and enjoyful.

Saturday, April 23, 2005

Finally the response to my I-140 RFE is filed.

The RFE was issued on Feb 25, 2005, so it was almost two months ago. Firstly, it took some time to get the supporting letter from CHINA, then the attorney started to look at my case after two weeks. Then after that, we found that ODJFS screwed up the priority date, so we waited another two weeks to deal with issue.

Finally, the package was sent out on Thursday night, hopefully, I can get it approved next week.

It will be such a relief.

Friday, April 22, 2005

Good example in XML Serialization in C#

XML Serialization in C#

Best examples to demonstrate the xml serialization.

Sunday, April 10, 2005

Too many things to do.

Always feel too many things to do everyday. Working is the most important, but also a lot of reading. I am always exciting to get a new book, but rarely get enough time to go through. Well, maybe, just try my best.

Browsing web has been the worst thing I can ever do to waste the time, sometimes, I just cannot control myself, reading those stupid news.

Answering other people's questions in newsgroup seems a better way to relaxing.

Wait for the pictures of Albany trip from Lingling and Dawei.

Tuesday, March 22, 2005

Excited trip to Albany, NY

I am excited to visit my freind, Lingling and Dawei. They just bought a new house , and we are excited to check it out.

One house, two cars, and a dog is a typical American life which I have seen in movies and imagined in my head. I still have one house, one car, and a dog left. Maybe, I need to work harder on this.

TDD: Testing Internal classes

TDD: Testing Internal classes

Nice trick to test the internal class, plus another trick to test private methods( http://www.codeproject.com/csharp/TestNonPublicMembers.asp). I should be able to test whatever I want to test.

Sunday, March 20, 2005

Essential .Net by Don Box.

Like all other books written by Don Box, I can always learn something which I cannot learn by day to day programming. Though I still insist the best way to learn programming is still through coding.

The chapter 7 "Advanced Methods" has a lot of similarities with the ideas expressed in "Transactional COM+". All objects are living in context, and context decides the behavior of the objects.

Good book, recommend for reading.

Tuesday, March 08, 2005

C# and .NET articles and links

C# and .NET articles and links

A very good C# resources. I read about this person from MS C# newsgroup, and then find this out. Really easy understanding tutorial. Compared to a lot of C# books, this one has a lot of practical approaches. Strong recommended , A++.

Sunday, March 06, 2005

The best online Computer Science resources I have ever found.

CS Classes

I start to read this when I prepare the CS GRE subject test, this is by far the best online resources I have ever found on Internet. Though I didn't do well on Nov, 2004 test, but I think I learned a lot in the process of preparing it. I got a lot of trouble in ansewring those questions related to virtual memory, cache, pipeline, and also computation theory. Well, I won't say the questions are too difficult, it's just all about myself. I don't have a solid understanding on those concepts , it's also understandable for a geography major. But I still think I am on the right track.

Sunday, February 27, 2005

The Code Project - Testing TCP and UDP socket servers using C# and .NET - C# Programming

The Code Project - Testing TCP and UDP socket servers using C# and .NET - C# Programming

I am starting to write a serious TCP/UDP socket testing for the E911server . Honestly, the version I wrote before using visual basic is too simple, and naive. Thanks for Len Holgate. It's always joyful to find something exciting on codeproject.

The E911 server really hasn't passed a stress test yet, there are only limited connections so far. And I am sure the synchronous TCP/IP socket programming is not the best way to approach.

I am glad that I have restructured the program completely, it's always good to separate the business logic out of the programming logic.