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 startingDate = StartingDate.Get(context);
            DateTime endingDate   = EndingDate.Get(context);
            bool     showSeconds  = ShowSeconds.Get(context);

            TimeSpan diff = startingDate - endingDate;

            StringBuilder sb = new StringBuilder();

            sb.Append($"{diff.Days}d.");

            sb.Append($"{diff.Hours:00}h:");

            sb.Append($"{diff.Minutes:00}m");

            if (showSeconds)
            {
                sb.Append($":{diff.Seconds:00}s");
            }

            Difference.Set(context, sb.ToString());
        }
Example #2
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 startingDate = StartingDate.Get(context);
            DateTime endingDate   = EndingDate.Get(context);

            startingDate = new DateTime(startingDate.Year, startingDate.Month, startingDate.Day, startingDate.Hour,
                                        startingDate.Minute, startingDate.Second, startingDate.Kind);

            endingDate = new DateTime(endingDate.Year, endingDate.Month, endingDate.Day, endingDate.Hour,
                                      endingDate.Minute, endingDate.Second, endingDate.Kind);

            TimeSpan difference = startingDate - endingDate;

            int secondsDifference = Math.Abs(Convert.ToInt32(difference.TotalSeconds));

            SecondsDifference.Set(context, secondsDifference);
        }
Example #3
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                DateTime startingDate = StartingDate.Get(executionContext);
                DateTime endingDate   = EndingDate.Get(executionContext);

                startingDate = new DateTime(startingDate.Year, startingDate.Month, startingDate.Day, startingDate.Hour,
                                            startingDate.Minute, 0, startingDate.Kind);

                endingDate = new DateTime(endingDate.Year, endingDate.Month, endingDate.Day, endingDate.Hour,
                                          endingDate.Minute, 0, endingDate.Kind);

                TimeSpan difference = startingDate - endingDate;

                int minutesDifference = Math.Abs(Convert.ToInt32(difference.TotalMinutes));

                MinutesDifference.Set(executionContext, minutesDifference);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                DateTime startingDate   = StartingDate.Get(executionContext);
                DateTime dateToValidate = DateToValidate.Get(executionContext);
                DateTime endingDate     = EndingDate.Get(executionContext);

                var between = dateToValidate > startingDate && dateToValidate < endingDate;

                Between.Set(executionContext, between);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
        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 startingDate   = StartingDate.Get(context);
            DateTime dateToValidate = DateToValidate.Get(context);
            DateTime endingDate     = EndingDate.Get(context);

            var between = dateToValidate > startingDate && dateToValidate < endingDate;

            Between.Set(context, between);
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                DateTime startingDate = StartingDate.Get(executionContext);
                DateTime endingDate   = EndingDate.Get(executionContext);

                TimeSpan difference = startingDate - endingDate;

                int hoursDifference = Math.Abs(Convert.ToInt32(difference.TotalHours));

                HoursDifference.Set(executionContext, hoursDifference);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
        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 startingDate = StartingDate.Get(context);
            DateTime endingDate   = EndingDate.Get(context);

            TimeSpan difference = startingDate - endingDate;

            int hoursDifference = Math.Abs(Convert.ToInt32(difference.TotalHours));

            HoursDifference.Set(context, hoursDifference);
        }
