protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } DateTime dateToUpdate = DateToUpdate.Get(context); int hour = Hour.Get(context); if (hour > 23 || hour < 0) { throw new InvalidPluginExecutionException("Invalid hour"); } int minute = Minute.Get(context); if (minute > 59 || minute < 0) { throw new InvalidPluginExecutionException("Invalid minute"); } int second = Second.Get(context); if (second > 59 || second < 0) { throw new InvalidPluginExecutionException("Invalid second"); } DateTime updatedDate = new DateTime(dateToUpdate.Year, dateToUpdate.Month, dateToUpdate.Day, hour, minute, second); UpdatedDate.Set(context, updatedDate); }
protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } DateTime dateToUpdate = DateToUpdate.Get(context); string datePart = DatePart.Get(context); int newValue = NewValue.Get(context); string[] allowedParts = { "HR", "MIN", "SEC", "MON", "DAY", "YR" }; int pos = Array.IndexOf(allowedParts, datePart.ToUpper()); if (pos == -1) { throw new InvalidPluginExecutionException("Invalid date part - must be HR/MIN/SEC MON/DAY/YR"); } DateTime updatedDate = new DateTime(); switch (pos) { case 0: if (newValue > 23 || newValue < 0) { throw new InvalidPluginExecutionException("Invalid hour"); } updatedDate = UpdateDate(newValue, dateToUpdate.Minute, dateToUpdate.Second, dateToUpdate.Month, dateToUpdate.Day, dateToUpdate.Year); break; case 1: if (newValue > 59 || newValue < 0) { throw new InvalidPluginExecutionException("Invalid minute"); } updatedDate = UpdateDate(dateToUpdate.Hour, newValue, dateToUpdate.Second, dateToUpdate.Month, dateToUpdate.Day, dateToUpdate.Year); break; case 2: if (newValue > 59 || newValue < 0) { throw new InvalidPluginExecutionException("Invalid second"); } updatedDate = UpdateDate(dateToUpdate.Hour, dateToUpdate.Minute, newValue, dateToUpdate.Month, dateToUpdate.Day, dateToUpdate.Year); break; case 3: if (newValue < 1 || newValue > 12) { throw new InvalidPluginExecutionException("Invalid month"); } updatedDate = UpdateDate(dateToUpdate.Hour, dateToUpdate.Minute, dateToUpdate.Second, newValue, dateToUpdate.Day, dateToUpdate.Year); break; case 4: if (newValue > 31 || newValue < 0) { throw new InvalidPluginExecutionException("Invalid day"); } updatedDate = UpdateDate(dateToUpdate.Hour, dateToUpdate.Minute, dateToUpdate.Second, dateToUpdate.Month, newValue, dateToUpdate.Year); break; case 5: if (newValue > 9999 || newValue < 1900) { throw new InvalidPluginExecutionException("Invalid year"); } updatedDate = UpdateDate(dateToUpdate.Hour, dateToUpdate.Minute, dateToUpdate.Second, dateToUpdate.Month, dateToUpdate.Day, newValue); break; } UpdatedDate.Set(context, updatedDate); }