using System; using System.Activities; using System.ServiceModel; using System.Globalization; using System.Runtime.Serialization; using System.IO; using System.Text; using System.Net; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; namespace LucasWorkflowAssemblies { /// /// This class is used to calculate the date that is X business days from now. /// public sealed class CalculateDateByBusinessDays : CodeActivity { /// /// [Input("Number of business days")] /// This input takes the number of business days from today for which the date will be determined. /// [Input("Number of business days")] public InArgument NumBusinessDays { get; set; } /// /// [Output("Calculated date")] /// This output is the date calculated from the supplied business days value. /// [Output("Calculated date")] public OutArgument CalculatedDate { get; set; } /// /// Executes the workflow activity /// /// The execution context protected override void Execute(CodeActivityContext executionContext) { int newcount = 0; DateTime today = DateTime.Now; // give them an extra day to complete if it comes in 1 PM or later int adjustedBusinessDays = NumBusinessDays.Get(executionContext); if (today.Hour > 13) { adjustedBusinessDays++; } while (adjustedBusinessDays > 0) { newcount++; today = today.AddDays(1); if (!(today.DayOfWeek == DayOfWeek.Saturday) && !(today.DayOfWeek == DayOfWeek.Sunday)) { adjustedBusinessDays--; } } CalculatedDate.Set(executionContext, today); } } }