Friday, July 10, 2009

More on Visual Studio Magazines demise

In the comments to my earlier post on the sad state of Visual Studio Magazine I responded to Matt Morollo VP of Publishing for the Redmond Group. I’d like to take the numbers quoted in my response and compare the current issue to the December 2008 issue, which was before the redesign of the magazine.

  Current Issue December 2008
Pages 32 40
Adverts 13 13
Meaningful articles* 0 3

* A meaningful article is defined as one that contains code samples or demonstrates a technology or language feature.

As you can see we’ve lost 8 pages, 3 articles and manages to keep the same number of advertisements.

At the end of the day the advertisers are the real losers here. The subscribers will seek out and find new sources of information either through print or on the internet while the advertisers who are footing the bill for the shiny anemic new look will not see much return in terms of revenue.

Silverlight 3 tools released

Silverlight 3 tools have been released. Unfortunately Blend 3 hasn’t been released to manufacturing yet. You can grab the bits at http://silverlight.net/GetStarted/

Tuesday, July 7, 2009

Windows Workflow Foundation 4.0 (Part 3 Activities)

On of the most visible areas of change in WF 4.0 is the out of the box activities. In this article we’ll take a look at the out of the box activities that are included in beta 1. The in the following articles we’ll begin to use these activities as well as custom activities to write a functional workflow that I’ll use to demonstrate some of the other features of WF 4.0.

Activities

  The out of the box activities are divided into five categories.

  • Procedural – These are the core workflow activities including activities such as the ForEach activity, While activity and a number of others described below.
  • Flowchart – As the name implies these are the core flowchart activities.
  • Messaging – These are the WCF workflow activities that include Send and Receive activities as well as several others.
  • Power Shell – These are a new set of activities for working with Windows Power Shell from WF.
  • Interop – There is only one activity in this category.

Activity

Description

Collection Management

AddToCollection<T>

Adds an Item to a Collection.

RemoveFromCollection<T>

Removes an Item from a Collection.

ClearCollection<T>

Clears a Collection, removing all items stored in it.

ExistsInCollection

Verifies if an Item exists in a Collection. If the item exists, its Result argument will yield True.

Control of Flow

If

The If activity selects a child activity for execution based on the value of a Boolean expression.

If the Boolean expression Condition yields True (and “Then” activity is configured), the “Then” activity is scheduled. If the expressions yields False (and “Else” activity is set), the “Else” expression is scheduled.

DoWhile

Executes its Body until the Condition evaluates to True. The Body will be executed at least once.

ForEach / ForEach<T>

ForEach activity contains a list of Values and a Body. At runtime, the list is iterated and the body is executed for each value in the list.

Pick

The Pick Activity provides event-based control flow modeling in WF. The only valid children for a Pick activity are PickBranches.

At the beginning of a Pick execution, all the Trigger activities from all its Branches are scheduled. When the first Trigger completes its corresponding Action activity is scheduled, and all other Trigger activities are canceled.

PickBranch

PickBranch represents a branch in a Pick. It consists of a Trigger and Action. PickBranch can only be added to a Pick activity.

Sequence

The Sequence activity allows for the execution of one or more Activities in order.

Switch<T>

Switch activity is similar to switch statement in C#. It contains an Expression and a set of Cases (each case has a key and an activity). After the expression is evaluated, the Switch activity looks for a Case with a key that matches the result of the expression and if found, it schedules the activity associated with that Case.

While

The While activity executes it's Body while a Boolean Condition is True.

Parallel Execution

Parallel

Parallel activity allows parallel execution of its children. It operates by scheduling each WorkflowElement in its Branches collection at the beginning of its execution.  It completes when all of its Branches complete or when its CompletionCondition property evaluates to true.

ParallelForEach /  ParallelForEach<T>

The ParallelForEach activity enumerates the elements of a collection(Values) and executes an Activity for each element of the collection, in a similar way than the ForEach activity does. The main difference is that the embedded statement is executed in a parallel fashion.

