Tigraine

Daniel Hoelbling-Inzko talks about programming

Presenting .less at the Barcamp Klagenfurt 2010

Barcamp Klagenfurt 2010

Time goes by way faster than I’d like it to and the Barcamp Klagenfurt 2010 is coming up really fast. (6-7. February)

While usually I was quite hesitant to choose a topic due to the diversity of the attending crowd (unfortunately not really enough real technical topics represented there), this year I think I can bring something very interesting to the camp: .less.

The advantages are obvious, with a crowd of bloggers, artists and also technical people talking about something as ubiquitous as CSS, and ways to improve it, will surely resonate well, allowing me to be a bit technical without raising too many question marks above my audience’s heads like last year (where I talked about IoC and Windsor).

As for the talk itself, I plan on first going over general features of Less (since we are a port I can also point people over to the Ruby version if they are more comfortable with that than with .NET ), and then into a tiny bit of detail about how .less works internally.

Finally, I hope to see as many people as possible at Barcamp Klagenfurt! Thanks to the team for organizing this year after year!

Filed under barcamp, dotless, personal

Print dialog not showing up on Windows 64 Bit on a AMD CPU

Imagine the following: Clint calls telling me “Hey Daniel, I just got a new computer with Windows 7 64 Bit installed, everything is working great so far. The Software you wrote a year ago works fine on it too, only problem: I can’t print”

My immediate reaction: “Reboot the system” (ok kinda lame, but I have spent too much time with problems that went away through a reboot to not suggest it).
Well, but the reboot didn’t help here. Even after rebooting the print dialog was still not showing up.

Now, I know for a fact that the Software runs fine on Win7, I also know it runs fine on Win7 x64 (since I developed it running both x32 and x64 Win7 Beta builds back in the day). And since I am using the PrintDialog class provided by the .NET framework I wasn’t really sure what  could be the issue. I mean, hey that’s a framework class, those things are supposed to run cross platform and be CPU ignorant. But hey, why not simply ask Google the most stupid question I could think of: “windows 64 .net print dialog” ..

And the answer was right there on Microsoft’s MSDN page as a remark:

Also, The PrintDialog class may not work on AMD64 microprocessors unless you set the UseEXDialog property to true.

WTF? (Ok more words come to mind, but since I don’t want to get hatemail for my language I’ll leave it at that).

We are talking about a class in the .NET BCL that is supposed to work cross plattform (at least Windows), be completely CPU ignorant (fully managed), and yet I have to set UseExDialog to true to see this dialog on a AMD CPU? Are you kidding me Microsoft?

Well, the fix was quite easy (thankfully). I went into my PrintDialogFactory and changed one line of code, packed a new release and sent it to my client, yet my confidence in BCL classes has been severely shaken.

I really don’t know anything about the reasons for this odd (to say the least) behavior, but I can say that I am a bit sad to see it monkey-patched like this. Especially in a VM environment like the .NET framework I expect Microsoft to solve their system-specific problems under the hood where I can’t see them and don’t have to care about them.

Filed under net, programmierung

.Less now supports files from the VirtualPathProvider!

Ok, I’ve just spent almost the whole day refactoring the hell out of our .less codebase just to add one tiny change:

Allow users to not only load files present on the current file system, but also directly from in-memory strings and VirtualPaths (as requested on the list). The problem here being that not everyone wants to serve his .less files right from the server’s file system but sometimes people have pretty sophisticated virtualized storage systems in place that require them to use the VirtualPathProvider abstraction that was added to .NET 2.0.
You can read up on that in ScottGu’s blog or David Ebbo’s blog, but in a nutshell it’s just another way to open files besides using System.IO.File.Open(), letting you forget about all the nasty stuff of where the file is really located. 

To do so I had to allow uses to plug in different “Sources” for .less code, and so I also had to make a breaking change to the main ILessEngine interface. The Interface was taking a filename as parameter, but in light of our recent support emails on the development list I decided that has to go away in favor of a more open approach (mainly to allow users to simply throw in-memory strings at the engine).

Because I know this will break some code, all implementors of ILessEngine still offer the old string parameter as an overload that then defaults to the default FileSource.

Now, for changing the source provider:

If you want to use anything besides the default filesystem based FileSource provider, you now have the ability to plug in a type implementing ILessSource through the DotLessConfiguration (thus through web.config).
.Less comes with three sources built in: VirtualPathSource, FileSource (default).

FileSource by default just opens a file through System.IO.File, while VirtualPathSource will use the HostingEnvironment.VirtualPathProvider.GetFile() method to open a Stream and read the .less code from there.

To enable the VirtualPathSource in your web application you simply need to modify your web.config a bit:

<dotless minifyCss="false" cacheEnabled="true" source="dotless.Core.VirtualPathSource">
  
</dotless>

The important part is the source attribute as it has to reference a type name implementing ILessSource. So if you want to create your own less source you could simply create another implementation of ILessSource and reference it’s name in the .less config.

If you want to use .less directly from your code to transform something you can just new up a LessSourceObject (the very output we get from ILessSource) and throw your code in there like this:

ILessEngine lessEngine = new EngineFactory().GetEngine(new DotlessConfiguration());
var output = lessEngine.TransformToCss(new LessSourceObject() {Content = "my .less code here"});

As always you can get the latest code from GitHub, or the latest binary release through our TeamCity build server. You can read more about .less (pronounced dot-less) on the project’s website at http://www.dotlesscss.com.


And while at it, we’d appreciate it if you spread the word about .less :).

Happy New Year 2010!

It’s been a busy year 2009, and I’m quite pleased with how things turned out.

I had a lot of fun going back to university, working on various open source projects like .less, elmsConnector, Pandora.

I can only hope you enjoyed 2009 as much as I did, and hope 2010 turns out even better. Thanks for reading my blog and have a nice 2010!

Filed under personal

My Photography business

Projects

dynamic css for .NET

Archives

more