Example #8
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));
            }

            var startDate = StartingDate.Get(context);

            startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, startDate.Hour, startDate.Minute, 0);
            var endDate = EndingDate.Get(context);

            endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, endDate.Hour, endDate.Minute, 0);

            if (startDate == endDate)
            {
                MinutesDifference.Set(context, 0);
                return;
            }

            Entity          calendar = null;
            EntityReference holidayClosureCalendar = HolidayClosureCalendar.Get(context);

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

            var businessMinutes = 0;

            if (endDate > startDate)
            {
                while (startDate < endDate)
                {
                    if (startDate.IsBusinessMinute(calendar))
                    {
                        businessMinutes++;
                    }

                    startDate = startDate.AddMinutes(1);
                }
            }
            else
            {
                while (startDate > endDate)
                {
                    if (startDate.IsBusinessMinute(calendar))
                    {
                        businessMinutes--;
                    }

                    startDate = startDate.AddMinutes(-1);
                }
            }

            MinutesDifference.Set(context, businessMinutes);
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                DateTime startingDate = StartingDate.Get(executionContext);
                DateTime endingDate   = EndingDate.Get(executionContext);

                DateTime fromDate;
                DateTime toDate;
                int      increment = 0;
                int[]    monthDay  = { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
                int      month;
                int      day;

                if (startingDate > endingDate)
                {
                    fromDate = endingDate;
                    toDate   = startingDate;
                }
                else
                {
                    fromDate = startingDate;
                    toDate   = endingDate;
                }

                if (fromDate.Day > toDate.Day)
                {
                    increment = monthDay[fromDate.Month - 1];
                }

                if (increment == -1)
                {
                    increment = DateTime.IsLeapYear(fromDate.Year) ? 29 : 28;
                }

                if (increment != 0)
                {
                    day       = (toDate.Day + increment) - fromDate.Day;
                    increment = 1;
                }
                else
                {
                    day = toDate.Day - fromDate.Day;
                }

                if ((fromDate.Month + increment) > toDate.Month)
                {
                    month     = (toDate.Month + 12) - (fromDate.Month + increment);
                    increment = 1;
                }
                else
                {
                    month     = (toDate.Month) - (fromDate.Month + increment);
                    increment = 0;
                }

                int year = toDate.Year - (fromDate.Year + increment);

                int monthsDifference = month + (year * 12);

                MonthsDifference.Set(executionContext, monthsDifference);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
        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 startingDate = StartingDate.Get(context);
            DateTime endingDate   = EndingDate.Get(context);

            DateTime fromDate;
            DateTime toDate;
            int      increment = 0;

            int[] monthDay = { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            int   month;
            int   day;

            if (startingDate > endingDate)
            {
                fromDate = endingDate;
                toDate   = startingDate;
            }
            else
            {
                fromDate = startingDate;
                toDate   = endingDate;
            }

            if (fromDate.Day > toDate.Day)
            {
                increment = monthDay[fromDate.Month - 1];
            }

            if (increment == -1)
            {
                increment = DateTime.IsLeapYear(fromDate.Year) ? 29 : 28;
            }

            if (increment != 0)
            {
                day       = toDate.Day + increment - fromDate.Day;
                increment = 1;
            }
            else
            {
                day = toDate.Day - fromDate.Day;
            }

            if (fromDate.Month + increment > toDate.Month)
            {
                month     = toDate.Month + 12 - (fromDate.Month + increment);
                increment = 1;
            }
            else
            {
                month     = toDate.Month - (fromDate.Month + increment);
                increment = 0;
            }

            int year = toDate.Year - (fromDate.Year + increment);

            int monthsDifference = month + year * 12;

            MonthsDifference.Set(context, monthsDifference);
        }
        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 startingDate = StartingDate.Get(context);
            DateTime endingDate   = EndingDate.Get(context);
            string   relativeTimeString;

            if (endingDate < startingDate)
            {
                relativeTimeString = "in the future";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            const int second = 1;
            const int minute = 60 * second;
            const int hour   = 60 * minute;
            const int day    = 24 * hour;
            const int month  = 30 * day;

            var    ts    = new TimeSpan(endingDate.Ticks - startingDate.Ticks);
            double delta = Math.Abs(ts.TotalSeconds);

            if (delta < 1 * minute)
            {
                relativeTimeString = ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            if (delta < 2 * minute)
            {
                relativeTimeString = "a minute ago";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            if (delta < 45 * minute)
            {
                relativeTimeString = ts.Minutes + " minutes ago";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            if (delta < 90 * minute)
            {
                relativeTimeString = "an hour ago";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            if (delta < 24 * hour)
            {
                relativeTimeString = ts.Hours + " hours ago";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            if (delta < 48 * hour)
            {
                relativeTimeString = "yesterday";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            if (delta < 30 * day)
            {
                relativeTimeString = ts.Days + " days ago";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            if (delta < 12 * month)
            {
                int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
                relativeTimeString = months <= 1 ? "one month ago" : months + " months ago";
                RelativeTimeString.Set(context, relativeTimeString);
                return;
            }

            int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));

            relativeTimeString = years <= 1 ? "one year ago" : years + " years ago";
            RelativeTimeString.Set(context, relativeTimeString);
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                DateTime startingDate = StartingDate.Get(executionContext);
                DateTime endingDate   = EndingDate.Get(executionContext);
                string   relativeTimeString;

                if (endingDate < startingDate)
                {
                    relativeTimeString = "in the future";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                const int second = 1;
                const int minute = 60 * second;
                const int hour   = 60 * minute;
                const int day    = 24 * hour;
                const int month  = 30 * day;

                var    ts    = new TimeSpan(endingDate.Ticks - startingDate.Ticks);
                double delta = Math.Abs(ts.TotalSeconds);

                if (delta < 1 * minute)
                {
                    relativeTimeString = ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                if (delta < 2 * minute)
                {
                    relativeTimeString = "a minute ago";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                if (delta < 45 * minute)
                {
                    relativeTimeString = ts.Minutes + " minutes ago";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                if (delta < 90 * minute)
                {
                    relativeTimeString = "an hour ago";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                if (delta < 24 * hour)
                {
                    relativeTimeString = ts.Hours + " hours ago";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                if (delta < 48 * hour)
                {
                    relativeTimeString = "yesterday";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                if (delta < 30 * day)
                {
                    relativeTimeString = ts.Days + " days ago";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                if (delta < 12 * month)
                {
                    int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
                    relativeTimeString = months <= 1 ? "one month ago" : months + " months ago";
                    RelativeTimeString.Set(executionContext, relativeTimeString);
                    return;
                }

                int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));
                relativeTimeString = years <= 1 ? "one year ago" : years + " years ago";
                RelativeTimeString.Set(executionContext, relativeTimeString);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }