Categories: .Net, Silverlight Posted by mheydt on 8/16/2008 11:46 PM | Comments (0)
I was wondering how to do this and found this link...

Tip of the Day #11 – Transparency - How to make your Silverlight control transparent. - Mike Snows Silverlight Blog

Blogged with the Flock Browser
Categories: .Net, C#, C++, WPF Posted by mheydt on 8/7/2008 12:03 AM | Comments (0)
I've gotten a few requests about the force directed graph post that I made several months back.  Seems that this is a popular topic for people trying to find code to do this, and I've been asked several times to post the code.

First, I don't know how robust and scalable this control is, as I was only writing it to learn some WPF control templating.  Also, I modeled the engine off of some code in another open source project that is GPL.  I say modeled as I literally wrote my own off of that code, but because of that it is somewhat similar, so I wonder about distributing my code before I do some checks into licensing.  Until I figure that out, you can get the code that I started with over at the Netron site and do similarly to what I did.  Note that the code in that project supports a lot more functionality, is highly intertwined with WinForms code (not WPF), and that is where I spent most of the time converting things into an engine that only does force directed layout, is seperate from the UI, and of course with a WPF interface.

And, as I mention in this post, I've actually moved on with creating what should be a much more robust force directed graph control using the C++ boost graph library wrapped with C#.  That code is in a really early stage and not worth posting at this point, but given the interest I may very well try to get it better and posted for everyone.  That is free to distribute if that time ever comes.  Unfortunately, it does not work quite as well as the former project at this point as I am still learning how to do the C++ to C# integration.

Categories: .Net, ActiveRecord, ALT.NET, AoP, C#, Castle, Rhino Posted by mheydt on 8/6/2008 11:25 PM | Comments (0)
I've been doing quite a bit of messing around with Rhino Commons the last few days.  I really like the ability it has to let you use Castle ActiveRecord without needing to derive from a base class, to provide access to objects through the Repository<T> class, and to not have to use NHibernate XML configuration files (yuk).

However, one of my struggles with it is that the library assumes that you are in a web app, as you must derive your application class from the UnitOfWorkApplication class, which is itself derived from HttpModule.  Well, this is a problem if you are writing a console app, service, or other non-web application, as the UnitOfWorkApllication class does a lot of setup in its constructor that is needed to use all of the cool features of the library.

So, after much diving into the source code to figure out what's going on (there is almost no documentation on how this library actually works), I was able to write my own application class, appropriately called GenericUnitOfWorkApplication, which can be used in non-web apps (specifically, console apps).

As an example, here is my sample console application which show you how to use this class, while storing a new domain object in the database and then iterating across all of them:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Model;

using Rhino.Commons;
using _42Spikes.Rhino.Commons;

namespace TestConsole
{
    class Program : GenericUnitOfWorkApplication
    {
        static void Main(string[] args)
        {
            new Program().run();
        }

        private void run()
        {
            UnitOfWork.Start();

            Repository<User>.Save(new User("Mike Heydt"));
            
            With.Each<User>(
                Repository<User>.FindAll(), 
                t => Console.WriteLine(t.Name));

            UnitOfWork.Current.Dispose();
        }
    }

    public abstract class With
    {
        public delegate void operationdelegate<T>(T o);
        public static void Each<T>(
            IEnumerable<T> objects, 
            operationdelegate<T> f)
        {
            foreach (T i in objects) f(i);
        }
    }
}
You can download this entire solution (short of the database) here.

What's going on there is that the Program class derives from my GenericUnitOfWorkApplication class, and when its constructor is run it does all the initialization of the Castle and NHibernate stuff that the UnitOfWorkApplication class does, minus all of the web stuff (like setting up things to manage unit of work mapping to ASP.NET sessions).

The down side of this is that the unit of work is not set up automaticaly, and you need to do it yourself.  Oh well, a small price to pay I think for this great functionality.

And I really like the brevity of this code and now much functionality it has in just a few lines.  Also note my use of a custom With class to apply a lambda function to each element of the database, which I think is quite nice syntax.

Just thinking out loud here, I still think that there are a few things things that I still need to do with this code:
  1. I like that the original UnitOfWorkApplication would map units of work to the session automaticaly.  It's only a few lines of code up there, but it would be nice if this could somehow be automatic.  I think the solution to this is to use PostSharp to apply an aspect to specific methods that automatically create the UnitOfWork.  That would be cool.
  2. This class is still a problem in an application like WPF where your app object needs to derive from a framework class, so this class is not really of use in that situation.  However, there is nothing magic about this class as it does not have to be your base class, you can create a singleton instance of it in your app.  All that is needed is the initialization code run in the constructor.
Which leads me to wonder about the use of AoP.  It would seem to me that you should be able to automatically inject this functionality into your application class.  I'll have to look into how to do that with PostSharp.

Categories: Silverlight Posted by mheydt on 8/3/2008 6:47 PM | Comments (0)
I just came across this nice writeup on creating a silverlight photo browser:

Will Allan's Blog: Creating a Silverlight image viewer

This was referenced by the following article:

http://www.michielpost.nl/PostDetail_11.aspx

This was an extension of the former, which extended the original to retrieve photos via an RSS feed and generate thumbnails.

IMHO, this is a great utilization of Silverlight to overcome some of its difficulties, that of having access to server side content (particularly files and their contents).  Exposing data via RSS for the client to access solves this quite nicely.

Blogged with the Flock Browser

Tags:

Categories: .Net, ALT.NET, AoP, C#, PostSharp, Dependency Injection, MbUnit, NLog, Rhino, Castle, ActiveRecord Posted by mheydt on 8/3/2008 6:21 PM | Comments (0)
I'm starting a new project at a client tomorrow, and I think I'm going to go with a lot of Alt.Net stuff on it.  Specifically, I'm looking into using:

  • Visual Studio 2008 SP1
  • .NET 3.5 SP1
  • PostSharp (for AoP)
  • Rhino Commons (for simplifying access to NHibernate and such)
  • Castle Windsor (IoC and DI)
  • Rhino Mocks (Test Mocks)
  • NHibernate (Database Access)
  • MbUnit (Unit Testing)
  • NLog (or log4net)
I actually would really have liked to try Linq, but I'm using an Oracle database so that goes right out the window.  I don't even want to try to use EF as I don't need that much of a hammer on this...

I've only got a nominal amount of database reading and writing, so I think I'm going to front this access with the Rhino Commons and Castle Active Record.  I really don't want to write any ADO.NET or NHibernate XML files, so this looks like a good way to go.  I also want to use DI to be able to inject either database mocks or actual data classes into tests.  I want to also be able to run this in disconnected mode, so some mock data would be great when provided through DI.

I've used MbUnit before, so I'm staying with that, although I'm going to move up to the new version which apears to have some more features.

The big thing I want to move into is the AoP model (as well as DI).  I just got the latest version of PostSharp installed and it worked great, at least with initial tests.  I'm big on logging in the applications, but I really have been wanting to do cross-cutting instead of explicitly coding it all over the place.  This looks like it will solve this nicely for me, as well as combined with some DI I should be able to inject null loggers into the system for optimization.

Categories: EC2, Mac, QEMU, S3, Ubunto Posted by mheydt on 8/3/2008 5:14 PM | Comments (0)
I saw a presentation the other day on Amazon EC2 which got me quite intrigued in the use of this service for doing “cloud computing”.  I currently host several sites for a couple of people on a dedicated windows server at a hosting center, and I’ve lately been wondering about other options so as to make things both easier and to save money, and this looked good at least at first sight.

The basic problem with it for my situation is that I’m running services that run on NET on windows servers, and the EC2 services only support Linux servers.  This immediately made me start to think about how I can get around this.  My first thoughts of course went to VMWare, but that would also necessitate buying VMWare in addition to Windows.  So, I did a little googling and I found this link:

http://www.howtoforge.com/amazon_elastic_compute_cloud_qemu

Interesting stuff, so I figured I’d give running windows with QEMU on an Ubuntu install.  I run VMWare Fusion on my mac, so I went and downloaded an Ubuntu appliance from VMware and had that up and running within a few minutes, as well as copying over some windows 2003 server .iso’s (which you can see on the desktop):

(booting up):


(running):


First thing I had to do (via the link) is install yum, as it wasn’t installed by default in this ubuntu appliance.  Well, it appears that Ubutnu doesn’t use yum, but something called apt-get, so where told to use yum in the link, I used this command:
sudo apt-get install qemu
The next step is to create a disk image for qemu to install windows into.  This is done with the following:
qemu-img create -f qcow win2003.img 4G
And then after arguing with the system about the amount of shared memory (I still don’t really have this worked out, but I got it running with 128m), I got the following command to start the virtual machine as can be seen in this image:



I will have to say that I am impressed with this; running virtualization software within virtualization software!

I’m going to let this run for a little to get the install done and I’ll continue the post more later.