Dreamlusion’s blog

August 10, 2008

PowerShell Massive/Batch Extraction

Filed under: Uncategorized — Tags: — dreamlusion @ 11:42 am

To run this script you will need the open source 7-Zip utility which is available here.

ls '

'| % { &"[7z.exe path]" "e" "-o[output directory]" $_.FullName }

While your files are getting extracted you may either sit back and enjoy it or write a blog entry :)

July 16, 2008

Using a ASP.NET AJAX behavior with many or no TargetControlIDs

Filed under: Uncategorized — Tags: , — dreamlusion @ 1:06 pm

Let’s say you want to build a versatile Modal Dialog for your application that will use the ModalPopupExtender control, that may, or may not, be bound to a Button or a LinkButton. You may want for example to Show/Hide it using custom client or server side code.

Volador, a member of my team, pointed me in the right direction for a solution. The trick is to set the TargetControlID property of the Extender control to an ID of a HiddenField declared somewhere in your aspx Page. Your markup should look something like this.


<ajaxToolkit:ModalPopupExtender runat="server" PopupControlID="pnlModalDialogPopup"
ID="modalPopupExtender1" TargetControlID="hfTarget" />

<asp:HiddenField runat="server" ID="hfTarget" />

July 12, 2008

Help Update in Progress, dexplore

Filed under: Uncategorized — Tags: — dreamlusion @ 8:50 pm

I pressed F1 from within VS about an hour ago. The “Help Update in Progress” dialog popped out and Process Lasso reported high CPU usage from dexplore.

I left it running for a few minutes but eventually, I terminated the process. I found some similar incidents on the net, but nothing providing a reproducible scenario with a solution.

Given that, I got armed with courage and the hope that dexplore has not fallen into a deadlock, and decided to let the process run for a while. If that had failed, I’d have completely uninstalled the MSDN Library from my system.

To my surprise, it finally completed successfully, and I was able to use Help again.

I also found an answer to my question of what triggered the Help Update, that is I installed HTML Help Workshop about two weeks ago.

*** multiple target patterns using CDT 5.0

Filed under: Uncategorized — Tags: , , — dreamlusion @ 10:09 am

Problem Description

If you want to build a project, using the Cygwin tool chain, that has dependencies to a third party library, you might experience a “multiple target patterns” error.

The usual procedure to do build a project that uses a third party library involves two steps.

  1. Add the Includes required for compiling in the Project Properties > C/C++ General > Paths and Symbols > Includes dialog.
  2. Add the library directories in the Library Search Path section of the Project Properties > C/C++ Build > Settings > Tool Settings > Cygwin C++ Linker > Libraries dialog. Then, in the Libraries section of the same dialog add all of your third party libraries.

NOTE: When adding your third party libraries be aware that you need to specify them with neither the “lib” prefix nor the extension. For example, if you have a library called libboost_regex.a, you should type in just boost_regex.a in the appropriate dialog. This is how the g++ compiler works, the Unix way.

Tools Used/Affected

  • Eclipse IDE for C/C++ Developers (Eclipse Platform Ganymede (3.4.0), CDT 5.0.200806171202)
  • Cygwin GCC tool chain (Make 3.81, GCC 3.4.4)

Solution

The root cause of the problem is that the Cygwin GCC tool chain expects paths to be in the unix style, but when Eclipse uses the values you specified for includes, library paths, e.t.c. to automatically generate the appropriate make files, it does not convert these values in Unix style and therefore building fails.

You are going to experience a beautiful build if you change all the paths you entered in Windows format to Unix format (e.g. C:\Cygwin\home to /home).

If you do this though, there is another shortcoming ahead, fortunately smaller than the previous one.

Because Eclipse won’t recognize the Unix path style you’re going to loose content assist (code completion) for the includes you specified and you’ll also get a “Path Entry Problem” warning.

UPDATE: As volador pointed me out, you may use windows paths but with forward slashes.

Conclusion

Paths definition, for projects targeting the Cygwin tool chain, seems to have been problematic since long ago for the CDT environment. There’s a relevant bug report that has been arround since 2005.

July 6, 2008

An error occurred when merging assemblies: Access to the path ‘…’ is denied.

Filed under: Uncategorized — Tags: — dreamlusion @ 1:29 pm

Not much talk has been around this error. There has been some incident reports in the ASP.NET forums that suggest the root cause of the problem is a duplicate type name, typically a page class, in the merging assemblies.

We did encounter some serious problems recently in my work relevant to this issue. The Web Deployment Project for our Web Site that served us well for some time, all of a sudden stopped working giving this error in it’s build output console.

One of my first attempts to solve this puzzle, after having searched the net for an answer, was to check if any of the containing types of the the assembly that seemed to be causing the problem, was given an already existent name across the project, but that was not the case.

I decided to look further the problem by manually compiling and merging the Web Application in order to gain more control over the issuing commands and, hopefully, get the duplicate type name.

As aspnet_compiler has always been compiling the project with success, I didn’t use any extra switches to manipulate it’s error/status output.

aspnet_compiler.exe -v /WebSite -p C:DevelopmentWebSite -u -f -d C:DevelopmentWebSiteBuildTempBuildDir

For aspnet_merge I used the extra -errorstack and -log arguments the functionality of which is described in the ASP.NET Merge Tool presentation article here.

aspnet_merge.exe C:DevelopmentWebSiteBuildTempBuildDir -o WebSiteBuild -a -debug -copyattrs -errorstack -log merge.log

From the extra -errorstack argument I’ve learned that an UnAuthorizedAccessException causes aspnet_merge to fail with this stack trace:

[UnauthorizedAccessException]: Access to the path 'C:DevelopmentWebSiteBuildTempBuildDirbinApp_Web_9imofmvu.dll' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at System.Web.Compilation.Merge.DeleteFileNoThrow(String filepath)
at System.Web.Compilation.Merge.RemoveOldAssembly(Hashtable assemblyMapping)
at System.Web.Compilation.Merge.Main(String[] args)

or

[UnauthorizedAccessException]: Access to the path 'C:DevelopmentWebSiteBuildTempBuildDirbinApp_Code.dll' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at System.Web.Compilation.Merge.DeleteFileNoThrow(String filepath)
at System.Web.Compilation.Merge.RemoveOldAssembly(Hashtable assemblyMapping)
at System.Web.Compilation.Merge.Main(String[] args)

And from the the -log argument I didn’t learn anything as the log file did not contain anything suspicious to me.

The gathered information didn’t help much to achieve my initial goal, to unveil the duplicate type name, so I needed to move onto this mini research.

Having trust to what others say about the problem, and continuing to believe that for some reason a duplicate type name existed in the project – I had nothing else to work on -, I thought I could merge the assemblies using some tool other than aspnet_merge, that will hopefully give me more details if any error occurs.

After some googling I came up with a tool called ILMerge. It is hosted in Microsoft, is authored by Michael Barnett and shares the same codebase as aspnet_merge.

You typically use this tool in command of the following form:

ILMerge /target:(library|exe|winexe) /out:filename Program.exe ClassLibrary1.dll ClassLibrary2.dll

For the specific situation of merging the pre-compiled assemblies of a Web Site, the correct command to use is:

ILMerge /out:WebSiteBuild.dll App_Web_*.dll App_Web_*.dll App_Web_*.dll ...

For ILMerge to work you, obviously, first need to use aspnet_compiler to pre-compile your Web Site. You then need to explicitly specify all the assembly names that you want to take part in the merge operation. If you have PowerShell installed in your system you may issue the following command instead of specifying each assembly one-by-one:

PS C:DevelopWebSiteBuildTempBuildDirbin> $assemblies = ls .* -include App_*.dll -name; &'C:Program FilesMicrosoftILMergeILMerge.exe' /t:lib /out:WebSiteBuild.dll $assemblies

NOTE: You may need a Visual Studio PowerShell Prompt to do this.

and.. BINGO!

If a duplicate type name exists in your set of assemblies you should get the following output:

