<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">wf - on code</title>
  <icon>http://suhair.in/Content/icons/flame.ico</icon>
  <logo>http://suhair.in/Content/icons/flame.png</logo>
  <updated>2009-09-28T16:59:42</updated>
  <id>http://suhair.in/tags/wf/atom</id>
  <link rel="alternate" type="text/html" hreflang="en" href="/tags/wf/atom"/>
  <link rel="self" type="application/atom+xml" href="http://suhair.in/Tags/wf/ATOM"/>
  <generator uri="http://oxite.net" version="1.0">Oxite</generator>
  <entry>
    <title type="html">Sequential Workflow - Part 2</title>
    <link rel="alternate" type="text/html" href="http://suhair.in/Blog/sequential-workflow-part-2"/>
    <id>http://suhair.in/Blog/sequential-workflow-part-2</id>
    <updated>2009-09-28T11:29:29.82</updated>
    <published>2009-09-28T16:59:42</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="csharp" />
    <category term="wf" />
    <content type="html" xml:lang="en">
      &lt;pre class=&quot;prettyprint&quot;&gt;partial class ATMSimulator
{
      #region Designer generated code

      /// &lt;summary&gt; 
      /// Required method for Designer support - do not modify 
      /// the contents of this method with the code editor.
      /// &lt;/summary&gt;
      [System.Diagnostics.DebuggerNonUserCode]
      private void InitializeComponent()
      {
          this.CanModifyActivities = true;
          System.Workflow.Activities.CodeCondition codecondition1 = new System.Workflow.Activities.CodeCondition();
          this.DispatchAmount = new System.Workflow.Activities.CodeActivity();
          this.GatherAmountInput = new System.Workflow.Activities.CodeActivity();
          this.CashWithdrawalSequence = new System.Workflow.Activities.SequenceActivity();
          this.WhileUserNeedsATMService = new System.Workflow.Activities.WhileActivity();
          // 
          // DispatchAmount
          // 
          this.DispatchAmount.Name = &amp;quot;DispatchAmount&amp;quot;;
          this.DispatchAmount.ExecuteCode += new System.EventHandler(this.DispatchAmount_ExecuteCode);
          // 
          // GatherAmountInput
          // 
          this.GatherAmountInput.Name = &amp;quot;GatherAmountInput&amp;quot;;
          this.GatherAmountInput.ExecuteCode += new System.EventHandler(this.GatherAmountInput_ExecuteCode);
          // 
          // CashWithdrawalSequence
          // 
          this.CashWithdrawalSequence.Activities.Add(this.GatherAmountInput); &lt;span class=&quot;box nocode&quot;&gt;3&lt;/span&gt;
          this.CashWithdrawalSequence.Activities.Add(this.DispatchAmount);
          this.CashWithdrawalSequence.Name = &amp;quot;CashWithdrawalSequence&amp;quot;;
          // 
          // WhileUserNeedsATMService
          // 
          this.WhileUserNeedsATMService.Activities.Add(this.CashWithdrawalSequence);&lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt;
          codecondition1.Condition += new System.EventHandler&lt;system.workflow.activities.conditionaleventargs&gt;  ( his.CheckUserNeedsATMService);
          this.WhileUserNeedsATMService.Condition = codecondition1; &lt;span class=&quot;box nocode&quot;&gt;4&lt;/span&gt;
          this.WhileUserNeedsATMService.Name = &amp;quot;WhileUserNeedsATMService&amp;quot;;
          // 
          // ATMSimulator
          // 
          this.Activities.Add(this.WhileUserNeedsATMService);
          this.Name = &amp;quot;ATMSimulator&amp;quot;;
          this.CanModifyActivities = false;

      }

      #endregion

      private CodeActivity DispatchAmount;
      private SequenceActivity CashWithdrawalSequence;
      private WhileActivity WhileUserNeedsATMService; &lt;span class=&quot;box nocode&quot;&gt;1&lt;/span&gt;
      private CodeActivity GatherAmountInput;

}

&lt;/system.workflow.activities.conditionaleventargs&gt;&lt;/pre&gt;
&lt;p&gt;
	The major differnce from the Part 1 in this workflow is the inclusion of &lt;span class=&quot;inlinecode&quot;&gt;WhileActivity&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;1&lt;/span&gt; so that the user can make more than one transaction in one go. &lt;span class=&quot;inlinecode&quot;&gt;WhileActivity&lt;/span&gt; is a &lt;span class=&quot;inlinecode&quot;&gt;CompositeActivity&lt;/span&gt; so it can conatin other activities &lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt;.&amp;nbsp; Since &lt;span class=&quot;inlinecode&quot;&gt;WhileActivity&lt;/span&gt; can execute only single activity, the previous activities are packaged in to a single &lt;span class=&quot;inlinecode&quot;&gt;SequenceActivity&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;3&lt;/span&gt; and given to the &lt;span class=&quot;inlinecode&quot;&gt;WhileActivity&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt;. The &lt;span class=&quot;inlinecode&quot;&gt;Condition&lt;/span&gt; property of &lt;span class=&quot;inlinecode&quot;&gt;WhileActivity&lt;/span&gt;, which is set to an instance of &lt;span class=&quot;inlinecode&quot;&gt;CodeCondition&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;4&lt;/span&gt; in this code, determines whether the WhileActivity should proceed or halt.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;public sealed partial class ATMSimulator : SequentialWorkflowActivity
{
      private int amountToWithdraw = 0;
      private bool userNeedsService = true;

      public ATMSimulator()
      {
          InitializeComponent();
      }
      private void GatherAmountInput_ExecuteCode(object sender, EventArgs e) &lt;span class=&quot;box nocode&quot;&gt;1&lt;/span&gt;
      {
          Console.WriteLine(&amp;quot;please sepecify the amount to withdraw&amp;quot;);
          amountToWithdraw = int.Parse(Console.ReadLine());
      }

      private void DispatchAmount_ExecuteCode(object sender, EventArgs e) &lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt;
      {
          Console.WriteLine(String.Format(&amp;quot;Please collect {0:c} from the ATM&amp;quot;, amountToWithdraw));
          Console.WriteLine(&amp;quot;Enter Q to quit&amp;quot;);
          userNeedsService = !Console.ReadLine().Equals(&amp;quot;Q&amp;quot;, StringComparison.OrdinalIgnoreCase); &lt;span class=&quot;box nocode&quot;&gt;3&lt;/span&gt;
       }

      private void CheckUserNeedsATMService(object sender, ConditionalEventArgs e) &lt;span class=&quot;box nocode&quot;&gt;4&lt;/span&gt;
      {
          e.Result = userNeedsService; &lt;span class=&quot;box nocode&quot;&gt;5&lt;/span&gt;
      }


}

