protected override void Execute(CodeActivityContext context) { DateTime dateTimeInput = DateTimeVal.Get <DateTime>(context); int seconds = Seconds.Get <int>(context); DateTime calculatedDate = dateTimeInput.AddSeconds(seconds * -1); CalculatedValue.Set(context, calculatedDate); }
protected override void Execute(CodeActivityContext context) { Int32 day = Day.Get(context); Int32 month = Month.Get(context); Int32 year = Year.Get(context); Int32 hours = Hours.Get(context); Int32 minutes = Minutes.Get(context); Int32 seconds = Seconds.Get(context); Boolean IsLeapYear = DateTime.IsLeapYear(year); if (day < 1 || day > 31) { throw new System.ArgumentOutOfRangeException(nameof(day), "Day out of range (1 - 31"); } if (month < 1 || month > 12) { throw new System.ArgumentOutOfRangeException(nameof(month), "Month out of range (1 - 12)"); } if (hours < 0 || hours > 23) { throw new System.ArgumentOutOfRangeException(nameof(hours), "Hours out of range (0 - 23)"); } if (minutes < 0 || minutes > 59) { throw new System.ArgumentOutOfRangeException(nameof(minutes), "Minutes out of range (0 - 23)"); } if (seconds < 0 || seconds > 59) { throw new System.ArgumentOutOfRangeException(nameof(minutes), "Secondes out of range (0 - 23)"); } if ((month == 2 && day == 29) && !IsLeapYear) { throw new System.ArgumentOutOfRangeException(nameof(year), "year is not a leap year."); } Date.Set(context, new DateTime(year, month, day, hours, minutes, seconds)); }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (Seconds.Expression != null) { targetCommand.AddParameter("Seconds", Seconds.Get(context)); } if (Milliseconds.Expression != null) { targetCommand.AddParameter("Milliseconds", Milliseconds.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }