Archive for dotNet

AnkhSVN Visual Studio 2005 Install

Install
-Download AnkhSVN (e.g. AnkhSVN 2.0.5250) from CollabNet download page at http://ankhsvn.open.collab.net/servlets/ProjectProcess?pageID=3794.
-Install by double clicking and accept all default options.
-Start VS2005
-Set current source control plug-in to AnkhSVN: Tools -> Options -> Source Control.

Browse Repository
-Start VS2005
-Open Repository Explorer (View -> Repository Explorer)
-Click the second icon under the Repository Explorer tab (a globe with a plus sign to the upper right) to add a new URL to repository
-Enter your SVN repository URL (e.g. svn://localhost/trunk/myproject)

Check Out A Directory
-Open Repository Explorer (View -> Repository Explorer)
-Highlight the directory to be checked out
-Click the first icon under the Repository Explorer tab (red heart icon with a green check mark to the lower right)
-Enter the destination folder to check out or accept the default location
-Select the revision to check out. Default to Head which is the most current revision.

Open A VS Solution
-Open a VS solution as usual. If the solution folder is checked out from SVN and AnkhSVN is set as current source control plug-in, you should see SVN icons replacing the usual Windows Explorer icons under the Solution Explorer.
-Right click entries under Solution Explorer (solution, project, file. etc.), a SVN context menu will be available for various SVN operations.

Dependency Injection (DI) or Inverion of Control (IoC)

DI Frameworks 

Overview

  • Loose coupling
  • Built on factory patterns
  • Work through interfaces 

References

Windows Workflow Foundation (WWF)

Requirement

  1. Visual Studio 2005 Version 8.0.50727.42 
  2. .Net Framework 3.0 or above
  3. Visual Studio extensions for workflow (file: Visual Studio 2005 Extensions for Windows Workflow Foundation (EN).exe): http://www.microsoft.com/downloads/details.aspx?familyid=5D61409E-1FA3-48CF-8023-E8F38E709BA6&displaylang=en

Workflow Types

  • Sequential workflow
    • Good for business process
    • Not so good for user interaction
  • State machinen workflow
    • Good for lots of user interactions
  • Rule driven workflow, based on sequential workflow
    • More complicate and costly

Two types of activities

  • Composite activities
    • Contains other activities, e.g. sequential acitivities
  • Basic activities
    • Does the actual work 

System.Workflow.Runtime.WorkFlowRuntime object

  • Properties
    • IsStarted
  • Methods
    • AddService
    • CreateWorkflow
    • StartRuntime
    • StopRuntime
  • Events
    • Started
    • Stopped
    • WorkflowCompleted
    • WorkflowIdled
    • WorkflowTerminated

WorkflowInstance object

  • Properties
    • InstanceId
    • WorkflowRuntime
  • Methods
    • ApplyWorkflowChanges
    • GetWorkflowDefinition
    • Resume
    • Start
    • Suspend
    • Terminate: instance.Terminate("User cancellation.");
  • Events
  • Status: workflowInstance.GetWorkflowDefinition().ExecutionStatus.ToString();

Activity object

  • Properties
    • Description
    • Enabled
    • ExecutionResult
    • ExecutionStatus
    • ActivityExecutionStatus
    • Name
    • Parent
    • WorkflowInstanceId
  • Methods (they are all protected virtual methods)
    • Cancel
    • Clone
    • Execute
    • GetActivityByName
    • Load
    • RaiseEvent
    • RaiseGenericEvent<T>
    • Save
  • Events 

ActivityExecutionContext class

  • Created by workflow runtime
  • Provide info about workflow instance
    • Initialization
    • Timers
    • General execution flow

Sequence Activity Object

  • Is a composite activity 

Code Activity

Throw/FaultHandler Activities

  • Each FaultHandler is designed to handle one, and only one, exception type.

Suspend Activity

Terminate Activity

  • Difference from workflow termination by unhandled exception
    • WorkflowTerminatedEventArgs.Exception is of the type System.Workflow. ComponentModel.WorkflowTerminatedException

Workflow interprocess communication

  • WF uses an abstraction layer to buffer workflow from host
    • Local communication service
    • Need to add ExternalDataService to workflow runtime?
  • Create a workflow data communicaiton interface
  • Annotate with [ExternalDataExchange] (marker interface for local communication service)

    public interface IMVDataService
    {
    [ExternalDataExchange]
    void MVDataUpdate (DataSet mvData);
    }
  • Create a workflow data event argument class

    [Serializable]
    public class MVDataAvailableArgs : ExternalDataEventArgs
    {
    public MVDataAvailableArgs(Guid instanceId)
    : base(instanceId)
    {
    }
    }

Pluggable services

  • Additonal software functions that your workflow can use to complete their tasks
  • Some are optional and some are required
  • They are pluggable
  • Base workflow services
    • WorkflowPersistenceService
    • WorkflowQueuingService
    • WorkflowRuntimeService
    • WorkflowSchedulerService
      • DefaultWorkflowSchedulerService
      • ManualWorkflowSchedulerService
    • WorkflowSubscriptionService
    • WorkflowTransactionService
    • TrackingService
      • SqlTrackingService
        • Can use Workflowmonitor to query
        • Tracking specification objects
        • Tracking retrieval objects
          • Example 
            • SqlTrackingQuery
          • Activity events
            • ActivityTrackingPoint
            • ActivityTrackingLocation
          • Workflow events
          • User events
        • Tracking records are decorated with annotations
        • Tracking level determined in tracking profile
          • XML doc
      • ConsoleTrackingService
      • SimpleFileTrackingService

Pass Dictionary object as a parameter to workflow instance

  • In the activity class

    public sealed partial class Workflow1: SequentialWorkflowActivity
    {
    private Int32 _delay = 10;public Workflow1()
    {
    InitializeComponent();
    }// Receives value from parameter
    public Int32 Delay
    {
    get { return _delay; }
    set
    {
    if (value < 0 || value > 120)
    {
    value = 10;
    }
    if (ExecutionStatus == ActivityExecutionStatus.Initialized)
    {
    _delay = value;
    delayActivity1.TimeoutDuration = new TimeSpan(0, 0, _delay);
    }
    }
    }private void PreDelayMessage(object sender, EventArgs e)
    {
    MessageBox.Show("Pre-delay code is being executed.");
    }private void PostDelayMessage(object sender, EventArgs e)
    {
    MessageBox.Show("Post-delay code is being executed.");
    }
    }
  • In the main program

    class Program
    {
    private static AutoResetEvent _waitHandle = new AutoResetEvent(false);
    static void Main(string[] args)
    {
    WorkflowRuntime wfr = WorkflowFactory.GetWorkflowRuntime();
    wfr.WorkflowIdled +=
    new EventHandler(wfr_WorkflowIdled);
    wfr.WorkflowCompleted +=
    new EventHandler(wfr_WorkflowCompleted);
    wfr.WorkflowTerminated +=
    new EventHandler(wfr_WorkflowTerminated);Int32 delay = 0;
    string val = args.Length > 0 ? args[0] : "10";
    if (!Int32.TryParse(val, out delay))
    {
    Console.WriteLine("You must pass in an integer value.");
    return;
    }// Constructs a Dictionary object as workflow instance parameter
    Dictionary prms = new Dictionary();
    prms.Add("Delay", delay);Console.WriteLine("Waiting for workflow completion ({0} seconds).", val);WorkflowInstance wfi =
    // Pass the Dictionary object as parameter
    wfr.CreateWorkflow(typeof(LongRunningWorkflow.Workflow1), prms);
    wfi.Start();
    _waitHandle.WaitOne();
    Console.WriteLine("Done.");
    }
    static void wfr_WorkflowTerminated(object sender, WorkflowTerminatedEventArgs e)
    {
    Console.WriteLine("Workflow terminated.");
    _waitHandle.Set();
    }
    static void wfr_WorkflowIdled(object sender, WorkflowEventArgs e)
    {
    Console.WriteLine("Workflow idled.");
    }static void wfr_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
    {
    Console.WriteLine("Workflow completed.");
    _waitHandle.Set();
    }
    }

Downloading and installing Windows Workflow Foundation

  1. Download the following files from the links provided:
Note 

The dotnetfx3setup.exe file is necessary only if you’re using Windows XP or Windows Server 2003. If you’re using Windows Vista, the .NET Framework 3.0 runtime is already installed.

  1. Install the downloaded software packages in the following order:

    • Double-click the dotnetfx3setup.exe file to begin installation of the .NET Framework, version 3.0. Follow the on-screen wizard’s instructions to complete the installation. This installation application will download additional components from Microsoft at the time you install it and when complete will prompt you to download and install the latest related service packs and security updates.

    • Place the DVD you created with the Windows SDK into your DVD-ROM player and follow the provided installation instructions.

    • Double-click the vsextwfx.msi file to merge the installation files for the Visual Studio enhancements into Visual Studio. If you receive an error stating you don’t have the prerequisite software already installed, ignore the error and continue.

    • Execute Visual Studio 2005 Extensions for Windows Workflow Foundation (EN).exe to install the Windows Worflow Foundation components. Follow any on-screen instructions.