Unix time (__time64_t or time_t) to FILETIME



Here is the code to convert unix time (__time64_t) to FILETIME. You can also use time_t, in which case you would need to use Int32x32to64(t, 10000000) function to multiply in the below code.

void UnixTimeToFileTime(__time64_t t, FILETIME * pFT)
{
	// Note that LONGLONG is a 64-bit value
	LONGLONG ll;
 
	ll = (t * 10000000) + 116444736000000000;
 
	pFT->dwLowDateTime = (DWORD)ll;
	pFT->dwHighDateTime = ll >> 32;
}


Visual Studio closes/crashes when opening edmx file



Whenever I tried opened the Entity Framework’s edmx file, Visual Studio 2008 would simply close. I tried to google, stack overflow. But couldn’t find the answer.

I noticed that when I double clicked on the edmx file, the status bar said “Initializing toolbox” just before closing of Visual Studio.

SOLUTION

  1. Close all the open windows using the Window->Windows menu in Visual Studio
  2. Explicitly click on the “Toolbox” pane. From the menu you would choose View->Toolbox.
  3. Then double click on .edmx to open it. You should be able to open it successfully.

I still unsure whether .edmx opened because I closed all the windows or because I opened the Toolbox explicitly.

Thanks :)



Windows Azure Cloud Computing for Dummies



Seriously, if you don’t understand anything about Windows Azure Cloud Computing, here is a neat article that talks about Windows Azure with complete clarity. Love this article :)

https://www.windowsazure.com/en-us/manage/windows/fundamentals/intro-to-windows-azure/

Following excerpt is taken from the article:

Windows Azure is Microsoft’s application platform for the public cloud. You can use Windows Azure just to store data, with the applications that use this data running on-premises (that is, outside the public cloud). You can use Windows Azure to create virtual machines for development and test or to run SharePoint and other applications. You can use Windows Azure to build massively scalable applications with lots and lots of users. Read more of it.

I suggest you opt for the 90-day free trial of Windows Azure. Powerful machine, simple to use.

Thanks :)



Localization in ASP.Net MVC Projects



Hello all,

As I am new to .Net Framework & ASP.Net MVC, I was looking in to various articles that would give clear step by step instructions as to how to add localization to ASP.Net MVC Projects. Especially, localization of string resources.

Here is a fantastic article on Localization in ASP.Net MVC projects.

Thanks to the author.



CHARFORMAT to LOGFONT



Thought someone might require this conversion.

CharformatToLogfont(CHARFORMAT & cf, LOGFONT & lf, COLORREF & cr)
{
 
	lf.lfCharSet = cf.bCharSet;
	lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	lf.lfEscapement = 0;
	lf.lfOrientation = 0;
	lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	lf.lfQuality = DEFAULT_QUALITY;
	lf.lfPitchAndFamily = DEFAULT_PITCH;
 
 
	if ( (cf.dwEffects & CFE_BOLD) == CFE_BOLD)
	{
		lf.lfWeight = FW_BOLD;
	}
 
	CDC dc;
	dc.CreateDC(_T("DISPLAY"),NULL,NULL,NULL);
	lf.lfHeight = -MulDiv(cf.yHeight/20, dc.GetDeviceCaps(LOGPIXELSY), 72);
	dc.DeleteDC();
 
	lf.lfUnderline = ( (cf.dwEffects & CFE_UNDERLINE) == CFE_UNDERLINE);
	lf.lfStrikeOut = ( (cf.dwEffects & CFE_STRIKEOUT) == CFE_STRIKEOUT);
	lf.lfItalic = ( (cf.dwEffects & CFE_ITALIC) == CFE_ITALIC);
 
	lf.lfWidth = 0;
	_tcscpy_s(lf.lfFaceName, LF_FACESIZE, cf.szFaceName);
 
	//save color separately because LOGFONT does not accept color
	cr = cf.crTextColor;
 
}


LOGFONT to CHARFORMAT



Thought someone might require this conversion.

 
LogfontToCharformat(LOGFONT & lf, COLORREF & cr, CHARFORMAT & cf)
{
 
	cf.cbSize = sizeof(CHARFORMAT);
	cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET 
        | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_OFFSET;
	cf.dwEffects = 0;
 
	if (lf.lfWeight >= FW_BOLD)
	{
		cf.dwEffects |= CFE_BOLD;
	}
 
	if (lf.lfUnderline)
	{
		cf.dwEffects |= CFE_UNDERLINE;
	}
 
	if (lf.lfItalic)
	{
		cf.dwEffects |= CFE_ITALIC;
	}
 
	if (lf.lfStrikeOut)
	{
		cf.dwEffects |= CFE_STRIKEOUT;
	}
 
	//temporary create DC
	CDC dc;
	dc.CreateDC(_T("DISPLAY"),NULL,NULL,NULL);
	cf.yHeight = 20*long( 0.5 + fabs(double(72*lf.lfHeight)/dc.GetDeviceCaps(LOGPIXELSY)));
	dc.DeleteDC();
 
	cf.yOffset = 0;
	cf.crTextColor = cr;
	cf.bCharSet = lf.lfCharSet;
	cf.bPitchAndFamily = lf.lfPitchAndFamily;
	_tcscpy_s(cf.szFaceName, LF_FACESIZE, lf.lfFaceName);
}


Linq – Distinct by a particular column



I had a list of tags for a particular user. I wanted to show only unique tags. I initially thought there would be something an inbuilt ‘distinct’ operator in Linq. Unfortunately not. I then discovered the Distinct() function. But it doesn’t support filtering the results by a particular column.

Thanks to this StackOverflow question that set my direction. It says that I must use the ‘group by’ operator, which I did.

Following is the code that I ended up with:

1
2
3
4
5
//distinct tags for a particular user
var tags = from t in _db.Tags 
               where t.UserId == userId
               group t by t.Name into g
               select g.FirstOrDefault();

Since the query returns a group, we must select the first item in the group. Hence FirstOrDefault().

Thanks.



Why I upgraded to Entity Framework 4?



I was happily working with Entity Framework 1 until I read at several places about its lack of important features that are normally expected from an ORM framework. I started thinking seriously about upgrading to Entity Framework 4 (yes, the next version after Entity Framework 1) after I read this No Confidence letter. It lists all the issues that EF1 has and also suggests improvements. Several architects signed it.

So I upgraded to Entity Framework 4. This required me to upgrade my projects to Visual Studio 2010 & .Net Framework 4. Along with this, I also upgrade my MVC 2 project to MVC 3 with the help of this article.

Although POCO & Persistence Ignorance are the two most-liked features, they did not interest me because I had already generated the Entity classes from the database in EF1 and mapped them to my own model. What interested me was Lazy Loading and Foreign key association.

Entity Framework 4 addresses several issues and it has undergone a major rework. Worth upgrading.

Thanks.



HTTP Test Client



When developing a RESTful Web service in ASP.Net MVC I was looking for a HTTP Test client that I can be used to test the RESTful API that I had created. It is easy to test HTTP GET with a browser. What I was looking for in the tool was the ability to HTTP POST/PUT/DELETE to any Url. Thanks to Stackoverflow where chris recommended a fantastic freeware tool called Fiddler

Definition from Fiddler’s website: Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP(S) traffic, set breakpoints, and “fiddle” with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.

Thanks.