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 dateToUse           = DateToUse.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);
            string   format = Format.Get(context);

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                dateToUse = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, localContext.OrganizationService);
            }

            string formattedDateString = dateToUse.ToString(format);

            FormattedDateString.Set(context, formattedDateString);
        }
        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 dateToUse           = DateToUse.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);
            string   culture             = Culture.Get(context);

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                dateToUse = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, localContext.OrganizationService);
            }

            string monthName = dateToUse.ToString("MMMM", CultureInfo.CreateSpecificCulture(culture));

            MonthName.Set(context, monthName);
        }
        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 dateToUse           = DateToUse.Get(executionContext);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(executionContext);

                if (evaluateAsUserLocal)
                {
                    GetLocalTime glt          = new GetLocalTime();
                    int?         timeZoneCode = glt.RetrieveTimeZoneCode(service);
                    dateToUse = glt.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, service);
                }

                int dayNumberOfWeek = ((int)dateToUse.DayOfWeek + 1);

                DayNumberOfWeek.Set(executionContext, dayNumberOfWeek);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
예제 #4
0
        //http://blogs.msdn.com/b/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx

        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 dateToUse           = DateToUse.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                dateToUse = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, localContext.OrganizationService);
            }

            DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
            Calendar           cal = dfi.Calendar;

            int weekNumberOfYear = cal.GetWeekOfYear(dateToUse, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);

            WeekNumberOfYear.Set(context, weekNumberOfYear);
        }
        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 dateToCheck         = DateToCheck.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);

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

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

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                dateToCheck = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToCheck, timeZoneCode, localContext.OrganizationService);
            }

            var result = dateToCheck.IsBusinessDay(calendar);

            ValidBusinessDay.Set(context, result);
        }
예제 #6
0
        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 dateToUse           = DateToUse.Get(executionContext);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(executionContext);

                if (evaluateAsUserLocal)
                {
                    GetLocalTime glt          = new GetLocalTime();
                    int?         timeZoneCode = glt.RetrieveTimeZoneCode(service);
                    dateToUse = glt.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, service);
                }

                int      quarterNumber    = (dateToUse.Month - 1) / 3 + 1;
                DateTime quarterStartDate = new DateTime(dateToUse.Year, (quarterNumber - 1) * 3 + 1, 1, 0, 0, 0);
                DateTime quarterEndDate   = quarterStartDate.AddMonths(3).AddDays(-1).AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999);

                QuarterStartDate.Set(executionContext, quarterStartDate);
                QuarterEndDate.Set(executionContext, quarterEndDate);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
        //http://blogs.msdn.com/b/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx

        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 dateToUse           = DateToUse.Get(executionContext);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(executionContext);

                if (evaluateAsUserLocal)
                {
                    GetLocalTime glt          = new GetLocalTime();
                    int?         timeZoneCode = glt.RetrieveTimeZoneCode(service);
                    dateToUse = glt.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, service);
                }

                DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
                Calendar           cal = dfi.Calendar;

                int weekNumberOfYear = cal.GetWeekOfYear(dateToUse, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);

                WeekNumberOfYear.Set(executionContext, weekNumberOfYear);
            }
            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));
            }

            try
            {
                DateTime dateToCheck         = DateToCheck.Get(context);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);

                if (evaluateAsUserLocal)
                {
                    int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                    dateToCheck = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToCheck, timeZoneCode, localContext.OrganizationService);
                }

                var result = dateToCheck.IsBusinessDay(localContext.OrganizationService, this.HolidayClosureCalendar.Get(context));

                this.ValidBusinessDay.Set(context, result);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(OperationStatus.Failed, $"{ex.Message}");
            }
        }
        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 dateToUse           = DateToUse.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                dateToUse = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, localContext.OrganizationService);
            }

            DateTime yearStartDate = new DateTime(dateToUse.Year, 1, 1, 0, 0, 0);
            DateTime yearEndDate   = yearStartDate.AddYears(1).AddDays(-1).AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999);

            YearStartDate.Set(context, yearStartDate);
            YearEndDate.Set(context, yearEndDate);
        }
예제 #10
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 firstDate           = FirstDate.Get(context);
            DateTime secondDate          = SecondDate.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                firstDate  = GetLocalTime.RetrieveLocalTimeFromUtcTime(firstDate, timeZoneCode, localContext.OrganizationService);
                secondDate = GetLocalTime.RetrieveLocalTimeFromUtcTime(secondDate, timeZoneCode, localContext.OrganizationService);
            }

            bool sameDay = firstDate.Date == secondDate.Date;

            SameDay.Set(context, sameDay);
        }
예제 #11
0
        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 firstDate           = FirstDate.Get(executionContext);
                DateTime secondDate          = SecondDate.Get(executionContext);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(executionContext);

                if (evaluateAsUserLocal)
                {
                    GetLocalTime glt          = new GetLocalTime();
                    int?         timeZoneCode = glt.RetrieveTimeZoneCode(service);
                    firstDate  = glt.RetrieveLocalTimeFromUtcTime(firstDate, timeZoneCode, service);
                    secondDate = glt.RetrieveLocalTimeFromUtcTime(secondDate, timeZoneCode, service);
                }

                bool sameDay = firstDate.Date == secondDate.Date;

                SameDay.Set(executionContext, sameDay);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
