insert entertaining tagline here

Beijing Day 2

Friday, 29 August 2008 21:26 by markscottjohnson

A day of rather average weather put paid to my original plans to head over to the Forbidden City as planned. So instead I thought I would check out the local (indoor) shopping. As expected, a roaring trade in fake clothing (abercrobie and fitch seemed to be the most common) is going on in the peripheral shopping malls. What is more surprising is that the more central shopping streets (and there are a few) are doing an equally roaring trade in legitimate equivalents.

Anyway, despite the weather, I did manage to accumulate a couple of anecdotes:

Little emperors and their split pants: Needing my first tea of the day, I ventured into a branch of Macdonald's (Are you proud of me Pete?) and attempted (surprisingly successfully considering my accent) to purchase a 'yua cha'. However, whilst doing this I observed what appeared to be mum and grandma 'excitedly discussing' the exchange of various previously ordered food items at the behest of a fat 5yr old boy who was climbing freely on the counter and almost over the other side. What made this most interesting was his short pants had a deliberate split from front to back, such that his dignity was quite visible to all and sundry in the queue. This I took in my stride would have erased from my mind had I not seen another child with the same 'ventilated' trousers on later in the day. This time a rather well dressed mummy was holding him up in the air - legs up, flap open - about a foot above a street waste bin in the middle of a particularly busy pedestrian shopping area. I should have been quicker in reaching for my camera, as then I would have been able to post an image of the little guy in mid crap! A little googling shows these are known as kaidangku and an established part of Chinese child rearing!

Struggling Artist Scam: Highlight of the day had to be my first encounter with 2 rather innocuos scam artists. Whilst sitting on a wall outside the silk market (centre of the cheesy Chinese antique/painting/pearls/mahjong set industry) I was approached by a girl and her 'cousin' (both students and about 19/20) who after making small talk for a while were desperate for my critical opinion of their work in painting 'exhibition' nearby. Needless to say alarm bells rang, but they were endearing and it was the middle of the day so I indulged them for about 30 minutes of chatting and eventually followed them round the corner to the 'art gallery' (ie small room at back of courtyard with handwritten english sign saying 'gallery'). After being shown innumerate pictures (all identical to ones I had seen piled to the ceiling in the market only hours before) that they claimed to have either painted themselves or their tutor (who was both a man and a woman depending on which one I asked) whist they dutifully solicited my artistic opinion (and keanly wrote down in big 'visitors book') I eventually tried to make my exit... This is where the totally unexpected mention of a 'donation' came out - supposedly to help them go to Copenhagen (apparently last year the school went to Barcelona but it wasn't very 'good'). As you can expect, knowing me, I was having none of it. But as a final attempt to beat me into submission, the guy insisted on demonstrating his caligraphy by painting a personalised scroll with Petra and I's name in Chinese (he was a hopeless romantic you see). When I actually saw how cack-handed his writing was (especially compared to the work he had claimed to have done only 5 minutes before), I had to hold in my laughter and in the end took pity on him and gave them 50Yuan (8 bucks). This was obviously far too much, as it made their day but was pretty much the going rate I had seen earlier and seemed perfect value to me for over an hours entertainment...(Petra: clear some space on the wall for one more piece of clutter).

Anyway, I have been typing for over an hour now (see below) and have to go and shower in preparation for my first encounter with the local nightlife...

PS: The other great Chinese (Fire)Wall is definitely in action...Despite a verifiable ADSL2 network level connection speed (yes, the hostel's router still has the default admin password) surfing in China is almost dial up slow!

Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   Travel
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

MVC Pageflow

Tuesday, 26 August 2008 17:50 by markscottjohnson

A few years ago I was responsible for selecting the WCSF (Web Client Software Factory) as the architecture for a website for one of my clients; at the time it was 'the' MVC based framework being touted most heavily by Microsoft.

Although it eventually turned out to be a mixed experience over the life of the project (particularly the Guidance Toolkit aspect), the feature that caught my eye when choosing it was the use of WF state machines as an underlying navigation management framework. This seemed particularly appropriate for the project as the previous version of the website had suffered badly from poorly implemented and unmaintainable navigation (the site presented multistage applications for financial products with complex dependencies between data and the order and display of pages).

Anyway, to paraphrase the 15th century French, 'WCSF is dead. Long live Asp.Net MVC!' So with this in mind, I thought I would see how easy/useful it would be to re-implement the use of WF as the basis of a generic 'wizard' MVC controller - separating the responsibility for all navigation to an underlying workflow.

At first I planned to use a standard state machine workflow wrapped in an MVC Controller class in the same way the WCSF had worked - but then I remembered Matt Winkler's Pageflow sample. This was a specialised workflow type designed explicitly to model navigation graphs and released informally through his blog back in mid 2007 (sadly too late for my first project).

So, after downloading and re-familiarising myself with this, I set about coding a generic MVC Controller class that would support the standard multi-step actions we all expect in wizards (Start/Resume/Previous/Next/Abort) by delegating the required view selection logic to an instance of a Pageflow workflow. To make this vaguely realistic, I decided that anything I wrote had to be able to reproduce 'Workflow1' sample included with the download of the Pageflow bits (a 6 page (with two data driven steps) helpdesk request example). I also restricted myself to referencing the Pageflow DLL (Microsoft.Samples.Workflow.UI.dll) without recompilation.

Here is what I came up with:

MvcPageflow.csproj

This class library is the crux of the solution and where all the Pageflow to MVC logic resides, in particular:

  • The WorkflowWizardController class contains the majority of the code. It is a generic class (parameterised by a Pageflow derived type) that defines the actions described above and handles all the necessary communication with the Pageflow instance.
  • The WizardControllerViewData (internal) class. This is passed to all views (which are defined as ViewPage<Workflow1Controller.WizardControllerViewData> to allow them to enable/disable various navigation options and to receive the output of the previous Pageflow transition.
  • The HttpCookieWizardContextManager class which is the default implementation for handling the correlation of client requests and Pageflow instances (see below).
  • EnhancedBookmark class which derives from the original Bookmark class by adding IsStartingActivity/IsTerminatingActivity properties necessary for the population of similar properties passed to the view.
  • EnhancedNavigationManager again derived from the equivalent NavigationManager class adding extra methods for working out the IsStartingActivity/IsTerminatingActivity info for each stage.

Note: The two final classes are certainly not the most elegant implementation and are only necessary as a result of my self imposed restriction to maintain binary compatibility with the original Microsoft.Samples.Workflow.UI.dll.

MvcSampleWeb.csproj

A standard MVC web project with:

  • A Workflow1Controller (derived from WorkflowWizardController with a few logic specific methods overridden).
  • 6 simple views (copied in layout from the Asp.Net pages of the original sample) and with Previous/Next/Abort links enabled based on the ViewData passed to them.
  • An edited Index view with links to Start/Resume a Workflow1Pageflow process and some explanatory text.

MvcSamplewebPageflow.csproj

A a standard workflow class library containing:

  • Workflow1.xoml - the unaltered Pageflow (modelling a helpdesk request) from Matt's original Asp.Net sample.

Note: I actually started off with Workflow1.xoml in the same folder as the Workflow1Controller class in the MVC web project, but the WF designer continually crashed until I placed this in a separate assembly.

MvcSampleWebTests.csproj

This is a standard VSTest project that contains a few rudimentary tests which exercise the Workflow1Controller, checking all the views are transitioned to in the correct order and that the Resume and Abort actions work/throw appropriately.

Note: The the 'fake' context/request/response test helper classes are extracted as-is from here.

In Summary:

So exactly how hard was this, well not very hard at all. The only really interesting/difficult decisions were:

Instance Correlation: As we all know, the browser/server interaction is essentially stateless, yet state machine workflow's are fundamentally stateful so how do we reassociate a client's request for a relative action such as 'Next' with the correct Pageflow instance (which maintains the knowledge of which state Next is to be applied to). Well, the original Asp.Net example used cookies and so do I. Although for you IoC fans out there, this is factored into an interface (IWizardContextManager) and made a Controller constructor dependency for easy substitution.

Pageflow/View Communication: The original sample had a reaonably tight coupling between the Pageflow and the pages (as is the way with traditional Asp.Net). One of my goals was to write a reusable base Controller which could be derived from and used to model more than just trivial Next,Next,Next processes. If, like the Workflow1 example, these required branching logic within the Next transitions based on user entered data there needed to be an easy way to pass this into/and out of the pageflow. The solution I came up for output data was simple, make it a property on the ViewData class passed to the views. For the input data, which would vary from view to view, I added a virtual GetWorkflowInputData() method that can be overriden to provide any data into the workflow at each action. This can be seen in action in the Workflow1 controller which simply returns the appropriate request form fields depending on the view; these are then used internally by the transitions on the EnterAlias and EnterProfile Pageflow InteractionActivities to decide which activity (and so view) comes next.

Future Areas for Improvement:

WorkflowRuntime: WF requires Pageflows (as with all workflows) to run in a single instance of the runtime configured with the appropriate services. Purely for ease of coding the download currently stores this in a static field of the WorkflowWizardController - this would be better placed in the Application object. The configuration of this runtime is also currently hardcoded (see download instructions) and should be more configurable.

Download:

If you are interested in getting this to work on your machine you will need to:

  • Download and install (to default location) Asp.Net MVC Preview 3 from here.
  • Download and install (to default location) the Pageflow sample from here.
  • Download and extract the source to this post (and open in VS2008) from here: MvcPageflow.zip (65.67 kb)

You will also need to have setup a persistence service SQL database (this page has a paragraph on how to do this) and update the connection string in WorkflowWizardController static constructor (I know this should be read from the web.config).

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , ,
Categories:   Coding
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed