2016
03.31

Recently I was required to do enhancements to an old ASP.NET Projects. It is an ASP.NET MVC 2 project supplemented with Ext.NET. Since the enhancements are quite minor, and no major enhancements planned, there’s no good reason to upgrade to the later ASP.NET MVC version. Not to mention that we didn’t renew our Ext.NET license 😀

On the other hand, I recently upgraded my workstation to Windows 10. All my previous development tools (VS 2008 Pro, IntelliJ, VS 2012) also have been installed. So I expect nothing wrong with loading this old project in VS 2008. But I was wrong. I got the dreaded “the project type is not supported by this installation” error.

devenv_2016-03-30_21-32-06

Possible Cause No. 1

I suspected that I forgotten to install ASP.NET MVC 2 Tools for Visual Studio 2008. So I went to Microsoft and download the installer. When I install it, it strangely complained that another version of MVC 2 is already installed. So I uninstall the installed ASP.NET MVC 2, then install again using the executable I just downloaded. It still failed.

Possible Cause No. 2

Could it be that Ext.NET prevented the project loading? From the project’s web.config, I can see that it is using Ext.NET v.1.xx. I vaguely remember that I need to install something in order to create Ext.Net project and to have intellisense on Ext.Net’s classes. Unfortunately, Ext.NET website doesn’t provide download for previous versions. :( So, nothing can be done here.

Possible Cause No. 3

Could it be that this project is other that MVC 2? I open the .csproj in Notepad++ and found that the project type GUID is exactly just F85E285D-A4E0-4152-9332-AB1D724D3325. When I Google this GUID, it is exactly the GUID of ASP.NET MVC 2 project.

Solution

Out of desperation, I opened Visual Studio’s About window. Perhaps I missed any components.

vs2008sp1

Hmm, SP 1. Could this be the problem? Since I have no other way, I decided to uninstall Visual Studio 2008 SP 1 (9.0.30729.1) and install the previous version (without SP 1).

devenv_2016-03-30_23-21-49

Lo and behold! Now I can load my ASP.NET MVC 2 project!.

Conclusion

Visual Studio 2008 SP 1 (9.0.30729.1) is not compatible with ASP.NET MVC 2 project (Project Type GUID: F85E285D-A4E0-4152-9332-AB1D724D3325).

Worth sharing?

  • Facebook
  • Twitter
  • Google
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
2016
03.29

This trick is useful for handling suspicious emails. By looking on its header, we can see from which IP address the email was sent.

  1. Double click the email to make it open in a new window
  2. Click the Tags button
    OUTLOOK_2016-03-29_00-20-49

OUTLOOK_2016-03-29_00-23-16

Using online WHOIS, we can find out more about the IP address:
chrome_2016-03-29_00-31-28

Whois result:
chrome_2016-03-29_01-21-02

If you really have nothing to do, you can submit complaint to the ISP of that naughty IP address. But very likely, the PC on that IP address is just a dummy, and is a part of a BotNet.

Worth sharing?

  • Facebook
  • Twitter
  • Google
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
2016
02.04

Yesterday, I found myself in need of a TIFF image splitter. Reason: The scanner in my office didn’t allow me to retain the settings after a document scan. So every time I choose to ‘End Scanning’, the output image quality setting is reset to default. Which means I need change the output settings for each of document that I want to scan. The only way was to scan all documents at one go. That lead me to the situation where a TIFF splitter is needed.

A quick Google-search brought me to a simple, free and open-source program called Tiff Splitter. It is exactly the kind of program that I need. It is simple, and does its job well.

Because it does the job well, I become interested to find out how exactly Tiff Splitter works. Since it’s an open-source, I can immediately take a dive and learn.

TiffSplit_2016-01-28_15-16-40

After we click, select an input file, or, drop a file, the event handlers will eventually call processFile method.

private void processFile(string fileName)
{
   // ... SNIP ...
   
   _configs.inputFile = fileName;

   // Configure the extractor
   RetObj retObj = TiffSplitCode.Prepare(_configs, out numOfPages);
   
   // ... SNIP ...
   
   // Let user select pages to extract
   PageSelection ps = new PageSelection(numOfPages);
   ps.ShowDialog();
   _configs.fromPage = ps.PageFrom;
   _configs.toPage = ps.PageTo;
   _configs.doOverwrite = ps.OverwriteFiles;
   
   // ... SNIP ...
   
   // do the work in separate thread
   backgroundWorkerSplit.RunWorkerAsync(_configs);
}

On the worker thread it will do the splitting

private void backgroundWorkerSplit_DoWork(object sender, DoWorkEventArgs e)
{
	ConfObj input = e.Argument as ConfObj;  
	RetObj retObj = TiffSplitCode.Split(input, _updateProgress);
	e.Result = retObj;
}

The actual work was done by TiffSplitCode

public static RetObj Split(ConfObj input, UpdateProgress updateProgress)
{
	int numOfPages = input.toPage - input.fromPage + 1;                               
	// save each image
	for (int i = 0; i < numOfPages; i++)
	{
		_coder.Save(input.fromPage - 1 + i);
		// ... SNIP ...
	}
	// ... SNIP ...
}


Hmm, it looks simple. But who is _coder? How does it able to distinguish PDF, TIFF or JPG? Different format definitely requires different treatment right (or so I thought) ?

The secret is in Prepare and CoderFactory method.

public static RetObj Prepare(ConfObj input, out int numOfPages)
{
	// .. Snipped: Validate input file ..	

	// overwrite output type if the input is PDF
	if (ext.ToUpper() == ".PDF")
		input.outputType = OutputType.PDF;

	// create output coder
	_coder = CoderFactory(input.outputType);

	// open file
	numOfPages = _coder.LoadImage(input.inputFile);

	// prepare
	_coder.Prepare(input);

	return retobj;
}

static private ICoder CoderFactory(OutputType type)
{
	switch (type)
	{
		case OutputType.TIF:
			return new TiffCoder();
		case OutputType.JPG:
			return new JpegCoder();
		case OutputType.PDF:
			return new PDFCoder();
		default:
			throw new Exception("Unknown output format.");
	}
}


So now it's clear that the actual loading and splitting in classes which implement ICoder interface. So for Tiff, the work is done by TiffCoder

public class TiffCoder : ICoder
{
	private Image _image;
	private FrameDimension _dim;
	
	// ... SNIP ...

	public int LoadImage(string fileName)
	{
		_inputImageName = fileName;
		_image = Image.FromFile(fileName);
		Guid guid = _image.FrameDimensionsList[0];
		_dim = new FrameDimension(guid);
		return _image.GetFrameCount(_dim);
	}


	public void Save(int pageNum)
	{
		_image.SelectActiveFrame(_dim, pageNum);
		string outputFileName = null;

		// ... SNIP: Output file name

		if (!_config.doOverwrite)
		{
			outputFileName = HelperMethods.ModifyFileName(outputFileName);
		}

		_image.Save(outputFileName);
	}

	// ... SNIP ...
}


Well that's interesting. The program actually uses .NET's System.Drawing.Image instead of some external library to handle TIFF. As a dig deeper, I found out that System.Drawing is actually a managed interface to Windows' native library, GDI+ (mind blown!)

I'll stop my exploration here, perhaps in the future I'll have the motivation to dig deeper than today. For more reading please check the following references:

  1. System.Drawing.Image source code
  2. brief introduction to GDI
  3. Microsoft GDI+ page

Worth sharing?

  • Facebook
  • Twitter
  • Google
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS