Digiwar - the Yeep-blog

November 18th, 2006

Windows Vista

So on friday Windows Vista was available for download at MSDN. Actually, it was available thursday night, so I got lucky and downloaded it before the big rush I guess.

After I got the download in, I burned it to DVD and started installing it on my laptop. Now, I use this laptop for work. I develop webapplications and webservices for both .NET 1.1 and .NET 2.0 on it. So I need both Visual Studio 2003 and Visual Studio 2005 working. Can you see where this is going?

The first hurdle I encountered was the vast difference in the interface. I wanted to install IIS, but it took me a while before I found it. In hindsight it’s pretty logical, but I was thinking too much in Windows XP. Windows Vista comes with IIS7, which is different then IIS6 or IIS5 (both of which look remarkebly the same from the management interface point of view). I spend some time looking at the options, then added a webapplication and worked to get it running correctly. As with IIS6 I had some trouble getting all the security setup correctly. Then I spend a lot of time getting it to run on ASP.NET 1.1. Apparently, by default, it runs on ASP.NET 2.0 and even an ASP.NET 1.1 application will, in fact, be run on ASP.NET 2.0. There is some sort of backwards-compatibilty in there to make it work. But I really wanted it to work in ASP.NET 1.1. So I had a lot of tweaking to do, but after a few hours of Googling, trying and cursing, I was able to make it work.

What you have to do is install .NET 1.1, then add the ASP.NET .1. ISAPI filter DLL to the “ISAPI and CGI restrictions” part of the configuration and set it to ‘allow’. Then select the ASP.NET 1.1 Application pool and your done. In my case I also needed to comment out some stuff in the globalk web.config and the local web.config. I’ll see how I can make it run with both ASP.NET 1.1 and ASP.NET 2.0 later, when I fix my remaining problems.

So, the website was working. Not to get Visual Studio 2003 up and running.
The thing is, it’s not supported. That’s right. Microsoft puts great pride in their ‘backwards compatibilty’ layers, some of which stop Windows from utilizing it’s full potential, but they won’t make VS2003 work on their new OS. By the way, do wanna now what old development enviroment did they spend time on? Visual Basic 6.
That’s no joke. Apparently the reason is that migrating from .NET 1.1 to .NET 2.0 is easier then VB6 to something else. And in that they are correct, however that doesn’t help me a s developer at all! If operations won’t install .NET 2.0 on the production machines, then I can’t update the codebase. So I’ll need to run VS2003.
To make things even more interesting, even VS2005 isn’t fully supported(!!!!!!!!!!!!!!!) Even after you install servicepack 1 (which is currently in beta) there will still be ‘issues’.
So let me get this straight….even though Vista was in development for over 5 years, they can’t make an application they released last year compatible? And here I thought Steve Balmer thought developers where so important.

Currently I can’t get VS2003 to open a web project. It’s complains that the source directory does not match the IIS share. And from what I read on the internet, this isn’t even supposed to be the problem. The real problem is related to debugging.

It’s really simple. If I can’t get VS2003 to work with Vista, I can’t upgrade and I’ll go back to Windows 2003 Server. Then only after we upgraded all .NET 1.1 applications to .NET 2.0 and Microsoft got their act together to get VS2005 working perfectly on Vista, can I upgrade to Vista. And this goes for my home machine too. Sure I play games on it, but I also develop some stuff as a hobby. If I can’t run VS2005, I’m not upgrading anytime soon. Shiny aero glass windows or not.

[Last played: Testament - The Haunting]

July 12th, 2006

Treeview boldness

This is something I’ve had on my “to-write”-list for some time now.

When I started working on Feed Vortex I wanted to have a treeview with the feeds you we’re subscribed to and when you’d have unread articles the feed would have its name in a bold font and the number of unread articles would be in paranthesis behind the name of the feed.

It was pretty simple: just get the font object from the treenode, make it bold and put it back. Easy as that.

Until I looked at the treeview. The longest feed label seemed truncated. I first thought this had to do with the window I had put the treeview on, but this wasn’t the case. It turns out that the treeview determines how much space it should reserve for its labels only when you create it, or add a new treenode to it. Basing it on the font it has at that time.

So the solution was actually pretty simple. Create the treeview with a bold font by default and then add a treenode with a regular font. The other way around doesn’t work. Also, just to be sure, I added some additional spaces to the end of the label, just to make absolutely sure I have enough space left to display the label when I set the font to bold.

[Last played: Nightwish - Beauty Of The Beast]

April 18th, 2006

Writing a plug-in architecture in .NET

So I wanted FeedME to be versatile. I want it to be able to use any back-end. So for that to be possible I need to create a plug-in architecture so you can easily write a DLL that provides a new back-end to FeedME. The plug-in architecure is basically just a list of functions FeedME will assume are there and will want to use. The best way to achieve this is by defining interfaces.
So I went on happily defining all kinds of functions in different interfaces. Then I decided that I only wanted singleton classes.
For those that don’t know, a singleton is a type of class that get’s instantiated only once. You keep on using the same instance throughout the lifetime of the process.
You do this by defining a class whose constructor is private and which has a static Create() function. The class also has a static variable that simply contains an instance of it’s own class. So the create function just returns this reference and so everytime you call Create(), you get the same class reference. Ofcourse it can be implemented in some other ways, but I just wanted to explain what a singleton is.

So, I wanted to define a static Create() function in the interface, but you cannot do that.
Allrighty….so then I tried making an abstract class that implements the interface which has a static Create function. And again, not possible. Well it’s possible to create the abstract class, but in order for a derived class to implement it’s own Create() function I need to mark it “virtual” and that’s not allowed on a static function.

*sigh*

So I just made the normal interface and put in the comments/documentation that the class must behave in a singleton manner.
I did define a factory interface with Create() functions, but they are just not static.

That’s what I’m missing right now, some way of enforcing design pattern usage for classes that derive from a base class or who implement an interface. I would like that even more then LINQ.

Another issue I ran into was how to instantiate the class whose name you don’t know. In “old” days you’d create a DLL which had a C function in it that created the class for you. But in .NET you can’t have a stand-alone function, they’re always part of a class. But then I remembered that’s what reflection is for. You can just look in a DLL and see what classes are in there and implement which interface. So all I need to do is enumerate through the classes in the DLL until I find the one that implements the interface I need.
Sounds simple, but I have not yet implemented it, so I don’t know if it truly is that simple. I’ll know soon enough :-)

[Last played: Lacuna Coil - Devoted]

March 9th, 2006

I will not REST until this problem is solved

The Google API for Google Reader has not been released. At least officially. I found a real good head-up at Niall Kennedy’s weblog. The information there is more then enough to get you started. The information in the main article is not complete though. You can find out some more tidbits in the comments and I also found some more stuff while working on FeedME. It hadn’t occured to me how easy it actually is to get some information about the API. I figured, it’s a web application, so all the interesting communication happens at the server itself, no way I can get to that. I had even downloaded the javascript file Google Reader uses for it’s work when it occured to me that, yes, this is a web application. It’s a web 2.0 (I really hate that term, but now everybody should know what I mean) application. It uses Ajax, which means that all communication with the server backend originates from my own machine! Add Fiddler and you’ve got a neat protocol-sniffing-setup :-)
I’m thinking about doing a page on the Google Reader API to put all the info I have at one location.

Anyways this is not about the Google Reader API, at least not in depth. What I am going to write about is the HttpWebRequest, WebResponse and the Uri classes of the .NET framework 2.0.
These were the classes that I wanted to use for communicating with Google. The are built for that purpose! In fact, they worked perfectly for the first API I incorperated, the call to download your subscription list. After I had that working and had a really basic GUI I was ready to move on to the next thing: Downloading the articles for the feeds I’m subscribed to.
The Google Reader API is a REST API (or at least based on some REST principles). This means is uses simple HTTP GET and HTTP POST commands to communicate with XML. Okay, so this also covers SOAP, but the thing with REST is that it doesn’t have predefined XML to use. It’s all up to the implementation. Whereas SOAP has everything standardized except the data itself.

