The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

October 2008 - Posts

One of the things launched at the PDC is Windows 7. A number of new features where mentioned but the one I find most intriguing is being able to boot of a virtual hard disk. I use VMWare quite a bit, in fact I do most of my development in virtual machines, but that always means running a copy of Windows inside of Windows. Now the host Windows is actually not doing all that much except host the virtual machine and, being Vista, eat a lot of resources in the process. So the ability to get rid of the host and just run the virtual machine seems like great feature.

Another interesting thing is that Microsoft seems to be pushing Windows 7 with the first beta starting real soon. My guess is they want Windows 7 to replace Windows MEsta (oops that should be Vista) as soon as possible.

Enjoy Windows MEsta in mean time.

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | with no comments
Filed under: ,

One of the intriguing things today at the second day of the PDC was the mention of SIlverlight outside the browser. There was no real statement about it but several references where made to it during the keynote. Now this opens some interesting possibilities! Lets hope there are some more announcements soon.

Enjoy.

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | with no comments
Filed under: ,

Windows Azure is the Microsoft awnser to the Google App Engine and Amazon EC2. Basically it is a platform in the cloud for developing web applications. It isn't just about hosting ASP.NET applications but also about services like SQL Server and SharePoint Server. You basically use Visual Studio and the languages like C# or VB ou already know. Development is local using a development server that mimincs the Azure network, just like Cassini mimicts IIS during development. And ofcouse Azul also contains workflow services Smile

Windows Azure is the development, hosting, and management environment of the Azure Services Platform, which enables you to run applications at Internet scale while leveraging the skills and tools you use today.

Windows Azure Tools for Microsoft Visual Studio extend Visual Studio to enable the creation, building, debugging, running, and packaging of scalable services on Windows Azure.

see http://blogs.msdn.com/cloud/ or http://www.azure.com for more details.

interseting stuff Smile

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | with no comments
Filed under: , , ,

Its that time again as I am just about to leave for the PDC Smile

 

Hope to see you all there!

 

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | with no comments
Filed under:

I have heard quite a few times that the ReplicatorActivity can only be use in parallel mode with a custom activity. The reason being that you need an extra property to store the current child data.

When the ReplicatorActivity works in sequential mode the following code works just fine:

private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
    int value = (int)replicatorActivity1.CurrentChildData[replicatorActivity1.CurrentIndex];
    Console.WriteLine("Loop value = {0}", value);
}

However when run in parallel the current index always point to the last item so this doesn't work. As an aside I think this is a bug as it results in hard to find errors. IMHO the ReplicatorActivity CurrentIndex should be -1 or some other value that would trigger either an IndexOutOfRangeException or an InvalidOperationException. Unfortunately that is not the case Sad.

Instead when we set the mode to parallel we need to use the ChildInitialized event to save the child data for that loop. So we need a place to store it.

Traditional thinking results in an extra property being added that is being scoped to the loop and an extra property means a custom activity to add it to.

But wait a minute doesn't every workflow foundation activity derive from DependencyObject and isn't that class all about using dependency properties?

Yes it is and that is exactly the reason you don't need a custom activity. In fact you can add as much extra data to any activity as you like!

 

How to add custom data to the standard activities

The trick is in using a DependencyProperty that is created using the DependencyProperty.RegisterAttached() function. This creates an attached property you can use to store data in activities that have no clue about the data. So the first step is to create a dependency property like this:

public static DependencyProperty LoopValueProperty = 
    DependencyProperty.RegisterAttached("LoopValue", typeof(int), typeof(Workflow1));

Now in the ChildInitialized event we van store the loop value in child activity like this:

private void replicatorActivity1_ChildInitialized(
    object sender, 
    ReplicatorChildEventArgs e)
{
    e.Activity.SetValue(LoopValueProperty, e.InstanceData);
}

Easy right Smile

So if I add a code activity as the child just to print the data all I need is the following code:

private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
    Activity activity = (Activity)sender;
    int value = (int)activity.GetValue(LoopValueProperty);
Console.WriteLine("The current value = {0}", value); }

A slightly larger example showing the parallel behavior

Below is a slightly more complex example showing this. I have added a DelayActivity with a random timeout just to show that the ReplicatorActivity is really running in parallel.

The workflow looks like this:

image

And when run this produces the following output:

image

The complete code behind file looks like this:

public sealed partial class Workflow1 : SequentialWorkflowActivity
{
    public Workflow1()
    {
        InitializeComponent();
    }

    public static DependencyProperty LoopValueProperty = 
        DependencyProperty.RegisterAttached("LoopValue", typeof(int), typeof(Workflow1));


    private void replicatorActivity1_Initialized(object sender, EventArgs e)
    {
        ReplicatorActivity replicator = (ReplicatorActivity)sender;
        replicator.InitialChildData = new List<int>(Enumerable.Range(1, 20));
    }

    private void delayActivity1_InitializeTimeoutDuration(object sender, EventArgs e)
    {
        DelayActivity delay = (DelayActivity)sender;
        Random random = new Random();
        delay.TimeoutDuration = TimeSpan.FromSeconds(random.Next(5));
    }

