/// <summary> /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>. /// </summary> /// <returns> /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>. /// </returns> public override string ToString() { const string atomFormat = @"<?xml version=""1.0"" encoding=""utf-8""?> <feed xmlns=""http://www.w3.org/2005/Atom""> <title>{0}</title> <subtitle>{1}</subtitle> <link href=""{2}"" rel=""self"" /> <link href=""{3}"" /> <id>urn:uuid:{4}</id> <updated>{5}</updated> <author> <name>{6}</name> <email>{7}</email> </author> {8} </feed>"; return(string.Format(atomFormat, Title, SubTitle, LinkSelf, Link, Id, UpdatedDate.ToString("u"), AuthorName, AuthorName, RenderEntries(Entries))); }
/// <summary> /// Executes the workflow activity. /// </summary> /// <param name="executionContext">The execution context.</param> /// protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { DateTime originalDate = OriginalDate.Get(executionContext); int businessDaysToAdd = BusinessDaysToAdd.Get(executionContext); EntityReference holidaySchedule = HolidayClosureCalendar.Get(executionContext); Boolean ishighLevel = IsHighLevel.Get(executionContext); Int32 decreaseHours = DecreaseHours.Get(executionContext); Entity calendar = null; EntityCollection calendarRules = null; if (holidaySchedule != null) { calendar = service.Retrieve("calendar", holidaySchedule.Id, new ColumnSet(true)); if (calendar != null) { calendarRules = calendar.GetAttributeValue <EntityCollection>("calendarrules"); } } DateTime tempDate = originalDate; DateTime tempDateHours = originalDate; /* * * Test segment */ if (ishighLevel) { Int32 DecreaseHoursNegative = decreaseHours * -1; tempDateHours = tempDateHours.AddHours(DecreaseHoursNegative); if (tempDateHours.Day != tempDate.Day) { businessDaysToAdd = -1; tempDate = tempDate.AddHours(DecreaseHoursNegative); } } /****************/ if (businessDaysToAdd > 0) { while (businessDaysToAdd > 0) { tempDate = tempDate.AddDays(1); if (tempDate.DayOfWeek == DayOfWeek.Sunday || tempDate.DayOfWeek == DayOfWeek.Saturday) { continue; } if (calendar == null) { businessDaysToAdd--; continue; } bool isHoliday = false; foreach (Entity calendarRule in calendarRules.Entities) { DateTime startTime = calendarRule.GetAttributeValue <DateTime>("starttime"); //Not same date if (!startTime.Date.Equals(tempDate.Date)) { continue; } //Not full day event if (startTime.Subtract(startTime.TimeOfDay) != startTime || calendarRule.GetAttributeValue <int>("duration") != 1440) { continue; } isHoliday = true; break; } if (!isHoliday) { businessDaysToAdd--; } } } else if (businessDaysToAdd < 0) { while (businessDaysToAdd < 0) { tempDate = tempDate.AddDays(-1); if (tempDate.DayOfWeek == DayOfWeek.Sunday || tempDate.DayOfWeek == DayOfWeek.Saturday) { continue; } if (calendar == null) { businessDaysToAdd++; continue; } bool isHoliday = false; foreach (Entity calendarRule in calendarRules.Entities) { DateTime startTime = calendarRule.GetAttributeValue <DateTime>("starttime"); //Not same date if (!startTime.Date.Equals(tempDate.Date)) { continue; } //Not full day event if (startTime.Subtract(startTime.TimeOfDay) != startTime || calendarRule.GetAttributeValue <int>("duration") != 1440) { continue; } isHoliday = true; break; } if (!isHoliday) { businessDaysToAdd++; } } } DateTime updatedDate = tempDate; UpdatedDate.Set(executionContext, updatedDate); } catch (Exception ex) { tracer.Trace("Exception: {0}", ex.ToString()); } }