Getting your subscription list is just sending a GET at a specific URL, let’s say: “http://www.google.com/reader/api/subscriptions/” (This isn’t the real URL, just an example). You’ll then get some XML back that describes your subscriptions. Simple to do with HttpWebRequest.
To get the articles of a specific feed, you need to add the URL of the feed to the URL. An example (also not real): “http://www.google.com/reader/api/feed/http://www.digiwar.com/feeds/”
This would give you the articles from this website that Google have in their Reader database. Now here I ran into a problem.

The HttpWebRequest class takes, or converts your string into, a Uri object. The Uri object is a real useful class that does all kinds of useful stuff to the URL you supply. Like checking if it’s a valid URL, removing contradicting directory paths or removing those pesky doubles slashes some people put in their URLs by accident. Do you see the problem already? If not, I’ll give you 5 minutes to think about it.

Take your time.

You got it? Good. So you aggree with me that I was really frustrated that my HttpWebRequests ended up going to “http://www.google.com/reader/api/feed/http:/www.digiwar.com/feeds/” instead of the correct URL. Nothing I could do would help. I tried double-double slashes, tried escaping them, tried encoding them as “%2F”. Nothing worked. I did a lot of Googling on the subject, inquired in newsgroups. Nowhere did I find an answer. So what did I do? I wrote my own HttpRequest, HttpResponse and Url classes.

The Url class was really simple. It just houses a few strings and does some parsing in the constructor. It does no validation whatsoever.
The HttpRequest and the HttpResponse class where a bit harder. For them I P/Invoked a lot of WinInet functions. One important thing learned here: If you ever need the P/Invoke signature of a Win32 function, or at least a good pointer in the right direction, just google for “dllimport “. Also visit pinvoke.net, it’s really useful.

And ofcourse, after I had everything up and running (beautifully I might add) some one found an answer for me. Apparently if you encode the second double slash as ‘\u2215′. So you’ll end up with “http://www.google.com/reader/api/feed/http:/\u2215www.digiwar.com/feeds/” and this seems to work. I still have to test it in a realy world scenario (such as my program), but I’ve just invested a lot of time in my custom classes and it’s working perfectly, so why switch?
I might switch back to the .NET classes sometime in the future, but for now I’m content with how it is.

[Now playing: The Kovenant - Jihad]

March 7th, 2006

Writing your own news aggregator

So I took the task upon myself to write a Windows application that allows me to sync with Google Reader and allows me to read my feeds I have in Google Reader. This is not a post for plugging that application though. This is a post, or probably one of a series of posts, about the things I learned while programming the application.

But to spend just a few words on the application: I’m going to call it “FeedME”. I had thought up that name probably two years ago when me and a colleague were already considering writing a feed reader. The project never got really far, but the name stuck.

So far the application allows you to log in, retrieve the feeds your subscribed to and then the unread articles from those feeds. The articles are show in a real simple newspaper format in an embedded Internet Explorer control. That’s about it.
The biggest hurdles I crossed so far? Downloading the feeds from Google (getting the subscription list is easy, getting the articles of a particular feed is much harder, more on that later) and logging into Google.

Logging into the Google Reader is complex, but not really that hard when you think about it. The thing is you can’t just send a username and password combination to a webservic. At least not that I know of. No, you have to use cookies and then, somehow, find out the Google SID for the user. I will explain this in detail later!

So, expect some articles about the problems I encountered and how I solved them (or worked around them) in the future. And if I get it into a workable state, I will release FeedME for everyone to use. Free of charge!

Right now I’m gonna see if I can come up with a nice way to mark a seperate article as ‘read’ and ‘unread’ and how to tell Google that and how to show that in my application (no support for read articles yet).

[Last played: Static-X - Trance is the motion]

January 21st, 2005

Things learned this week

