Ejemplo n.º 1
0
 public override int GetHashCode()
 {
     return(OriginalDate.GetHashCode() ^ 7
            * OriginalHomeName.GetHashCode() ^ 11
            * OriginalAwayName.GetHashCode() ^ 17
            * TipsterId.GetHashCode() ^ 19
            * PickId.GetHashCode() ^ 23
            * OriginalDiscipline.GetHashCode() ^ 29);
 }
        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        originalDate      = OriginalDate.Get(context);
            int             businessDaysToAdd = BusinessDaysToAdd.Get(context);
            EntityReference holidaySchedule   = HolidayClosureCalendar.Get(context);

            Entity calendar = null;

            if (holidaySchedule != null)
            {
                calendar = localContext.OrganizationService.Retrieve("calendar", holidaySchedule.Id, new ColumnSet(true));
            }

            DateTime tempDate = originalDate;

            if (businessDaysToAdd > 0)
            {
                while (businessDaysToAdd > 0)
                {
                    tempDate = tempDate.AddDays(1);

                    if (tempDate.IsBusinessDay(calendar))
                    {
                        // Only decrease the days to add if the day we've just added counts as a business day
                        businessDaysToAdd--;
                    }
                }
            }
            else if (businessDaysToAdd < 0)
            {
                while (businessDaysToAdd < 0)
                {
                    tempDate = tempDate.AddDays(-1);

                    if (tempDate.IsBusinessDay(calendar))
                    {
                        // Only increase the days to add if the day we've just added counts as a business day
                        businessDaysToAdd++;
                    }
                }
            }

            DateTime updatedDate = tempDate;

            UpdatedDate.Set(context, updatedDate);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj is Date d)
            {
                return(OriginalDate.Equals(d.OriginalDate));
            }

            return(false);
        }
Ejemplo n.º 4
0
        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 originalDate = OriginalDate.Get(context);
            int      yearsToAdd   = YearsToAdd.Get(context);

            DateTime updatedDate = originalDate.AddYears(yearsToAdd);

            UpdatedDate.Set(context, updatedDate);
        }
Ejemplo n.º 5
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                DateTime originalDate = OriginalDate.Get(executionContext);
                int      hoursToAdd   = HoursToAdd.Get(executionContext);

                DateTime updatedDate = originalDate.AddHours(hoursToAdd);

                UpdatedDate.Set(executionContext, updatedDate);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
Ejemplo n.º 6
0
        /// <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());
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Converts the value of the current System.DateTime object to its equivalent string
 /// representation using the specified format and culture-specific format information.
 /// </summary>
 /// <param name="format">A standard or custom date and time format string..</param>
 /// <param name="provider">An object that supplies culture-specific formatting information.</param>
 /// <returns>
 /// A <see cref="System.String" /> representation of value of the current System.DateTime object as specified by format and provider.
 /// </returns>
 /// <exception cref="System.FormatException">
 /// The length of format is 1, and it is not one of the format specifier characters defined for System.Globalization.DateTimeFormatInfo. -or- format does not contain a valid custom format pattern.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// The date and time is outside the range of dates supported by the calendar used by provider.
 /// </exception>
 public string ToString(string format, IFormatProvider provider)
 {
     return(OriginalDate.ToString(format, provider));
 }
Ejemplo n.º 8
0
 public override int GetHashCode()
 {
     return(OriginalDate.GetHashCode());
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns a new System.DateTime that adds the specified number of days to the value
 ///     of this instance.
 /// </summary>
 /// <param name="day">A number of whole and fractional days. The value parameter can be negative or
 ///     positive.</param>
 /// <returns>
 /// An object whose value is the sum of the date and time represented by this instance
 /// and the number of days represented by value.
 /// </returns>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// The resulting System.DateTime is less than System.DateTime.MinValue or greater than System.DateTime.MaxValue.
 /// </exception>
 public Date AddDay(double day)
 {
     return(new Date(OriginalDate.AddDays(day), OriginalCalendar, ReferentialCalendar));
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Converts the value of the current System.DateTime object to its equivalent string
 ///     representation using the specified format and the formatting conventions of the
 ///     current culture.
 /// </summary>
 /// /// <returns>
 /// A <see cref="System.String" /> representation of value of the current System.DateTime object as specified by format and provider.
 /// </returns>
 /// <exception cref="System.FormatException">
 /// The length of format is 1, and it is not one of the format specifier characters defined for System.Globalization.DateTimeFormatInfo. -or- format does not contain a valid custom format pattern.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// The date and time is outside the range of dates supported by the calendar used by provider.
 /// </exception>
 public override string ToString()
 {
     return(OriginalDate.ToString("d"));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Converts the value of the current System.DateTime object to its equivalent string
 ///     representation using the specified format and culture-specific format information.
 /// </summary>
 /// <param name="format">A standard or custom date and time format string..</param>
 /// <returns>
 /// A <see cref="System.String" /> representation of value of the current System.DateTime object as specified by format and provider.
 /// </returns>
 /// <exception cref="System.FormatException">
 /// The length of format is 1, and it is not one of the format specifier characters defined for System.Globalization.DateTimeFormatInfo. -or- format does not contain a valid custom format pattern.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// The date and time is outside the range of dates supported by the calendar used by provider.
 /// </exception>
 public string ToString(string format)
 {
     return(OriginalDate.ToString(format));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Converts the value of the current System.DateTime object to its equivalent string
 ///     representation using the specified format and culture-specific format information.
 /// </summary>
 /// <param name="provider">An object that supplies culture-specific formatting information.</param>
 /// <returns>
 /// A <see cref="System.String" /> representation of value of the current System.DateTime object as specified by format and provider.
 /// </returns>
 /// <exception cref="System.FormatException">
 /// The length of format is 1, and it is not one of the format specifier characters defined for System.Globalization.DateTimeFormatInfo. -or- format does not contain a valid custom format pattern.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// The date and time is outside the range of dates supported by the calendar used by provider.
 /// </exception>
 public string ToString(IFormatProvider provider)
 {
     return(OriginalDate.ToString(provider));
 }