Tuesday, December 21, 2010

My Bag of Tools for 2011

This is my bag of tools. I need to constantly improve it. I will update my list with new tools. And with replacement which are superior to what on the list already.

Visual Studio Add-ins

.Net Development & Frameworks

Process & Project Managment

Desktop/Browser Utilities

Videos

My ToDo List

Monday, December 13, 2010

WCF readings and downloads

There is a lot of useful blogs out there. And the technology surrounding WCF as a communication line between businesses is growing. But there is also a growing demand for more interacting web pages which can benefeath from this technology. REST, Json and Ajax.

Start reading here:

Thursday, December 02, 2010

'', hexadecimal value 0x1F, is an invalid character.

Using XElement to create html in code behing. Reusing the existing code with new data, the XElement gives this error  trying to access the ToString() method. Obviously the problem was that the new data contains 0x1F character.

From the blog, http://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/:
The decimal range for ASCII control characters is 0 – 31, and 127. Or, in hex, 0×00 – 0x1F. The problem that causes these XmlExceptions is that the data being read or loaded contains characters that are illegal according to the XML specifications. Almost always, these characters are in the ASCII control character range (think whacky characters like null, bell, backspace, etc). These aren’t characters that have any business being in XML data; they’re illegal characters that should be removed, usually having found their way into the data from file format conversions, like when someone tries to create an XML file from Excel data, or export their data to XML from a format that may be stored as binary.

This is a very accurate match for this case. The text which contains this character is OCR read from paper as the only source.

The solution was to manually replace this character with a white space, before adding the value to the XElement.

.Replace((char)(0x1F), ' ')


Wish I could do this more generic, with a framework Encode method.

Friday, November 26, 2010

Compiling in Release Mode

Adding WebformsMvp with NuGet to an existing WebForms project worked like a charm. I’ve been running the site and new page on my localhost for a few days now. In Debug mode that is. But when the time for a deployment has come, my problem arises.

Could not load file or assembly ‘file:///C:\xxx\bin\WebFormsMvp.dll’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) … SGEN

Compile debug mode. No problem. Compile release mode. No. Remove references, and adding again. No effect.

Solution:
To build the project with the build settings for Generate serialization assembly set to Off.

Questions to be answered is why? And will this impact my solution in the production enviroment?

Monday, November 22, 2010

WebformsMvp

WebformsMvp looks like what both me and this “old” project was needing. This old project I’m talking about isn’t really that old, only two or three years. The entire solution is written in webforms with some ajax. So the WebformsMvp looked as a very good framework to incorporate for new pages and rewrites. Using NuGet made incorporating WebformsMvp as easy as two clicks. After setting up my model, view and presenter the page threw an error: “An exception was thrown whilst trying to create an instance of …”. This error came when the ascx access Mvp or model. Manually upgrading to the build 0.9.7.4 fixed this bug.

Experience so far gives me high hopes for this framework and pattern.

Friday, September 17, 2010

Some words on Norwegian letters

First as a proud Norwegian, I must say this problem hadn’t been there if not the Swedish also had their own letters. We Scandinavians always have jokes about the Norwegian, Swedish and Danish who did something, and the better man is alway the Norwegian here in Norway. Likewise in the other countries.

The Danish and Norwegian alphabets end with æøå, whereas the Swedish and the Finnish ones conventionally put åäö at the end. The website I do some development for had this page with a list of proprietors.

screenshot

The heading displays all 29 Norwegian letters. Clicking on one of the letters causes the list to only display proprietors starting with this letter. The letter is given in the url with a postback. Like this at the end of the url; “&letter=68” for the the letter D.

The codebehind looked like this:

1 proprietors = proprietors.Where(x => x.Name.StartsWith(Convert.ToString(currentLetter)));

The problem with this were names which starts with letters other than the Norwegian. In this case a proprietor starting with the Swedish Ä, which didn’t show up either beneath A, Æ or Å. And with CultureInfo set to Norwegian, I would say Ä and Æ should be equal.

I was hoping the framework could offer me a solution for my problem. With an operation that could thell me that Ä equals Æ for Norwegian culture, and even A equals Ä equals Æ equals Å for CultureInfo(“en-US”). But I could not find such methode. Please let me know if you have any suggestions or ideas about this?



So what I had to is a more complex Linq where I do something almost like a sort. And then pick every name equal or larger than the current letter, but lower than the next letter. This way I get hold of Ä which is placed here sorting with Norwegian culture“…XYZÆÄØÅ”. This way finally the Swedish company showed up:



image



The code ended up like this:



1 //reduce list to all with letters larger or equal currentLetter
2 var fromChar = currentLetter == Alphabet.First() ? StartChar : currentLetter;
3 proprietors = proprietors.Where(proprietor => string.Compare(proprietor.Name.First().ToString(), fromChar.ToString(), true, new CultureInfo(AlphabetCulture)) >= 0);
4
5 //reduce list to all with letters smaller than the next letter in alphabet
6 var nextChar = NextLetter(currentLetter);
7 proprietors = proprietors.Where(proprietor => string.Compare(proprietor.Name.First().ToString(), nextChar.ToString(), true, new CultureInfo(AlphabetCulture)) < 0).ToList();
8

With theese supporting methods and constants:

1 private char currentLetter;
2 const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ";
3 const string AlphabetCulture = "nb-no";
4 private const char EndChar = '\uffff';
5 private const char StartChar = '\u0000';
6
7 /// <summary>
8 /// Returns the next letter in <see cref="Alphabet"/>. If latest letter, 'Å', then return the larges Unicode char.
9 /// </summary>
10 /// <param name="letter">The letter.</param>
11 /// <returns></returns>
12 private char NextLetter(char letter)
13 {
14 var index = Alphabet.IndexOf(letter);
15 return index + 1 < Alphabet.Length ? Alphabet.ElementAt((index + 1)) : EndChar;
16 }


If you got any feedback on how to this this better and more generic, please let me know! Thanks.

Wednesday, May 26, 2010

Share a single mouse and keyboard between multiple computers

I must advertise for this nice and cool utility.
Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems, each with its own display, without special hardware. It's intended for users with multiple computers on their desk since each system uses its own monitor(s).
Redirecting the mouse and keyboard is as simple as moving the mouse off the edge of your screen. Synergy also merges the clipboards of all the systems into one, allowing cut-and-paste between systems. Furthermore, it synchronizes screen savers so they all start and stop together and, if screen locking is enabled, only one screen requires a password to unlock them all.
Synergy is found here at sourceforge: http://synergy2.sourceforge.net/

EDIT: I've some issues with syngergy+. Most of the time it's working perfectly. But sometimes the master and slave doesn't seem to connect. I'm currently trying out Input Director as an alternative. http://www.inputdirector.com