This week was a very tiresome week. Not because of all the work I did, but more because of the lack of sleep. For some reason I could not sleep for more then 5 hours at a time at night, so I was very tired through-out the week.
But, I did learn two very interesting things:

  1. When a file is added to a Visual Studio Project/Solution, make sure to specify “FileShare.Read” when opening it with a FileStream from inside that project. Otherwise you’ll get an “Access denied”-error. Which is very distracting, because I’d expect a “Sharing violation”-error, but maybe that’s just me.
  2. When making an MPS provider and you’re storing data in the ProviderHelper rollback store, use strings and ints! I made a really handy class to encapsulate the data for me, but then I got “No such interface supported” errors somewhere inside MPS (not even inside my provider!!). At first we thought it might me a bug in MPS, or maybe a configuration error on my dev machine, but then I wondered if the MPF maybe tries to serialize the object stored in a database or something and my class wasn’t serializable. So I just started storing the data as strings and it worked. I’m not sure if it was the serializable thing, because making my classes serializable would probably be more work them just reworking the data to be stores as strings. So, just use strings!



[Last played: - ]

January 12th, 2005

More fruit!!!

More fruit from my labor. Although this isn’t much fruit, it’s a little fruit, maybe even slighty weird fruit, but that’s just a cheesy movie reference.
The fruit in question is a small class that contains one static member to retrieve a string value from an XML file. The name of the XML file is based on the name of the assembly that called the function and it only looks for the file in the current working directory. In other words, it’s a assemblyname-based configuration file reader!
I made this, because I couldn’t get the (mandatory :-( ) ’standard’ configuration reader, that was provided by my teamleader, to work. I just used mine for the debug build and implemented theirs for the release build. Let them figure out wich goddamn filename to use for their fucking ’standard’ config file. Do I seem frustrated? Hell yes! I changed the source for this config reader to match my personal style, but for the project I had to make it conform to their ‘coding standards’. The difference is about half the lines of code. That’s 50% of the source that’s unnecessary crud. And they want it for ‘readability’. Yeah…right….

[Last played: Strapping Young Lad - Critic]

[Now playing: My Life With The … - Starmartyr]

January 5th, 2005

Fruits of labor 2: Revenge of the fruit

Well, well. The second fruit of my labor has risen. I’m currently developing custom Microsoft Provisioning Services (MPS) providers. These are COM DLLs written in C#. The problem is that when we test them, the MPS process keeps the DLLs loaded (so the files are in use). So if I edit the source and recompile, I get errors because my post-build script can’t overwrite the DLL, because they are in use. Stopping and starting the two MPS services doesn’t help. The only thing that helps is manually killing the DllHost process from the task manager. However, there are two such processes and I need to kill only one of them. One is owned by the system and one is owned by an MPS user. This is not an issue when killing the process by hand, you can see the owner in the task manager, but when I tried to automate it I ran into a small issue. For as far as I could see, there is no way to determine the user who owns the process from the System.Diagnostics namespace. I even looked at the standard Win32 API funcions, but still no dice. The task manager knows, so I too should be able to find it out.
Then it hit me: WMI! I checked and indeed. With WMI I can enumerate the processes (in fact, thanks to WMI’s SQL-like interface, I can select the process I want based on its name) and then get the user who owns the process.
So I wrote a small program and plugged it into my post-build step. It doesn’t work a 100% (for some reason the program is finished and the post-build script tries to copy the files while the process is still busy terminating), but it works good enough for me.

To get the program, simply download this file and put it in a new Windows Forms project. It’s an empty Windows Forms class (I created it as Windows Forms, because a console application would pop-up a DOS box and I don’t like unneeded pop-ups :-) ) and all it runs is the Main() function.

To plug it in my post-build script I used the following code, maybe you can use it as well:

position = InStrRev(WScript.ScriptFullName, "")
scriptDir = Left(WScript.ScriptFullName, position)

set shell = CreateObject(”WScript.Shell”)
shell.Run scriptDir & “ProgramKill dllhost.exe MPFServiceAcct”,, true

December 31st, 2004

Fruits of the labor (Unix crypt() in C#)

Like I said earlier, I started working on a new project at work. And the first fruits of the labor are ripe for the picking :-)
I submitted an article over at the CodeProject which is a C# implementation of the Unix crypt() function. So if you need something like that, you over there and have a look.

This reminds me, I really need to update this page so I can put some of my work here.

October 13th, 2004

Unix timestamp conversions for .NET (in C#)

Right, so there I was, porting a small tool I once wrote from MFC to C# and trying to extend it. In my work I occasionally deal with Unix timestamps and I need to be able to convert them easily, so I wanted to add that functionality to my tool. But then I ran into a problem. You see, the .NET framework knows two kinds of timestamps. Ticks, which is the time since january 1st 0001 in 100 nano-second increments and FileTime, which is the time since january 1st 1601 in 100 nano-second increments. Neither of which maps to the timestamp used on Unix, which is the number of seconds since january 1st 1970.

First I Googled a bit and noticed the question had been asked before a few times, but I could not find an answer quick enough, so it looked like I had to do it myself. Fortunatly, it’s not that hard.

From Unix to .NET
This is the most simple. Create a DateTime object with the date of january 1st 1970 (12 AM) and just use the AddSeconds method to add the Unix timestamp:

public static System.DateTime UnixToDotNet(int unixTimestamp)
{
	System.DateTime date = System.DateTime.Parse("1/1/1970");
	return date.AddSeconds(unixTimestamp);
}

From .NET to Unix
The other way around is a bit harder, but not much. First create a TimeSpan object to cover the time from january 1st 0001 to january 1st 1970. This is the amount of time we want to ignore, because Unix time starts from january 1st 1970.
Substract that timespan from the .NET time you have and then divide the resulting Ticks, representing the time since januray 1st 1970, by 10 million. That gives you the time in seconds, which is the Unix format:

public static int DotNetToUnix(System.DateTime dotNetTimestamp)
{
	System.TimeSpan span = new System.TimeSpan(System.DateTime.Parse("1/1/1970").Ticks);
	System.DateTime time = dotNetTimestamp.Subtract(span);
	int t = (int)(time.Ticks / 10000000);
	return(t);
}

Easy enough.

September 2nd, 2004

.Net and LDAP

So, one of the first things I learned using C# to do some LDAP queries is that when you create the System.DirectoryServices.DirectoryEntry object and you specifiy the protocol to use (in my case LDAP), the text-string in which you specifiy it is CASE-SENSITIVE! Imagine my amazement when nothing in Windows was case-sensitive and all of a sudden this is!
“ldap://myldapserver” doesn’t work, while “LDAP://myldapserver” does. Retarted!

Another thing. When you connect to an Active Directory, it imposes a result limit of 1000 records. Meaning you can’t get more then 1000 records out of a single query. It took me a few hours to figure this one out, but it turns out it’s really simple!
The System.DirectoryServices.DirectorySearcher object you use to do the actual searching, has a property called “PageSize”. Setting this to 1000 (or 999 as I do, just in case) solved that problem, because the object will then get the results of the query in batches of 1000 (or 999) and add them together for you to use later on. So to you the programmer it’s like you receive all the records in one call and to the LDAP server it looks like the call has been segmented into smaller calls each receiving 1000 (or 999) results, staying nice below the server imposed limit.
You should know, however, that when I set the PageSize to anything but the default, I couldn’t query our Netscape LDAP. For some reason that LDAP doesn’t understand the PageSize property.

September 2nd, 2004

Learning C#

A few weeks back I bought a C# book by O’Reilly and started reading it. Turns out C# is a pretty cool programming-language. And since all kinds of new projects at my work involve (or will involve) Microsoft technologies, it’ll be particulary useful for me to know some .Net programming.
I wrote some small and simple C# programs to help me out with some small menial tasks at work, but to really learn the language I decided to try and write a real application with it. Recently my interest in XMPP (Jabber) flared up again, so I decided to try and write an XMPP-client in C#. It’s not supposed to be for general use, it’s just a learning project for me. I can learn both C# and XMPP doing this, both technologies which can really make a difference in my line of work.
So expect some of the things I’ve learned to show up on this blog and maybe, really really maybe, there might one day be a downloadable XMPP-client on this site. Don’t hold your breath though….

[Last played: My Life With The … - Starmartyr]

|