예제 #12
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 dateToUse           = DateToUse.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                dateToUse = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, localContext.OrganizationService);
            }

            int diff = dateToUse.DayOfWeek - DayOfWeek.Sunday;

            if (diff < 0)
            {
                diff += 7;
            }

            DateTime weekStartDate = dateToUse.AddDays(-1 * diff).Date;

            weekStartDate = new DateTime(weekStartDate.Year, weekStartDate.Month, weekStartDate.Day, 0, 0, 0);
            DateTime weekEndDate = weekStartDate.AddDays(6).AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999);

            WeekStartDate.Set(context, weekStartDate);
            WeekEndDate.Set(context, weekEndDate);
        }
        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 dateToUse           = DateToUse.Get(executionContext);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(executionContext);

                if (evaluateAsUserLocal)
                {
                    GetLocalTime glt          = new GetLocalTime();
                    int?         timeZoneCode = glt.RetrieveTimeZoneCode(service);
                    dateToUse = glt.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, service);
                }

                int diff = dateToUse.DayOfWeek - DayOfWeek.Sunday;
                if (diff < 0)
                {
                    diff += 7;
                }

                DateTime weekStartDate = dateToUse.AddDays(-1 * diff).Date;
                weekStartDate = new DateTime(weekStartDate.Year, weekStartDate.Month, weekStartDate.Day, 0, 0, 0);
                DateTime weekEndDate = weekStartDate.AddDays(6).AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999);

                WeekStartDate.Set(executionContext, weekStartDate);
                WeekEndDate.Set(executionContext, weekEndDate);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
예제 #14
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 dateToUse           = DateToUse.Get(context);
            bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(context);

            if (evaluateAsUserLocal)
            {
                int?timeZoneCode = GetLocalTime.RetrieveTimeZoneCode(localContext.OrganizationService);
                dateToUse = GetLocalTime.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, localContext.OrganizationService);
            }

            int minuteNumber = dateToUse.Minute;

            MinuteNumber.Set(context, minuteNumber);
        }
        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 dateToUse           = DateToUse.Get(executionContext);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(executionContext);
                string   cultureIn           = Culture.Get(executionContext);
                string   format = Format.Get(executionContext);

                CultureInfo culture = null;
                if (!string.IsNullOrEmpty(cultureIn))
                {
                    culture = new CultureInfo(cultureIn);
                }

                if (evaluateAsUserLocal)
                {
                    GetLocalTime glt          = new GetLocalTime();
                    int?         timeZoneCode = glt.RetrieveTimeZoneCode(service);
                    dateToUse = glt.RetrieveLocalTimeFromUtcTime(dateToUse, timeZoneCode, service);
                }

                string formattedDateString = dateToUse.ToString(format, culture);

                FormattedDateString.Set(executionContext, formattedDateString);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
예제 #16
0
        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 dateToCheck         = DateToCheck.Get(executionContext);
                bool     evaluateAsUserLocal = EvaluateAsUserLocal.Get(executionContext);

                if (evaluateAsUserLocal)
                {
                    GetLocalTime glt          = new GetLocalTime();
                    int?         timeZoneCode = glt.RetrieveTimeZoneCode(service);
                    dateToCheck = glt.RetrieveLocalTimeFromUtcTime(dateToCheck, timeZoneCode, service);
                }

                EntityReference holidaySchedule = HolidayClosureCalendar.Get(executionContext);

                bool validBusinessDay = dateToCheck.DayOfWeek != DayOfWeek.Saturday || dateToCheck.DayOfWeek == DayOfWeek.Sunday;

                if (!validBusinessDay)
                {
                    ValidBusinessDay.Set(executionContext, false);
                    return;
                }

                if (holidaySchedule != null)
                {
                    Entity calendar = service.Retrieve("calendar", holidaySchedule.Id, new ColumnSet(true));
                    if (calendar == null)
                    {
                        return;
                    }

                    EntityCollection calendarRules = calendar.GetAttributeValue <EntityCollection>("calendarrules");
                    foreach (Entity calendarRule in calendarRules.Entities)
                    {
                        //Date is not stored as UTC
                        DateTime startTime = calendarRule.GetAttributeValue <DateTime>("starttime");

                        //Not same date
                        if (!startTime.Date.Equals(dateToCheck.Date))
                        {
                            continue;
                        }

                        //Not full day event
                        if (startTime.Subtract(startTime.TimeOfDay) != startTime || calendarRule.GetAttributeValue <int>("duration") != 1440)
                        {
                            continue;
                        }

                        ValidBusinessDay.Set(executionContext, false);
                        return;
                    }
                }

                ValidBusinessDay.Set(executionContext, true);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }