//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 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 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()); } }
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()); } }
//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)); } 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); }
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()); } }
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()); } }