David Paquette

CDD (Caffeine Driven Development)

  Home  |   Contact  |   Syndication    |   Login
  22 Posts | 0 Stories | 10 Comments | 0 Trackbacks

News

Article Categories

Archives

Post Categories

Windows Forms

Wednesday, November 23, 2011 #

I will be presenting ‘The Role of Workflow in Enterprise Software’ at the Edmonton .NET User Group on November 30th. The presentation will cover workflow concepts and Windows Workflow Foundation 4 (WF4).

More details and registration at www.edmug.net

See you all there!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, November 01, 2011 #

Windows Phone 7.5 represents a new and credible challenge in the smartphone space for both consumers and businesses to adopt with confidence. With strong predictions from some of the leading think tank organizations saying that Windows Phone will be number two in global market share by 2015 (behind Android), there has never been a better time for developers to start learning how to build apps for Windows Phone and understand how to be successful on the platform.

In this day-long workshop, we will begin by giving you a developer overview of the platform where you will learn how the Windows Phone app ecosystem works, how to build applications for the phone and how to create amazing user experiences with those apps. The second, larger part of the day will be dedicated to creating apps with a proctor available to help you. The intent is that the overview session will provide you with the fundamentals of how to build apps and then you can take those learnings and start building your own apps.

 

Date: 5-November-2011

Location: University of Calgary

Room: KNB 126 (Kinesiology Building), 2500 University Dr. NW, Calgary, AB

Registration: 8:30 am - 9:00 am

Presentation: 9:00 am – 4:00 pm


Click here to register for this event

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Monday, October 10, 2011 #

I will be presenting ‘The Role of Workflow in Enterprise Software’ at the Calgary .NET User Group on October 26th.  The presentation will cover workflow concepts, Windows Workflow Foundation 4 (WF4), and will also touch on Entity Framework Code First.

More details and registration at www.dotnetcalgary.com

See you all there!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Wednesday, June 08, 2011 #

Join us for HTML5 Fest with John Bristowe and others in Calgary on Wednesday, June 15th.  Event details and registration at www.dotnetcalgary.com

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Sunday, May 08, 2011 #

Lately, I have been taking some time to learn some new technologies.  For me, the best way to learn a new technology is to jump head first into a project:

Daily deal websites such as GroupOn, LivingSocial, DealFind, etc. have really taken off over the last 6 months.  With so many sites out there, my inbox was being flooded with emails from all these daily deal websites.  This seemed like it might be a fun project,  so I set out to build a daily deal aggregator.

First, I built a Windows Phone 7 app.  I built this app using Visual Studio 2010. Silverlight for WP7, the silverlight toolkit for WP7 and WCF.  Overall, I was pleased with the developer tools for Windows Phone 7 and I am looking forward to building more apps for WP7

ScreenShot5

The app conveniently presents deals for your city in a format very similar to the email client for Windows Phone 7.  Users can flag deals, share deals with friends, and buy deals from over 20 daily deal websites.  If you have a Windows Phone, you can download the Deal Groupie App here.

 

Next, I set out to learn some new web technologies.  I had recently attended a Microsoft Web Camp in Calgary (presented by Jonathan McCracken) and I was impressed with what I saw.  I decided to build a web version of Deal Groupie using ASP.NET MVC3.  I also made use of jQuery, jQuery UI, SQL Server CE 4 and WCF.  Since I had most of the backend already built, the web version did not take me nearly as long to build as the WP7 version did.  I spent more time tweaking the css than anything else.  The website provides daily deals for the selected city in 3 ways: a simple webpage listing all the active deals, a free daily email, and an RSS feed.  The RSS feed was exceptionally easy to implement using Syndication mechanism built in to WCF.

DealGroupieSite

Find deals in your city -- http://www.mydealgroupie.com/

Currently, Deal Groupie is finding more than 2000 deals per day in over 300 cities in the USA, Canada, UK, and Australia.

Overall, building the Deal Groupie app and website has been a really good learning experience.  What’s next?  I’m thinking of building an Android version of the app and adding some filtering options to the website.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Wednesday, March 16, 2011 #

James Kovacs will be presenting "What's New in NHibernate 3" in Calgary on March 22nd.

Register at www.dotnetcalgary.com

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, January 25, 2011 #

Web Camps are a free event where you can learn about building websites using ASP.NET MVC.  More info at www.webcamps.ms

Register now as space is limitted:
https://msevents.microsoft.com/cui/EventDetail.aspx?culture=en-CA&EventID=1032473173

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Thursday, January 13, 2011 #

James Kovacs will be presenting "What's New in NHibernate 3" in Calgary on January 18th. 

Register at www.dotnetcalgary.com

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, October 26, 2010 #

If you are like me, you may have been surprised when you read the MSDN documentation for System.Activities.Statements.Parallel.

A Parallel activity operates by simultaneously scheduling each Activity in its Branches collection at the start. It completes when all of its Branches complete or when its CompletionCondition property evaluates to true. While all the Activity objects run asynchronously, they do not execute on separate threads, so each successive activity only executes when the previously scheduled activity completes or goes idle. If none of the child activities of this activity go idle, this activity execute in the same way that a Sequence activity does.

