Don't like ads? PRO users don't see any ads ;-)
Guest

CheckMailActivity

By: a guest on Jul 5th, 2012  |  syntax: C#  |  size: 3.17 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Activities;
  5. using EGR_Workflow_Helper;
  6.  
  7. namespace EGR_WorkflowLibrary
  8. {
  9.     public class CheckMailActivity : NativeActivity
  10.     {
  11.         public InArgument<String> InActivityClassName { get; set; }
  12.         public InArgument<string> InDeadLineName { get; set; }
  13.         public InArgument<int> InSwitchType { get; set; }
  14.         public InArgument<DateTime> InNewDeadline { get; set; }
  15.         public InArgument<int> InDaysToExtendDeadline { get; set; }
  16.         public InOutArgument<WorkflowContainer> WFContainer { get; set; }
  17.         public OutArgument<Boolean> OutMailReceived { get; set; }
  18.         public OutArgument<string> OutXMLID { get; set; }
  19.  
  20.         CheckMailItem _item;
  21.  
  22.         protected override void Execute(NativeActivityContext context)
  23.         {
  24.             try
  25.             {
  26.                 DateTime dueDate = new DateTime();
  27.                 IRequestItemHostNotification extension =
  28.                 context.GetExtension<IRequestItemHostNotification>();
  29.  
  30.                 {
  31.                     WorkflowContainer container = WFContainer.Get(context);
  32.                     List<Deadline> deadlines = (List<Deadline>)container.GetValue("Deadlines");
  33.                    
  34.                     // Create BookmarkName
  35.                     string _bookmarkName = context.WorkflowInstanceId + "." + InActivityClassName.Get(context) + "." + context.ActivityInstanceId;
  36.  
  37.                     //get deadline
  38.                     if (InNewDeadline.Get(context) != DateTime.MinValue)
  39.                     {
  40.                         dueDate = InNewDeadline.Get(context);
  41.                     }
  42.                     else
  43.                     {
  44.                         int st = InSwitchType.Get(context);
  45.                         string name = InDeadLineName.Get(context);
  46.  
  47.                         dueDate = ((List<Deadline>)container.GetValue("Deadlines")).
  48.                         Where(d => d.Designation == InDeadLineName.Get(context)).First().DueDate;
  49.                     }
  50.  
  51.                     dueDate = dueDate.AddDays(InDaysToExtendDeadline.Get(context));
  52.                     Console.WriteLine("CheckMail date: " + dueDate.ToShortDateString());
  53.                     _item = new CheckMailItem(dueDate, context.WorkflowInstanceId, _bookmarkName)
  54.                     {
  55.                         ProcessDocument = container.GetValue("ProcessDocument").ToString(),
  56.                     };
  57.  
  58.                     // Publish Workitem
  59.                     extension.Notify(_item);
  60.  
  61.                     // Publish Bookmark
  62.                     context.CreateBookmark(_bookmarkName, Resumed);
  63.                 }
  64.             }
  65.             catch (Exception ex)
  66.             {
  67.                 Console.WriteLine("CheckMailActivity.Execute error: " + ex);
  68.             }
  69.         }
  70.  
  71.         private void Resumed(NativeActivityContext context, Bookmark bookmark, object value)
  72.         {
  73.             OutMailReceived.Set(context, _item.MailReceived);
  74.             OutXMLID.Set(context, _item.XMLID);
  75.         }
  76.  
  77.         protected override bool CanInduceIdle
  78.         {
  79.             get { return true; }
  80.         }
  81.  
  82.     }
  83. }