当前位置: 首页>>代码示例>>C#>>正文


C# IDateTimeHelper.ConvertToUserTime方法代码示例

本文整理汇总了C#中IDateTimeHelper.ConvertToUserTime方法的典型用法代码示例。如果您正苦于以下问题:C# IDateTimeHelper.ConvertToUserTime方法的具体用法?C# IDateTimeHelper.ConvertToUserTime怎么用?C# IDateTimeHelper.ConvertToUserTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDateTimeHelper的用法示例。


在下文中一共展示了IDateTimeHelper.ConvertToUserTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToScheduleTaskModel

        public static ScheduleTaskModel ToScheduleTaskModel(this ScheduleTask task, ILocalizationService localization, IDateTimeHelper dateTimeHelper, UrlHelper urlHelper)
        {
            var now = DateTime.UtcNow;

            TimeSpan? dueIn = null;
            if (task.NextRunUtc.HasValue)
            {
                dueIn = task.NextRunUtc.Value - now;
            }

            var nextRunPretty = "";
            bool isOverdue = false;
            if (dueIn.HasValue)
            {
                if (dueIn.Value.TotalSeconds > 0)
                {
                    nextRunPretty = dueIn.Value.Prettify();
                }
                else
                {
                    nextRunPretty = localization.GetResource("Common.Waiting") + "...";
                    isOverdue = true;
                }
            }

            var isRunning = task.IsRunning;
            var lastStartOn = task.LastStartUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastStartUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
            var lastEndOn = task.LastEndUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastEndUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
            var lastSuccessOn = task.LastSuccessUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastSuccessUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
            var nextRunOn = task.NextRunUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.NextRunUtc.Value, DateTimeKind.Utc) : (DateTime?)null;

            var model = new ScheduleTaskModel
            {
                Id = task.Id,
                Name = task.Name,
                CronExpression = task.CronExpression,
                CronDescription = CronExpression.GetFriendlyDescription(task.CronExpression),
                Enabled = task.Enabled,
                StopOnError = task.StopOnError,
                LastStart = lastStartOn,
                LastStartPretty = task.LastStartUtc.HasValue ? task.LastStartUtc.Value.RelativeFormat(true, "f") : "",
                LastEnd = lastEndOn,
                LastEndPretty = lastEndOn.HasValue ? lastEndOn.Value.ToString("G") : "",
                LastSuccess = lastSuccessOn,
                LastSuccessPretty = lastSuccessOn.HasValue ? lastSuccessOn.Value.ToString("G") : "",
                NextRun = nextRunOn,
                NextRunPretty = nextRunPretty,
                LastError = task.LastError.EmptyNull(),
                IsRunning = isRunning,
                CancelUrl = urlHelper.Action("CancelJob", "ScheduleTask", new { id = task.Id }),
                ExecuteUrl = urlHelper.Action("RunJob", "ScheduleTask", new { id = task.Id }),
                EditUrl = urlHelper.Action("Edit", "ScheduleTask", new { id = task.Id }),
                ProgressPercent = task.ProgressPercent,
                ProgressMessage = task.ProgressMessage,
                IsOverdue = isOverdue,
                Duration = ""
            };

            var span = TimeSpan.Zero;
            if (task.LastStartUtc.HasValue)
            {
                span = model.IsRunning ? now - task.LastStartUtc.Value : task.LastEndUtc.Value - task.LastStartUtc.Value;
                if (span > TimeSpan.Zero)
                {
                    model.Duration = span.ToString("g");
                }
            }

            return model;
        }
开发者ID:toannguyen241994,项目名称:SmartStoreNET,代码行数:70,代码来源:ScheduleTaskExtensions.cs


注:本文中的IDateTimeHelper.ConvertToUserTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。