&lt;/pre&gt;
&lt;p&gt;
	The sequence activities are executed &lt;span class=&quot;box nocode&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt; in the first go and sets whether the user needs to do further transactions &lt;span class=&quot;box nocode&quot;&gt;3&lt;/span&gt;. Based on the user&amp;#39;s preference, &lt;span class=&quot;inlinecode&quot;&gt;CodeCondition&lt;/span&gt; event handler &lt;span class=&quot;box nocode&quot;&gt;4&lt;/span&gt; sets the &lt;span class=&quot;inlinecode&quot;&gt;Result&lt;/span&gt; to a boolean value to signal whether the while loop should halt or proceed &lt;span class=&quot;box nocode&quot;&gt;5&lt;/span&gt;.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">Sequential Workflow - Part 1</title>
    <link rel="alternate" type="text/html" href="http://suhair.in/Blog/sequential-workflow-part-1"/>
    <id>http://suhair.in/Blog/sequential-workflow-part-1</id>
    <updated>2009-09-28T12:32:21.18</updated>
    <published>2009-09-27T08:00:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="csharp" />
    <category term="wf" />
    <content type="html" xml:lang="en">
      &lt;pre class=&quot;prettyprint&quot;&gt;public sealed partial class ATMSimulator : SequentialWorkflowActivity &lt;span class=&quot;box nocode&quot;&gt;1&lt;/span&gt;
{
      private int amountToWithdraw = 0;
      public ATMSimulator()
      {
          InitializeComponent();
      }

      private void GatherAmountInput_ExecuteCode(object sender, EventArgs e)&lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt;
      {
          Console.WriteLine(&amp;quot;please sepecify the amount to withdraw&amp;quot;);
          amountToWithdraw = int.Parse(Console.ReadLine());
      }

      private void DispatchAmount_ExecuteCode(object sender, EventArgs e)&lt;span class=&quot;box nocode&quot;&gt;3&lt;/span&gt;
      {
          Console.WriteLine(String.Format(&amp;quot;Please collect {0:c} from the ATM&amp;quot;, amountToWithdraw));
      }

}
&lt;/pre&gt;
&lt;p&gt;
	Activities are the primary building blocks in Windows Workflow Foundation (WF) and the sequential workflow itself is an activity called &lt;span class=&quot;inlinecode&quot;&gt;SequentialWorkflowActivity&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;1&lt;/span&gt;. As the &lt;span class=&quot;inlinecode&quot;&gt;SequentialWorkflowActivity&lt;/span&gt; inherits from the &lt;span class=&quot;inlinecode&quot;&gt;CompositeActivity&lt;/span&gt;, it can execute the code in the child activities &lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;3&lt;/span&gt; in a forward-only direction.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;partial class ATMSimulator
{
      #region Designer generated code

      /// &lt;summary&gt; 
      /// Required method for Designer support - do not modify 
      /// the contents of this method with the code editor.
      /// &lt;/summary&gt;
      [System.Diagnostics.DebuggerNonUserCode]
      private void InitializeComponent()
      {
          this.CanModifyActivities = true;
          this.DispatchAmount = new System.Workflow.Activities.CodeActivity();
          this.GatherAmountInput = new System.Workflow.Activities.CodeActivity();
          // 
          // DispatchAmount
          // 
          this.DispatchAmount.Name = &amp;quot;DispatchAmount&amp;quot;;
          this.DispatchAmount.ExecuteCode += new System.EventHandler(this.DispatchAmount_ExecuteCode);
          // 
          // GatherAmountInput
          // 
          this.GatherAmountInput.Name = &amp;quot;GatherAmountInput&amp;quot;;
          this.GatherAmountInput.ExecuteCode += new System.EventHandler(this.GatherAmountInput_ExecuteCode);
          // 
          // ATMSimulator
          // 
          this.Activities.Add(this.GatherAmountInput);
          this.Activities.Add(this.DispatchAmount);
          this.Name = &amp;quot;ATMSimulator&amp;quot;;
          this.CanModifyActivities = false;

      }

      #endregion

      private CodeActivity DispatchAmount; &lt;span class=&quot;box nocode&quot;&gt;4&lt;/span&gt;
      private CodeActivity GatherAmountInput; &lt;span class=&quot;box nocode&quot;&gt;5&lt;/span&gt;

} 
&lt;/pre&gt;
&lt;p&gt;
	In the designer generated file of the simulator program there exists two code activities &lt;span class=&quot;box nocode&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;5&lt;/span&gt;. The primary goal of the code activities are to invoke the code-beside methods &lt;span class=&quot;box nocode&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;box nocode&quot;&gt;3&lt;/span&gt;. These methods will be used to examine and change the workflow instance states.&lt;/p&gt;
    </content>
  </entry>
</feed>