An exception occurred during merging: ILMerge.Merge: ERROR!!: Duplicate type ‘Company.WebSite.YetAnotherClass’ found in assembly ‘App_Web_y1dnvgxw’.
at ILMerging.ILMerge.MergeInAssembly(AssemblyNode a, Boolean makeNonPublic)
at ILMerging.ILMerge.Merge()
at ILMerging.ILMerge.Main(String[] args)

Now that you have the name of the evil class name, all you have to do is to rename it, but in our case unfortunatelly things aren’t that sweet because the YetAnotherClass IS NOT a duplicate type, and that left me scratching my head..

I thought this should be related to the compilation, and I took a more thorough looked into the aspnet_compiler arguments.

Compiling using the -fixednames argument, and then merging using the ILMerge OR the aspnet_merge tools, makes the problem dissapear, meaning that the compiler no longer produces duplicate type names. Bug?

The problem is that from within VS I fnd no other way to pass the -fixednames argument to aspnet_compiler than to use the “Merge each individual folder output to its own assembly” option which, apparently, is not equivalent to “Merge all outputs to a single assembly”.

To the bottom line, if you experience the “Access Denied” error when merging all output to a single assembly, you may be able to overcome it but, probably, not from within VS, you’ll have to use the command prompt instead.

UPDATE: Using the “Merge all pages and control outputs to a single assembly” option, which calls aspnet_merge with the -w param instead of the -o param, resolves the issues we had.

July 5, 2008

Poor Performance of DataGridView with Image Column

Filed under: Uncategorized — Tags: — dreamlusion @ 11:05 pm

There are various incidents across theweb reporting slow or bad performance of the DataGridView control. In fact, the DataGridView control is designed to provide maximum scalability and is able to handle large amounts of data, but for this to happen efficiently, one has to keep in mind several things .

I’ve personally suffered from poor performance because I thoughtlessly set the AutoSizeMode property of a DataGridViewImageColumn to AllCells. The performance hit may pass unnoticed for tens of rows but in a situation with houndreds or thousands of rows, performance degraded significantly.

A thorough list of best practices for scaling the Windows Forms DataGridView control can be found in the homonymous article hosted in MSDN.

June 24, 2008

Reusable, Typed Assembly Attribute Accessors Class

Filed under: Uncategorized — Tags: — dreamlusion @ 9:58 am

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Dreamlusion
{
	public abstract class AssemblyAccessors<T> where T : class
	{
		public static string AssemblyTitle
		{
			get
			{
				object[] attributes = Assembly.GetAssembly(typeof(T)).GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
				if (attributes.Length > 0)
				{
					AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
					if (titleAttribute.Title != "")
					{
						return titleAttribute.Title;
					}
				}
				return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetAssembly(typeof(T)).CodeBase);
			}
		}

		public static string AssemblyVersion
		{
			get
			{
				return Assembly.GetAssembly(typeof(T)).GetName().Version.ToString();
			}
		}

		public static string AssemblyDescription
		{
			get
			{
				object[] attributes = Assembly.GetAssembly(typeof(T)).GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyDescriptionAttribute)attributes[0]).Description;
			}
		}

		public static string AssemblyProduct
		{
			get
			{
				object[] attributes = Assembly.GetAssembly(typeof(T)).GetCustomAttributes(typeof(AssemblyProductAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyProductAttribute)attributes[0]).Product;
			}
		}

		public static string AssemblyCopyright
		{
			get
			{
				object[] attributes = Assembly.GetAssembly(typeof(T)).GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
			}
		}

		public static string AssemblyCompany
		{
			get
			{
				object[] attributes = Assembly.GetAssembly(typeof(T)).GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
				if (attributes.Length == 0)
				{
					return "";
				}
				return ((AssemblyCompanyAttribute)attributes[0]).Company;
			}
		}
	}
}

June 22, 2008

Unpack an Inno Setup Installer

Filed under: Uncategorized — Tags: — dreamlusion @ 10:42 am

I thought I should give MONO a try and load it in my machine, but prior to installing I wanted to inspect what was going to be installed to avoid possible problems. I noticed that MONO is packed using Innot Setup.

Inno Setup Unpacker does what it’s name suggests. Just run

innounp -x <setup.exe>

and you’re done.

No, I mean NO desent solution to check my mail??

Filed under: Uncategorized — Tags: — dreamlusion @ 10:37 am

Lately I’ve been using GmailAssistant to check my GMail accounts. Many consider this as the “Ultimate GMail Notifier” and other characterization have been given as well, but when I first started using it, I thought that although it has some nice features, such as support for multiple GMail accounts, and encryption of the settings file, it lacked some essential functionality and user friendlines.

For example you could have multiple profile files, but most of the time you’ll be using just one, so that one precious profile could be stored in the user’s home directory. Furthermore, you’re always asked for the profile password, even if one isn’t setup.

The most annoying feature for me was the password that always popped up in my screen, because I had the program started on my system start up, so I though I should fix this. I fired up Eclipse to see what I could do, and I found to my dissapointment that, although I liked the coding style, the program lacked a consistent UI design. The lack of use of a designer, in applications that have windows, forms, e.t.c. (which is not that uncommon in the Java world..) is a problem and delays the evolution of the project, so I dumped the project.

Various other mail notifiers exist, some targeted in the .NET framework some for the JRE, some built on top of Yahoo! Widjets, Firefox or some other platform.

Those built on top of Yahoo! Widjets or Firefox or another hybrid-programmatic platform I consider them to be an overkill to use, and thus not an option. As a user I just need something that does not consume much memory, sit’s on the tray and tells me whan I have new mail, as simple as that.

From those that run as autonomous programs, I have tried some. Namely:

  • The original Google Notifier
    Well there’s not much to mention here, it merely has any features.. just checks your inbox. Have used it for a while.
  • RSS Notifier
    I must admit that I was impressed by this one. It supports RSS, POP and IMAP and it is well designed. Unfortunatelly, there are some downsides. First, it’s a bit slow checking IMAP and second it doesn’t support feeds like those used by Gmail. I’m not sure exactly what the problem was, it should either be SSL or authentication, but not sure…

Others certainly exist, but I have not tried them mostly for two reasons. Either they’re not build on .NET (-> so probably their UI wasn’t designed using a designer -> so either A) the UI will suck, or B) they will have put much effort in the UI and the program functionality will suck), or I’m not aware of it.

So, where do we end up? Option A) is to take some vacations in an exotic island. Option B) is to use Thunderbird. Besides, appart from being a descent notifier – althoug it does not consume memory as a notifier but 35MB isn’t that bad (thunderbird 3.0a1 without any extensions) – it also usefull to keep your email contacts in it, so that you don’t have them sparred across various online address books.

You can find more email clients (MUA) here.

June 19, 2008

Represent related DLinq entities in a TreeView control and Find a typed TreeNode

Filed under: Uncategorized — Tags: — dreamlusion @ 8:06 am

The following post presents a way to represent DLinq related entities in a TreeView control. It also provides a way to search for a specific typed TreeNode based on the entity id and the entity type.

For search to work, it is assumed that the TreeNode.Tag property contains the ID of the entity.

public abstract class EntityTreeNode<TEntity> : TreeNode
{
	public IEnumerable<NWhereTreeNode> EnumerableNodes
	{
		get { return Enumerable.Cast<EntityTreeNode>(Nodes); }
	}

	public EntityTreeNode<TSubEntity> Find<TSubEntity>(int pID) where TSubEntity : class
	{
		var resultingNodes = from n in EnumerableNodes
				where (n is EntityTreeNode<TSubEntity> && (int)n.Tag == pID)
				select n;

		if (resultingNodes.Count() > 0) // Wow! I got it.
		{
			return resultingNodes.First() as EntityTreeNode<TSubEntity>;
		}
		else // Do recurse
		{
			EntityTreeNode<TSubEntity> resultNode = default(EntityTreeNode<TSubEntity>);
			foreach (EntityTreeNodentNode in EnumerableNodes)
			{
				resultNode = ntNode.Find<TSubEntity>(pID);
				if (resultNode != null)
					break;
			}

			return resultNode;
		}
	}
}
Older Posts »

The WordPress Classic Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.