February 2009 - Posts

Mozilla Lab Concept Series, Aurora, and Flow

Shortly after I started playing around with Flow and put my ideas on paper (or at least digitally), someone pointed me to Adaptive Path’s Aurora Project. The brainstorm that lead to me writing about Flow preceded the publishing of the first Aurora video. I believe that I had created the first prototype before the video was published as well. It was really inspiring to me because I envisioned in Flow many of the concepts demonstrated in that video. What’s very interesting to me is this quote from their site:

This is not a demonstration of a real product. What you see in the video is a visualization of our ideas created by animators. Technologically, much of Aurora would be difficult or impossible to implement today. However, we expect everything you see to be possible in some form in the future.

Their desktop browser concept is definitely feasible, I think the Flow prototype shows this. It wouldn’t be difficult to replace the graphs with  The concept of synchronization across devices is enabled through Live Fx. WPF has a very rich visualization story and almost any data that can be pulled from a web page (for example a table of precipitation data) can be bound and transformed through different visualizations.

I don’t think that “Flow” would ever serve as a primary browser. Or I should say it’s not one of my goals to make Flow a new web browser but rather an Information Browser. In order to make a good browser, Flow would need the capacity of rendering HTML to WPF natively. Hopefully, Microsoft will one day release a native WPF browser control. Or I will attract the attention of an HTML rendering wizard. Until then, web browsing in Flow will be limited by the capabilities of the BrowserControl.

Posted by Mike Brown | with no comments
Filed under:

Static Reflection: Say What?

There’s a new oxymoron going around call Static Reflection. The basic gist is that by using expression trees you can do things that appear to be dynamic but in reality are checked at compile time. Like for instance, getting the name of a property for firing an INotifyPropertyChanged.PropertyChanged event. My colleague, Jon Fuller, showed me his code for Method Guards and my first comment was that this would be a great tool for implementing INotifyPropertyChanged. He informed me that he already went there and showed me that code as well.

I wasn’t too happy with the idea of wasting your sole base class on NotifyPropertyChanged so I suggested that we use extension methods instead. After a bit of finagling with the framework (Events don’t like to be fired from outside their declaring class), here is the result:

        public static void SetProperty<T>(
		this INotifyPropertyChanged source, 
		Expression<Func<T>> propExpr,
		Expression<Func<T>> fieldExpr,
		T value)
        {
            source.SetProperty(
		propExpr, 
		fieldExpr, 
		value, 
		() => { });
        }

        public static void SetProperty<T>(
		this INotifyPropertyChanged source,
		Expression<Func<T>> propExpr,
		Expression<Func<T>> fieldExpr,
		T value,
		Action doIfChanged)
        {
            var prop = 
		(PropertyInfo)
		((MemberExpression)propExpr.Body).Member;
            var field =
		(FieldInfo)
		((MemberExpression)fieldExpr.Body).Member;
            var currVal = (T)prop.GetValue(source, null);
            if (currVal==null && value==null)
                return;
            if (currVal==null || !currVal.Equals(value))
            {
                field.SetValue(source, value);
                var eventDelegate =
			(MulticastDelegate) 
			source.GetType().GetField(
				"PropertyChanged",
				BindingFlags.Instance | 
				BindingFlags.NonPublic).
				GetValue(source);
                Delegate[] delegates = 
			eventDelegate.GetInvocationList();
                var args = new PropertyChangedEventArgs(prop.Name);
                foreach (Delegate dlg in delegates)
                {
                    dlg.Method.Invoke(
			dlg.Target, 
			new object[] 
			{ 
			  source,
			  args 
			});
                }
                doIfChanged();
            }
        }

Now you can use a strongly typed NotifyPropertyChanged declaration without using your base class

    public class PersonStaticReflection : INotifyPropertyChanged
    {
        private string _firstName;
        private string _lastName;
        public string FirstName
        {
            get { return _firstName; }
            set { this.SetProperty(
			() => FirstName, 
			() => _firstName, 
			value); 
		}
        }
        public string LastName
        {
            get { return _lastName; }
            set
            {
                this.SetProperty(() => LastName,
                                 () => _lastName,
                                 value,
                                 () =>
                                     {
		// do something useful here
                                     });
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

For those concerned, you can statically cache the PropertyChanged field in a dictionary mapped to the object type so that you only have to reflect on it one time.

Posted by Mike Brown | 3 comment(s)

Get Your Hands on Flow

Quite a while ago, I first started hinting about “Flow”. I’ve given friends and colleagues information about the project, and have been teasing everyone with screenshots and videos. Monday, I started a series that I call “Refactoring to Patterns: WPF Edition” in which I started the task of building Flow from the ground up. A few moments ago I wrote a post discussing the background of Flow and finally made the prototype available for download. There is going to be some crossover between my other blog and this one here. But I’m getting ahead of myself.

I’d love to get your feedback. I will be publishing a Codeplex project where you can submit bugs, join the discussion, and even download the code. Until then, you can leave a message for me at either of my blogs. Happy coding!

Posted by Mike Brown | with no comments

Entity Framework Has Layers Like an Onion

If you’ve been following my tweets, you’ll know that I’ve been experimenting with Entity Framework lately. I’ve been digging around, looking at the generated code for EF and realized something very interesting.

    [EdmEntityType(NamespaceName="DBO", Name="Project")]
    [Attribute(IsReference=true)]
    [Serializable()]
    public partial class Project : EntityObject
    {

You see that? My entity has Attributes on it…very similar to NHibernate attributes. Here’s another interesting tidbit from a property that exposes a relationship between two entities (a so-called Navigation Property)

[EdmRelationshipNavigationProperty(
  "DBO", "FK_tblTasks_tblProjects", "tblTasks")]
public EntityCollection<Task> Tasks{
   get{
     return RelationshipManager.GetRelatedCollection<Task>(
                 "DBO.FK_tblTasks_tblProjects", "tblTasks");
   }
   set{
     if ((value != null)){
       RelationshipManager.InitializeRelatedCollection<Task>(
         "DBO.FK_tblTasks_tblProjects", "tblTasks", value);
   }
}

Notice that the navigation property has an attribute giving the name of the relationship (here the same name as the foreign key) and the related entity name (again given the same name as the foreign table). Behind the scenes it uses a relationship manager (property of EntityObject) to get/set the values.

So What’s Your Point?

The point is that the generated code is nothing more than a strongly typed convenience layer over the EF API. The point is that it is possible to provide your own engine that lays over this API and removes the coupling to EntityObject from your Domain Objects. The core of Entity Framework…the database abstraction layer…is very solid. It’s begging to have a proper O/RM engine placed on top of it.

Posted by Mike Brown | 1 comment(s)

Starting the New Year With a Bang!

Yes I know it’s February already, but this should show even more how big the start of this year has been for me. First and foremost is the big announcement that the new year brought.

MVP_FullColor_ForScreen

First and foremost, I’ve been named an MVP in Client App Development (for my community contributions with WPF). This is an incredible honor for me. In addition to the title, being an MVP provides me an opportunity to have better interaction and feedback with Microsoft especially with regards to my specialization. According to the program guidelines, the award is for my past activities and I am not required to do anything else.

However, I want to leverage this opportunity to the fullest and will continue my community contributions going forward, both with regard to WPF and Silverlight as well as with Windows Azure.

USAltNET

Second, as an organizer for our local Alt.NET User Group, Indy Alt.NET, I’m excited about a few recent developments with the group. Chief among those being named an official INETA group – something that surprised me seeing that there was already an INETA group in the Indianapolis area. We are coming on our first anniversary and have seen our attendance stabilize at around 25 per meeting. With almost a year under our belt we have sat down and started a few initiatives.

One major decision will be to incorporate as a non-profit organization (an idea we had thrown about for a while but were too busy with day to day operations to act upon). This action will allow us to apply for grants and begin some community outreach initiatives that we are all excited about. It will also make us more attractive to potential sponsors as certain donations to us will be tax deductible.

Another initiative has been a marketing and sponsorship drive. We are trying to grow organically, but we have noticed that we have a chicken or egg scenario. Therefore, we are pushing our growth on multiple fronts. So far we are getting good feedback from our efforts.

Our biggest initiative about which we are all very excited is planning for a local conference. More on that later ;)

SEP-logo

But wait there’s more! I just finished my first year with my current employer, Software Engineering Professionals. Management announced a number of initiatives here that are pretty exciting for me. I can’t necessarily talk about them right now, but it reaffirmed my decision to come here. I can honestly say that I have grown dramatically since I’ve been here. It is an amazing place to work, and I’m excited to see what the future has in store.

SEP-logo

Finally, my family is counting the days until our latest addition is expected to arrive.

Like I said, this year is starting off with a bang…and there’s more to come. I’ll keep you posted with new developments.

Posted by Mike Brown | 1 comment(s)
Filed under: