<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>WF</title>
        <link>http://geekswithblogs.net/cloud9/category/9043.aspx</link>
        <description>Windows Workflow Foundation</description>
        <language>en-US</language>
        <copyright>Juan Suero</copyright>
        <managingEditor>juan.suero@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>What a WF4.0 Workflow looks like in code</title>
            <link>http://geekswithblogs.net/cloud9/archive/2008/11/09/what-a-wf4.0-workflow-looks-like-in-code.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This code contains a sequential workflow running in a console application.&lt;/p&gt;
&lt;p&gt;There is a sequence and inside the sequence a QueryActions and ForeachLoop.&lt;/p&gt;
&lt;p&gt;The QueryActions Activity is a custom activity that you can create through Visual Studio add &amp;gt;&amp;gt; new &amp;gt;&amp;gt; .... etc... it gives you a design surface where you can drop standard out of the box activities.  In this case the QueryActions activity has inside of it a standard toolbox DBQuery activity which lets you point and click your way to a database select.  The QueryActions activity also takes some parameters it can supply to its DBQuery Acitivity.... Actions and DBConnectionContext.  The QueryActions activity outputs a List&amp;lt;Action&amp;gt;.  which is a generic list of Actions.  Actions is a Class manually created with XAML. &lt;/p&gt;
&lt;p&gt;Inside the QueryActions activity the DBQuery fills the List&amp;lt;Action&amp;gt;.  The List&amp;lt;Action&amp;gt; is then returned to the top level sequence activity and then the FOREACH activity is running iterating of the List&amp;lt;Action&amp;gt;.&lt;/p&gt;
&lt;p&gt;Inside the BODY of the FOREACH you can see other Activities being executed.  Namely CopyFile and DeleteAction activities.  The CopyFile Activity is another custom activity around a powershell commandlet activity that comes out of the box with WF4.0  The DeleteAction activity is a custom activity around DBQuery again.  This time executing a delete of records.&lt;/p&gt;
&lt;p&gt;The whole workflow does is take a list of file locations from the database, copies files from one location to another then deletes the records in the database.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;C#&lt;br /&gt;
namespace CustomActivities&lt;br /&gt;
{&lt;br /&gt;
    using System;&lt;br /&gt;
    using System.Linq;&lt;br /&gt;
    using System.Threading;&lt;br /&gt;
    using System.WorkflowModel;&lt;br /&gt;
    using System.WorkflowModel.Activities;&lt;br /&gt;
    using System.Collections.Generic;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {            &lt;br /&gt;
            AutoResetEvent syncEvent = new AutoResetEvent(false);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            Variable&amp;lt;DbConnectionContext&amp;gt; context = new Variable&amp;lt;DbConnectionContext&amp;gt; { Default = new DbConnectionContext("System.Data.SqlClient", "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=HOL_Lab2") };&lt;br /&gt;
            Variable&amp;lt;IList&amp;lt;Action&amp;gt;&amp;gt; actions = new Variable&amp;lt;IList&amp;lt;Action&amp;gt;&amp;gt; { Default = new List&amp;lt;Action&amp;gt;() };&lt;br /&gt;
            Variable&amp;lt;Action&amp;gt; action = new Variable&amp;lt;Action&amp;gt;();&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            var sequence = new Sequence&lt;br /&gt;
            {&lt;br /&gt;
                Variables = { context, actions },&lt;br /&gt;
                Activities =&lt;br /&gt;
                {&lt;br /&gt;
                    new QueryActions { Actions = actions, ConnectionContext = context },&lt;br /&gt;
                    new ForEach&amp;lt;Action&amp;gt; &lt;br /&gt;
                    {                        &lt;br /&gt;
                        Values = actions,&lt;br /&gt;
                        Body = new ActivityAction&amp;lt;Action&amp;gt;&lt;br /&gt;
                        {&lt;br /&gt;
                            Argument = action,&lt;br /&gt;
                            Handler = new Sequence&lt;br /&gt;
                            {&lt;br /&gt;
                                Activities = &lt;br /&gt;
                                {&lt;br /&gt;
                                    new CopyFile { Source = new InArgument &amp;lt;string&amp;gt;(e=&amp;gt;action.Get(e).SourceFile), Destination = new InArgument &amp;lt;string&amp;gt;(e=&amp;gt;action.Get(e).DestinationFile) },&lt;br /&gt;
                                    new DeleteAction { ConnectionContext = context, ActionId = new InArgument&amp;lt;int&amp;gt;(e=&amp;gt;action.Get(e).ActionId) }&lt;br /&gt;
                                }&lt;br /&gt;
                            }&lt;br /&gt;
                        }&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            };&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            WorkflowInstance myInstance = WorkflowInstance.Create(sequence);&lt;br /&gt;
            myInstance.Completed += delegate(object sender, WorkflowCompletedEventArgs e) { syncEvent.Set(); };&lt;br /&gt;
            myInstance.Aborted += delegate(object sender, WorkflowAbortedEventArgs e) { Console.WriteLine(e.Reason); syncEvent.Set(); };&lt;br /&gt;
            myInstance.Resume();&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            syncEvent.WaitOne();&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
Note: The program above creates a workflow containing a sequence. The sequence will execute firs the QueryActions activity that returns a list of actions. Foreach action the workflow will execute the CopyFile and DeleteAction activities.&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=126902"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=126902" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/cloud9/aggbug/126902.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Juan Suero</dc:creator>
            <guid>http://geekswithblogs.net/cloud9/archive/2008/11/09/what-a-wf4.0-workflow-looks-like-in-code.aspx</guid>
            <pubDate>Sun, 09 Nov 2008 14:44:10 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/cloud9/comments/126902.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/cloud9/archive/2008/11/09/what-a-wf4.0-workflow-looks-like-in-code.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/cloud9/comments/commentRss/126902.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>