PostSharp 1.0 - First Impressions

Ok so I must've been sleeping under a rock or something, so this is no doubt old news to many people - but PostSharp completely slipped by without me noticing it until now... Having played with it tonight, I'm definitely liking it :)

So far I've just used it for doing some AOP... unlike doing AOP using something like Dynamic Proxy / AspectSharp in Castle, PostSharp gives you a more... personal experience... letting you apply AOP to internal or sealed types, and allowing you to declaratively setup aspects with very little effort... as an example I created a simple little class for recording and playing back methods out of sync... so, first off I have a recorder interface:

public interface IRecorder
{
bool IsPlayback { get; }
void RecordMethod(MethodInfo method, object[] parameters);
}

Following that I implemented a base class for recording the methods, and allowing for playback:

public class BaseRecorder : IRecorder {
private readonly List
_methods = new List();
private bool _isPlayback;

#region IRecorder Members

public void RecordMethod(MethodInfo method, object[] parameters)
{
_methods.Add(new RecordedMethod(method, parameters));
}

public bool IsPlayback
{
get { return _isPlayback; }
}

#endregion

public void Playback()
{
try {
_isPlayback = true;
foreach (RecordedMethod method in _methods) method.Replay(this);
} finally {
_isPlayback = false;
}
}

#region Nested type: RecordedMethod

public class RecordedMethod {
private readonly MethodInfo _method;
private readonly object[] _parameters;

public RecordedMethod(MethodInfo method, object[] parameters)
{
_method = method; _parameters = parameters;
}

public void Replay(object instance)
{
_method.Invoke(instance, _parameters);
}
}

#endregion
}

Pretty basic - then I wrote myself the aspect - it really could not be simpler:

[Serializable]
public class MethodRecordAttribute : OnMethodInvocationAspect
{
public override void OnInvocation(MethodInvocationEventArgs eventArgs)
{
IRecorder recorder = (IRecorder) eventArgs.Delegate.Target;
object[] arguments = eventArgs.GetArguments();
if (recorder.IsPlayback) eventArgs.Delegate.DynamicInvoke(arguments);
else recorder.RecordMethod(eventArgs.Delegate.Method, arguments);
}
}

And finally a demo... so I create a recorder class of my very own and decorate it with the attribute created above:

[MethodRecord]
public class MyRecorder : BaseRecorder
{
public void SayHiTo(string name)
{
Console.WriteLine("Hi {0}", name);
}

public void AddSomeNumbers(int x, int y)
{
Console.WriteLine("{0} + {1} = {2}", x, y, x + y);
}
}

And now a quick demo:

[TestFixture]
public sealed class TryOutPostSharp
{
[Test]
public void RecordAndPlayback()
{
MyRecorder recorder = new MyRecorder();
Console.WriteLine("Starting to record");
recorder.SayHiTo("Alex");
recorder.SayHiTo("Renee");
recorder.SayHiTo("Blog subscribers");
recorder.AddSomeNumbers(10, 20);
Console.WriteLine("Starting to replay");
recorder.Playback();
Console.WriteLine("All done");
}
}

The output is:


Starting to record
Starting to replay
Hi  Alex
Hi  Renee
Hi  Blog subscribers
10 + 20 = 30
All done

Which I think is pretty darn sweet, I can definitely see this having a place in my toolbox in the near future - especially when attempting to uphold DRY in some of my code - anyone using it on production projects in NZ at the moment?

So how does PostSharp pull it off?  Well it post-processes the compiled assembly... it does so by hooking in to an existing extension point in msbuild, so that the post-processor is executed for any project where it references the PostSharp.Public assembly.

All this means that you get to see a couple of extra lines in the build output during compilation:

Compile complete -- 0 errors, 0 warnings
PostSharp 1.0 [1.0.7.261] - Copyright (c) Gael Fraiteur and
Community, 2005-2007.
TryPostSharp ->
C:devexperimentsTryPostSharpTryPostSharpbinDebugTryPostSharp.dll

========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

But how does it really work? Well if we take a look at the list of 7 approaches to AOP Ayende did ... then it fits into the last two (Compile-time & Run-time IL Weaving).

If you have been living under a rock like myself I'd definitely suggest talking 10 minutes out of your day to give it a quick try.

Read More

Architecture Chat 16

Quite a good turnout, with well over a table full (I didn't take an official count, but I'm guessing around 12 or more) including Alex James and Keith (who we hadn't seen for a while) and two newcomers from Olympic Software, which was great - we always like to see fresh faces and ideas.

I talked very briefly about Castle Project RC3 - I suggested it was a week or two away from getting out the door, but in fact - It's out as of about an hour ago! (11:30am) - the website and documentation is still in the process of being updated, but the installer and binaries/source are all here.

I was going to run through some of the changes I like in RC3 - but the conversation got steered away before I got warmed up - but it's well worth checking out, if you haven't been keeping an eye on the trunk and the changes that have been going in.

At any rate - this is the culmination of a huge amount of work from many of the Castle contributors, I think it even has a 2 line patch of my own in there somewhere :P ... great work guys!


PLINQ
- talked about PLINQ getting closer, and the fact that parallelization is a very hot topic of late, with a few noting that the last MSDN mag was almost entirely focused on this subject.

On a tangent, Erlang cropped, not too many of us have had exposure to the language details, but Keith had done some spelunking and gave us a quick rundown of how it all hangs together, definitely something to keep an eye on - Andrew Peter's even called
it his "Language of the year".

I brought up the MediaDefender debacle that's been unravelling over the last
week or so since their huge mail leak.  Not only are the inner workings of this organisation pretty unprofessional and certainly bordering on unethical for a corporation, but it highlights the risk most organisations run - the source of the leak being one employee who automatically forwarded all his work email to a gmail account, who then used the exact same credentials elsewhere.

Keith gave us some insight into LUA, including why it doesn't make an attractive language to port to .Net, and why it's so much easier to embed in a C++ based project as opposed to something like Ruby, which just seem to be designed for that purpose, especially with it's "out of the box" set of global variables.

I asked the question "What web load testing apps do you use" - and the answer was generally, we don't!... I've been reviewing WebLOAD - which looks quite good, especially because the load machines can be deployed on a non Microsoft machine, such as Linux, making it easier to span a number of load machines out on something like Amazons elastic cloud (EC2), or low-cost machines without the hassle of O/S licensing.

We then moved onto talking about high-scale load testing, i.e. simulating a million simultaneous requests - somebody suggested that maybe you could hire whoever's pulling the strings on the Storm BotNet - though I'm not sure they're into self-promotion ;o)

We talked about social networking applications, and leveraging social networking platforms with API's such as face book, this has been a popular topic over the last couple of months, including:

  • Finding the killer app(s) that could leverage an API like face book's, and making money out of it.
  • Bad habits encouraged by these platforms, such as requesting your email account username and password to "email your friends".


Alex James brought up the great series of posts that Rowan Simpson has been making lately - not everyone knew who Rowan was... so hopefully they should know now ;o) the posts walk through, the Trade me manifesto, and then drills into:
Over lunch we talked about many things, mostly non-IT related, but some things that did come up, including that the Mac OS isn't going to have a NZ Daylight savings time update before Daylight savings actually kicks in, though it's not really a problem.

Some things that got mentioned which I didn't quite catch the details of:

  • Metabase (I'm not sure I got the name right - couldn't find a link, but apparently it's a game / game development platform, in alpha development at the moment, where all game assets have an associated URL, and maybe an RSS Feed??) - Alex James suggested it might be interesting to combine something like that with a web based data storage platform, such as freebase, developed by Metaweb Tech.
  • Jason K (Knowles?) - who apparently supports the Idea of every user having there own domain, to cement their various web identities together, and where all their data is held by them in one place. - can anyone throw me the correct name and url?

Read More

Architecture Chat 16 Tomorrow

Sooo....

Another architecture chat tomorrow, 11:30am at the usual spot... some possible topics for discussion.

  • Row vs Column database storage, is Column based storage important?
  • Dead Skills - What skills are on the way out / way in for Developers, DBA & Architects?
  • Castle Project RC3 will be out shortly, I'll let you know whats going on.
  • I've been watching quite a few TED presentations over the last month or so - and it leads me to wonder, what sources of Inspiration do people tap into for their own Software Creation?
  • PLINQ update - it's getting closer!
  • I thought this was interesting - a new way to detect code theft, though how many of us in NZ actually fear code theft at the moment?


Light on topics, but still there's plenty of things to fuel debate - look forward to seeing you all there.  If anyone has anything else they would like to talk about it (or raised for debate, if you can't make it along) then just leave me a comment or flick me an email.

btw - Not sure if Alex James will be making it along to this one, but if he does, it will certainly be his last before leaving NZ for the U.S of A.

Read More

Architecture Chat 15

Architecture Chat


So we had a reasonable turnout today, with 9 people.

First up for discussion was the move from Microsoft to assist with the development of Moonlight - which is making silver light an even more compelling proposition then it was before...

There was a brief talk about WPF component suites ... some of the more win forms focused of the group are looking for an easier migration path from Winforms to WPF lead by a full featured control suite...  A few of us observed that Telerik are planning to release a WPF suite of controls later on this year, and of course they already have RadControls
for Silverlight
available now.  DevExpress are also planning to release WPF controls "some time" this year, though not much information is available on just what makes up a "control suite" for WPF, considering the power provided just through the great data binding experience, simple controls like lists and the native 3D support.

Following that we had a rather rambling conversation sparked off by Alex J buying an iMac for his mum, and my desire for an entirely modal windows experience for my grandmother - or at least something that stopped windows from being able to completely occlude each other (which can cause all sorts of confusion when people associate a window "disappearing" with an action having taken place, like an email being sent).

Peter mentioned a project (which I didn't quite catch the name of) which creates a "modal" almost terminal-like experience for windows, which sounds like it could be interesting... I'm thinking perhaps I need to write myself a entirely modal shell for windows... maybe a task for a full-screen WPF app ;o)

That lead on to a conversation about undo and document change tracking, concluding in a few thoughts - we covered a random assortment of topics including MOSS 2007, WebDav and the poor uptake/usage of shadow copy some of the "thoughts" included:

  • New versions of documents shouldn't be able to overwrite old documents, period, bake in at the OS level.
  • There needs to be a change to the usability of undo/redo so that you can move backwards and forwards through change history using a slider or some kind of similar time line experience.
  • Previous text can be copied and then the slider dragged back to the "current state" to paste (With no way of interacting with the previous state, to avoid accidentally loosing the current state).


After that we branched out into talking about Load balancing, Amazon E2 i.e. the Elastic cloud, Peter hadn't heard about  Grasshopper but seemed pretty excited by the thought of converting .Net applications to run on J2EE (and as such, commodity hardware) - though Gareth mentioned it wasn't all that cheap, so you probably need to avoid having to pay a few windows server licenses to balance to books.

Data Layer Componentization and the concept of a DataServer also got a mention, a long with some discussion around the lack of an off the shelf product which solves some of the "tough" problems with implementing highly scalable and distributed data platforms ah la things like BigTable and similar map-reduce style data storage concepts.  I wonder if Pile can offer us anything in this space as well?

Last of all Alex J briefly asked about mixed-mode authentication for IIS - as it happens Ayende recently posted about this, with the gritty details of getting it to work.

And I think that's about enough from me... also don't forgot we have 2 user groups next week (Tuesday in Ellerslie, Wednesday in Auckland Central), details are below.

Next Week : User Group Meetings

Ellerslie


A lap around Visual Studio 2008 & A lap around C# 3.0

11/09/2007 (Tuesday) Gathering at 5:45, starting at 6:00

A lap around Visual Studio 2008
Presented by Darryl Burling
Explore all the new Visual Studio 2008 features, from language enhancements; improved designers; Web and smart-client development tools; to Visual Studio Team System, a suite of software life cycle management tools poised to transform how you deliver software for Windows Vista, the 2007 Microsoft Office system, and the Web.

A lap around C# 3.0
Presented by Alex James Explore quickly the new features of C# 3.0, including things like LINQ, Lambda Expressions, Anonymous Types etc.

Catering: Pizza & Drinks
Door Charge: Free
Parking: Free, just park in Olympic Software's car park.

Venue

Olympic Software
10 Cawley St
Ellerslie,
Auckland

Map To Venue

Auckland CBD


A lap around Visual Studio 2008

12/09/2007 (Wednesday) Gathering at 5:45, starting at 6:00

A lap around Visual Studio 2008
Presented by Darryl Burling
Explore all the new Visual Studio 2008 features, from language enhancements; improved designers; Web and smart-client development tools; to Visual Studio Team System, a suite of software life cycle management tools poised to transform how you deliver software for Windows Vista, the 2007 Microsoft Office system, and the Web.

Catering: Pizza & Drinks
Door Charge: Free

Venue

Microsoft
Level 5,
22 Viaduct Harbour Avenue,
Auckland

Map To Venue

Read More

2007-09-05 - Architecture Chat Tomorrow

Hi All,

Another architecture chat tomorrow, 11:30am at the usual spot... some possible topics for discussion.

  • Data Layer Componentization.
  • OOXML - the "no with comments" response - anybody bother finding out what the comments were?
  • Google wiki.
  • IronPython, IronRuby... now IronLisp.
  • The so called "Digestion Phase" for technoloy.
  • Mono Olive - WF, WCF, System.Query/Linq, Xaml support (no WPF as such).


If anyone has any other ideas for discussion, just leave a comment on my blog... or just pop along tomorrow.
Read More