Just like the Parallel Activity, ParallelForEach has a CompletionCondition, so that the ParallelForEach activity could complete early if the evaluation of the CompletionCondition returns true. The CompletionCondition is evaluated after each iteration is completed.

Error Handling

TryCatch

TryCatch activity is similar to the try..catch construct in C#: all activities in the Try block are executed and if an exception occurs, it will schedule the Catch block that best matches that exception (if no matching catch is found, the workflow is aborted). All Catch blocks are contained in a collection called Catches.

TryCatch activity also has a Finally block that is executed after the Try (and any eventual Catch).

A note on unhandled exceptions:

TryCatch provides exception handling at the workflow level. When an unhandled exception is thrown, the workflow is aborted and therefore the Finally block won’t be executed. This behavior is consistent with C#.

Catch<T>

Represents one catch block to be used in a TryCatch activity. If an exception is thrown within a Try Element, the TryCatch will attempt to find a matching Catch element based on the type of the thrown exception.

Catch<T> can only be used inside a TryCatch activity

Throw

Throw activity throws an exception within a workflow. Throw activity has an Exception property that contains the exception that will be thrown at execution time.

Utilities

Assign

The Assign activity assigns the value of its Value argument to its To argument.

The types of both arguments must be compatible. This compatibility is verified at runtime.

Delay

Delay Activity, as its name suggests, will block the current workflow execution path for a Duration specified by user. After the duration expires, the workflow continues execution as expected. The duration of the delay is set using a TimeSpan.

InvokeMethod / InvokeMethod<T>

InvokeMethod is the activity that allows you to call an existing CLR instance or static method. To invoke a method all you need to do is provide the owner of the method (TargetType for static methods, TargetObject for instance methods), the MethodName, and its Parameters.

InvokeMethod supports the following method invocation scenarios:

· Public instance and static methods

· Parameter passing by value and by reference

· Support for parameter arrays

· Support for generic parameters

· Asynchronous method invocation

WriteLine

Writes text to the configured output console.

Writing beyond the System.Console

WriteLine has a TextWriter argument can be configured to write to different outputs. For example, we can configure the TextWriter property to send the text to an ASP.NET page. If the TextWriter is not set, it will be set by default to the System Console.

Advanced (Cancellation, Compensation, Transactions, and Persistence)

CancellationScope

The CancellationScope activity consists of two main parts, the Body and the CancelHandler. The body is the code path that normally executes. If the activity gets canceled, then the cancel handler is called.

CompensatableActivity

CompensableActivity is used to define a potentially long running activity with accompanying Compensation and Confirmation logic.

Compensation allows the user to specify corrective action to be taken on an activity based upon activity which occurs after the successful completion of the Body of the activity.

Compensate

Compensate is used to explicitly invoke the compensation handler of a CompensableActivity.

Confirm

Confirm is used to explicitly invoke the confirmation handler of a CompensableActivity.

Persist

Persists the workflow instance. Persistence will be done using the configuration of the WorkflowInstance that is being executed (this activity doesn’t have any arguments).

TransactionScopeActivity

The TransactionScopeActivity provides the mechanism for initializing a new transaction, making the transaction handle ambient (a workflow execution property) and calling complete on the transaction once the Body of the TransactionScope activity has completed.

TransactionScopeActivity supports “Requires” semantics. If there is already an ambient transaction it is used, else a new one is created.

Nested transaction scopes:

TransactionScopeActivity can be nested in another TransactionScopeActivity. A TransactionScopeActivity nested in another TransactionScopeActivity will use the existing transaction.

Flowchart

Activity

Description

Flowchart

This is the root for a Flowchart. Since Flowchart is an activity like any other, it can be composed inside any container activity.

For example, we can add a Flowchart inside of a Sequence or a Flowchart inside another Flowchart.

The green ball in the image at the right represents the start node of the Flowchart.

FlowDecision

FlowDecision models conditional forks within a Flowchart. It can be seen as the equivalent of the procedural If activity in the Flowchart world.

