Execution status of a Workflow Instance

May 6, 2007

We can determine the Execution status of an workflow instance using the workflow definition.. Workflow definition of an workflow instance provice the current execution status. Base class Activity contain one field named - ExecutionStatus which is a member of ActivityExecutionStatus Enum. ActivityExecutionEnum contain following values -

  • Initialized
  • Cancelling
  • Closed
  • Executing
  • Faulting
  • Compensating

Example -

Console.WriteLine( "Workflow Execution status :{0} ", instance.GetWorkflowDefinition().ExecutionStatus.ToString());


Dehydration & Rehydration in WF

May 6, 2007

If we have a long running workflow tasks or have a  large number of workflow tasks executing , we can unload and store it in a temporary storage using Persistence services ships with Workflow Foundation.

Dehydration : Removing a workflow instance from execution status and storing it away for later recall is called Dehydration. Typically persistence services that comes with WF is used for this purpose, but you can write your own service to perform the same task.

Rehydration: When needed - the workflow instance is brought back from persistence service. The process of bringing it back into an execution status is known as Rehydration.

The main goal is to unload the long running tasks from memory and store then in temporary storage and retrieve it when its needed. And by this way - it’s possible to provide efficient memory utilization.


Explicit Interface Implementation using C# - Interface101

May 2, 2007

Inerface was introduced to revoke the drawbacks of multiple inheritance. Moreover providing support for explicit interface implementation is the most fascinating thing for a developer who thinks in OO way. Now you can implement multiple interfaces in a class and still there is no ambiguity gets introduced.Apart from that , Explicit interface implementation actually create the whole implementation of the interface private , that is , to access the member of a class that implement the interface explicitly , interface reference is needed which supports the so-called concepts named “Run-time Bindings” and introduces a higher level of Abstraction .

In this Code sample, I am going to start from the simple interface definition and take a step at a time to reach up to Explicit interface implementation so that everyone could be on the same page. By this time, you probably understand that in the rest of the Code Sample I am going to focus on following Agenda –

1. Defining Interface.
2. Explicit Implementation of the Interface .
3. Advantage of Explicit Interface ImplementationCode Sample :

public interface ISimpleCalculator{
int Add(int num1, int num2);
}
public interface ICalculator
{
double Add(double num1, double num2);
}
///
/// Benefits of Explicit Interface -
/// 1. Private Implementation
/// 2. Remove Ambiguity while Implementing Mutiple Interface
///
public class Calculator:ISimpleCalculator , ICalculator
{
#region ISimpleCalculator Members
int ISimpleCalculator.Add(int num1, int num2)
{
return num1 + num2;
}
#endregion
#region ICalculator Members
double ICalculator.Add(double num1, double num2)
{
return num1 + num2;
}
#endregion
}

classProgram
{
static void Main(string[] args)
{
// Example - 1 : Private Implementation
Calculator calc = new Calculator();
/// Uncomment the following line and try to run the program, You will get a compile time error. Becauause , Members
/// of the Calculator class is Explicitly implements two interfaces. To Access the members of the class , there is only
/// one way … that is - Access it through INTERFACE REFERENCE.
//calc.Add(); // Uncomment it to get the Compile time Error
ISimpleCalculator simpleCalc = calc;
int result = simpleCalc.Add(5, 10);
Console.WriteLine(”Using ISimpleCalculator : “);
Console.WriteLine(”5+10 = ” + result);
Console.WriteLine(”————————————–”);

// Example -2 : Explicit Implementation to remove Ambiguity
/// If you have a look at the ICalculator and ISimpleCalculator interfaces - both these interfaces has one common
/// funationality - Add and our Calcultor class implement both the Interface ,that is , Calculator class has to
/// implement the Add funtionality twice . So .. The Question is - whether it gonna create Ambiguty? That’s the beuty
/// of Explicit Implementaion of Interface that it not gonna Create any Ambiguity :) That’s the beauty of POLYMOPHIC
/// REFERENCE
double num1 = 3.2;
double num2 = 5.8;
ICalculator floatingNumberCalculator = calc;
Console.WriteLine(”Using ICalculator : “);
Console.WriteLine(num1 +”+”+num2+” = “+ floatingNumberCalculator.Add(num2 ,num1)) ;
Console.WriteLine(”————————————–”);
}
}

So the key Take-away from Explicit Interface Implementation is that -1. It make the whole implementation Abstract/Private . That is , you need the interface reference to access that implementation.
2. It allow you to implement multiple Interface and at the same time , does not introduce any ambiguity. So , the polymorphic reference or runtime binding can be implement very efficiently.

“Code 4 Fun and Keep it Stylish”
~Adil