    private void replicatorActivity1_ChildInitialized(
        object sender, 
        ReplicatorChildEventArgs e)
    {
        e.Activity.SetValue(LoopValueProperty, e.InstanceData);
    }

    private void codeActivity1_ExecuteCode(object sender, EventArgs e)
    {
        Activity activity = (Activity)sender;
        int value = (int)activity.Parent.GetValue(LoopValueProperty);
Console
.WriteLine("The current value = {0}", value); } }

Enjoy!

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | 3 comment(s)
Filed under: , , ,

I am pretty excited about the news, a few weeks old by now, that Microsoft is going to include jQuery with ASP.NET. For those who do ASP.NET development and have never taken a look at jQuery: you really should do so as it is a great tool to use for client side scripting!

One of the cool things Microsoft is adding is Intellisense support, something that makes using jQuery a lot nicer!

But why wait until Microsoft release the updated jQuery file with the extra comments?

If you want Intellisense you can have it right now!

Yes that is right Mustafa already added the required comments and it makes using jQuery even better [:0]

You can download the jquery-1.2.6-intellisense.js from his blog at http://www.mustafaozcan.net/en/post/2008/06/15/JQuery-1-2-6-Intellisense-for-Visual-Studio-2008.aspx.

 

Enjoy jQuery

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | with no comments
Filed under: , ,

Last week during my Chalk & Talk session at the SDC one of the attendees was having problems with workflow persistence and collections of custom objects. Now I never got to see his code so I am not sure what the problem was but maybe this simple sample will convince him that this should work.

So we need a simple type, I decided to keep thing really simple and use the following:

using System;

namespace WorkflowConsoleApplication1
{
    [Serializable]
    public class Person
    {
        public string Name { get; set; }
    }
}

And we need a simple workflow like this. The two code activities print the contents of the collection and the delay activity is there to make sure everything is persisted to the database so I can stop and restart the application.

image

The code in the workflow is pretty simple as well Smile

using System;
using System.Collections.Generic;
using System.Workflow.Activities;

namespace WorkflowConsoleApplication1
{
    public sealed partial class Workflow1 : SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

        public List<Person> People { get; set; }

        private void printPeople_ExecuteCode(object sender, EventArgs e)
        {
            Console.WriteLine("The people in workflow {0} are:", WorkflowInstanceId);
            foreach (var person in People)
            {
                Console.WriteLine(person.Name);
            }
            Console.WriteLine();
        }
    }
}

And the code in the main program is simple to Smile. First we need to add the SqlWorkflowPersistenceService the runtime.

using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
    string connStr = @"Data Source=.\sqlexpress;Initial Catalog=WorkflowPersistence;Integrated Security=True";
    SqlWorkflowPersistenceService persistence = new SqlWorkflowPersistenceService(
        connStr, true, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(15));
    workflowRuntime.AddService(persistence);

 

and when we start the workflow we need to add the collection of people like this:

List<Person> people = new List<Person>();
people.Add(new Person() { Name = "Maurice de Beijer" });
people.Add(new Person() { Name = "John Doe" });
people.Add(new Person() { Name = "Arthur Dent" });

Dictionary<string, object> parms = new Dictionary<string, object>();
parms["People"] = people;

WorkflowInstance instance = workflowRuntime.CreateWorkflow(
    typeof(WorkflowConsoleApplication1.Workflow1), parms);
instance.Start();

 

Just to make sure we could see when a workflow was loaded from disk I added the following:

workflowRuntime.WorkflowLoaded += (s, e) =>
{
    Console.WriteLine("Workflow {0} was just reloaded", e.WorkflowInstance.InstanceId);
};

 

And the result is:

image

Just before this run I started the application and stopped it while the delayActivity was waiting so there was an extra record in the persistence database. During this run we can see the workflow being rehydrated and the collection of people being present. So everything works just as expected.

So pretty much the only thing that cab go wrong here is with the serialization. The workflow runtime uses the binary serializer sp all types need to be Serializable. And this includes all other types that are referenced somehow. And the somehow includes event handlers, something people tend to forget as this is not very visible as an object reference.

Hope this helps.

www.TheProblemSolver.nl
[f2}

Posted by Maurice | with no comments
Filed under: , , ,

Great new and a little unexpected so soon after the release of RC0.

See here: http://www.microsoft.com/presspass/press/2008/oct08/10-13Silverlight2PR.mspx for the full story. The download will be available tomorrow from http://www.microsoft.com/silverlight/.

Enjoy!

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | 1 comment(s)
Filed under: , , ,

The SDC conference we organized this year near Amsterdam was a great success with lots of good sessions from excellent speakers Smile. And the speakers seem to love being there as well even though we make them work for a living.

Don't believe me?

Well check out this picture of Miguel Castro who scored an amazingly high score on one of his sessions!

IMAGE_134

 

I guess he was completely exhausted after doing his session and slept through the lunch during the Holland tour. Or would that be from the bar afterwards Wink.

 

See you at the SDC next year!

 

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Posted by Maurice | with no comments
Filed under: , ,