This activity contains a Boolean expression Condition. If the expression evaluates to “True”, the true path is executed (otherwise, the false path is scheduled).

FlowSwitch

FlowSwitch activity selects a next node depending on the value of an expression. FlowSwitch can be seen as the equivalent of the procedural Switch activity in the Flowchart world.

Messaging

Activity

Description

Receive

Models one way receive of a message. It can receive data of the following types: Message, DataContract types, XmlSerializable types, and MessageContracts.

ReceiveAndSendReply

This activity template represents a correlated Receive activity and SendReply activity.

By using this template you can wait for an incoming message and then send a reply to the sender.

Since the Receive and the SendReply are inside a sequence, you can add any activity between them.

Send

Models one way send of a message. It can receive data of the following types: Message, DataContract types, XmlSerializable types, and MessageContracts.

This activity can be used in two ways:

1. Client: this activity can be used to send a request to a service. This is equivalent to a WCF client calling a service operation. No contract inference is performed on the client side.

2. On the server side the Send activity can be used to send a reply to a previous Receive. In this case the Send and Receive activities must have the same OperationName, Action and CorrelationHandle.

SendAndReceiveReply

This activity template represents a correlated Send activity and ReceiveReply activity.

By using this template you can send a message and then wait for a reply from the destination.

Since the Send and the ReceiveReply activities are inside a sequence, you can add any activity between them.

PowerShell

Activity

Description

InvokePowerShell

Invokes a PowerShell cmdlet that does not have a return value. InvokePowerShell can be used to invoke simple cmdlets and scripts. We can also pass parameters and input objects to the cmdlet. After execution, the activity provides a set of errors (if any occurred).

InvokePowerShell<T>

An activity that invokes and retrieves the resultant output from a PowerShell cmdlet. This flavor of the activity has all the same arguments than the non-generic version plus an InitializationAction.

The InitializationAction is used to map the results of the execution of the cmdlet to variables in our workflows.

Migration

Activity

Description

Interop

The Interop activity is a WF4 activity that wraps a WF3 activity (a non-abstract CLR type that derives from System.Workflow.ComponentModel.Activity) thus allowing the WF3 activity to be used in WF4 workflows.  Note that the WF3 activity can be a single leaf activity, or an entire compiled workflow (tree of activities).

The Interop activity bridges the WF4 and WF3 activity execution models, facilitates data flow across the interop boundary, and enables persistence and tracking of WF3 activity instances within WF4 workflow instances.

The Interop activity allows WF developers to move to the WF4 model in an incremental fashion:

· Quickly experiment with WF4 using existing WF3 activity artifacts

· Wrap WF3 activities the developer isn’t ready to redesign on the WF4 model

· Wrap WF3 activities for which the developer doesn’t own or possess the source code (e.g. they purchased the activity from a third party)

Overall this is quite an impressive list of activities when you consider the WF 3.5 came with a total of 30 out of the box activities. Missing are the event driven activities, code activity and web service activities to name a few.

Credits

  The descriptions in the beta documentation on MSDN are pretty weak. I was able to find  more complete descriptions on the .Net endpoint blog, which I’ve used because of the detail in descriptions.

Thursday, July 2, 2009

Visual Studio Magazine

Is now the number one most useless trade magazine published. It had been marginal at best up until it’s merger with Redmond Developer news, since the merger it has become utter garbage. The majority of the magazine is comprised of advertisements and very little in the way of articles. The commentary in articles is always that of a select group of perceived industry “heavy weights” who are in fact industry has-bens. These are the same people that crippled VB.Net from it’s inception and convinced hundreds of developers to stick with VB 6. Now the extol the virtues of the .Net framework and their pet technology in articles that are at best two pages long and absolutely worthless. All in an effort to keep relevant and sell you books and training.

If you’re considering a subscription to this magazine, do your self a favor and skip it.

Sunday, June 28, 2009

Windows Workflow Foundation 4.0 (Part 2 The Designer)

In part two of this series we’ll look at the project types available in Visual Studio 2010 and take look at the feature changes in the workflow designer.

Project Templates


There have been a number of changes in the available projects between WWF 3.5 and WWF 4.0. Below is a screen shot of the Visual Studio 2008 new Workflow project dialog.



As you can see in addition to the empty workflow project, there are several variations of the Sequential workflow and the State machine workflow. These variations include SharePoint 2007, library and console workflow applications. All of these workflows are built on designer functionality that has been available in Visual Studio since Visual Studio .Net was released in 2002.

The Visual Studio 2010 new Workflow project dialog contains a lot less clutter, some new project types and some that are missing. There may potentially be more project types available upon release, but for now we’ll concentrate on what’s available in beta 1. Below is a screen shot of the Visual Studio 2010 new Workflow project dialog.



The projects listed in the new project dialog are Activity Designer Library, Activity Library, Flowchart workflow console application and the Sequential workflow console application. All of the projects in the dialog are new for workflow with the exception of the Sequential workflow, missing is the State Machine workflow. All of the workflows in the WWF 4.0 are based on xaml or extensible markup language. This is the same technology that is used in WPF and Silverlight just to name a few.


Here is a quick overview of the project templates that are available in Visual Studio 2010.

The Activity Designer Library template provides a way to create a user interface for a custom or standard activity.

The Activity Library template provides a way to create custom activities visually.

The Sequential template creates a workflow that executes activities in sequence, one after another.

The Flowchart template creates a workflow that executes activities one after another, but allows the flow to return to an earlier step. This template replaces the State Machine workflow and is much more flexible.

Workflow Designers

There is a visual difference between the new Workflow designer and the Visual Studio 2008 designer. Below is the Visual Studio 2008 designer for a sequential workflow.


Below is the Visual Studio 2010 designer with a sequential workflow opened up.


The Visual Studio 2010 designer has some noticeable changes from the previous designer in that now, rather than creating variables and arguments in code, the designer now provides facilities for creating them from the designer.


When defining arguments from the argument window, you provide a name, type, default value and a direction. Valid directions are In, Out, In/Out and property. We’ll discuss these later after we discuss the available Out of the box activities and start to build a work flow.

Variables are much like arguments in definition except that instead of defining the direction we define the scope of the variable.

Navigation to activities and child activities is provided via bread crumbs. This was a feature of the State Machine workflows in WWF 3.5 that has carried over into WWF 4.0. The bread crumb navigation makes it easy to drill into the activities in a workflow to set the properties.

Overall the Workflow designer in Visual Studio 2010 is an evolution of the designer in Visual Studio 2008. Variable and Argument dialogs go a long way toward reducing the coding chores. And bread crumb navigation makes moving within activities and child activities a breeze. In the Next part we’ll look at the huge list of Out of the box activities.

Sunday, June 21, 2009

Windows Workflow Foundation 4.0 (Part 1)

Windows Workflow Foundation (WWF) has undergone a radical face lift in the .Net 4.0 framework. This face lift includes new out of the box activities, the designer, workflow types and persistence to name a few of the changes.

  WWF was first released as part of the .Net 3.0 framework and version 2 was released with the .Net 3.5 framework. While most successful among ISV’s (Independent Software Vendors), it hasn’t really taken hold with enterprise. WWF 4.0 is intended to change that and make a core part of every developers toolbox much like the way WCF has become the defacto communications technology in the .Net framework.

As with any beta release, documentation is nearly non existent. So with that in mind I’m going to break this down into a series of articles on WWF 4.0, learning what’s new and sharing my discoveries along the way.

Over the next several articles I intend to cover a lot of ground. I’ll spend time discovering and discussing the following topics

  • Designer changes – What’s new in the designer
  • Workflow types – New workflow types and what’s gone
  • Out of the Box Activities – New activities and what they provide
  • Custom Activities = How to create custom activities in WWF 4.0
  • Workflow Activation – Activating workflows from ASP.Net and Windows applications
  • Hosting – The new “Dublin” IIS hosting capabilities
  • Persistence – The WWF 4.0 persistence model