-MSDN (http://msdn.microsoft.com/en-us/library/system.activities.statements.parallel.aspx)

While the name implies that each branch of activities would be executed on a separate thread, the Parallel activity does not execute activities on separate threads.  In fact, all activities in a workflow execute on the same thread.  This is very similar to how in Windows Forms and WPF, all code that manipulates the user interface must be executed on the UI thread.  You might be asking yourself:  What is the point of this parallel activity?

It is possible for some activity to execute work on a background thread.  When combined with the Parallel activity (or the ParallelForEach activity), this allows the workflow runtime to schedule other activities to be executed while it is waiting for the background thread to complete.  WF4 comes with a number of asynchronous activities that can be used in this way.  Some examples are the Delay, InvokeMethod (when RunAsynchronously is set to true).  If you are creating custom activities, you can also create activities that execute asynchronously.  If you are implementing a code-based activity, you can inherit from AsyncCodeActivity.  If you are implementing more complex activities that need to make use of the workflow runtime, there are a couple strategies for implementing asynchronous activities.  One option is to use the parallel extensions introduced in .NET 4 (Workflow and Parallel Extensions).   Another option is to use bookmarks.

However, if you want to compose a workflow in XAML and have that workflow executed in parallel, your options are more limited.  Here’s an example:

image

In this example, I would like the 2 workflows to execute on a separate thread.  The output, however, shows that both activities are executed on the same thread:

image

Luckily, there is a way to accomplish this using a dynamic activity to execute a child activity on a background thread.  The child activity can be any activity (including Sequence or FlowChart), so this allows us to execute any portion of a workflow on a background thread. 

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Text;
   5: using System.Activities;
   6: using System.Threading.Tasks;
   7: using System.ComponentModel;
   8: using Microsoft.VisualBasic.Activities;
   9:  
  10: namespace ParallelActivities
  11: {
  12:     [Designer(typeof(AsyncActivityWrapperDesigner))]
  13:     public class AsyncActivityWrapper : AsyncCodeActivity
  14:     {
  15:         public AsyncActivityWrapper()
  16:         {
  17:             Body = new ActivityAction();
  18:         }
  19:  
  20:         [Browsable(false)]
  21:         public ActivityAction Body { get; set; }
  22:         
  23:         protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
  24:         {        
  25:              Activity activity = CreateDynamicActivity(context);
  26:             IDictionary<string,object> inputs = GetArgumentsAndVariables(context);
  27:             Task task = Task.Factory.StartNew((ignore) =>
  28:             {
  29:                 WorkflowInvoker.Invoke(activity, inputs);
  30:                 
  31:             }, state);
  32:             task.ContinueWith((t) => callback(t));
  33:             return task;
  34:         }
  35:  
  36:         protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
  37:         {            
  38:         }
  39:  
  40:         private Activity CreateDynamicActivity(AsyncCodeActivityContext context)
  41:         {
  42:             DynamicActivity result = new DynamicActivity();
  43:             //Create a DynamicActivityProperty for each argument / variable in the current context
  44:             foreach (PropertyDescriptor property in context.DataContext.GetProperties())
  45:             {
  46:                 DynamicActivityProperty dynamicActivityProperty = new DynamicActivityProperty();
  47:  
  48:                 dynamicActivityProperty.Name = property.Name;
  49:                 dynamicActivityProperty.Type = typeof(InArgument<>).MakeGenericType(property.PropertyType);
  50:                 dynamicActivityProperty.Value = Activator.CreateInstance(dynamicActivityProperty.Type);
  51:                 result.Properties.Add(dynamicActivityProperty);
  52:             }
  53:  
  54:             //Copy impors to dynamic activity;
  55:             VisualBasic.SetSettings(result, VisualBasic.GetSettings(this));
  56:             result.Implementation = () => Body.Handler;
  57:             return result;
  58:         }
  59:  
  60:         private IDictionary<string, object> GetArgumentsAndVariables(AsyncCodeActivityContext context)
  61:         {
  62:             IDictionary<string, object> result = new Dictionary<string, object>();
  63:  
  64:             foreach (PropertyDescriptor property in context.DataContext.GetProperties())
  65:             {
  66:                 result.Add(property.Name, property.GetValue(context.DataContext));
  67:             }
  68:  
  69:             return result;
  70:         }
  71:     }
  72: }

Using the AsyncActivityWrapper inside a Parallel activity accomplishes the desired behavior by executing activities inside the AsyncActivityWrapper as shown here:

image

With the AsyncActivityWrapper, we can see that each branch of the Parallel activity is executed on a separate thread:

image

The designer for this activity is actually very simple.  It contains a single WorkfowItemPresenter which allows us to drag and drop an activity into the AsyncActivityWrapper.

   1: <sap:ActivityDesigner x:Class="ParallelActivities.AsyncActivityWrapperDesigner"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
   5:     xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
   6:  
   7:     <sap:WorkflowItemPresenter Margin="7" Item="{Binding Path=ModelItem.Body.Handler, Mode=TwoWay}" HintText="Drop Activity"/>
   8:  
   9: </sap:ActivityDesigner>

 

In conclusion, the AsyncActivityWrapper can be used to execute portions of a workflow on a separate thread.  When combined with the Parallel or ParallelForEach activities, this allows us to execute multiple activities in parallel.  In situations where a workflow is processing a large amount of data, or doing a large number of complex calculations, the AsyncActivityWrapper can help to improve performance.  The implementation provided here does have some limitations.  As with any parallel programming, you need to make sure that activities that are executing in parallel do not conflict with each other.  If the activities are trying to access and manipulate the same data, you might run into problems.  If the activities have a return value, you may need an alternate implementation of AsyncActivityWrapper that inherits from AsyncCodeActivity<TResult>.  Also, since each activity is being executed as a separate independant workflow, you will lose some workflow functionality such as Persistence and Tracking.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Monday, October 18, 2010 #

On October 19th, Craig Anderson, Jason Lepp and Mo Khan will be presenting “From MVP to MVVM: An Introduction to Model-View-ViewModel”.

Register at http://tiny.cc/flu0b

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati