Ejemplo n.º 1
0
 public RecurringJobManager(
     [NotNull] JobStorage storage,
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] ITimeZoneResolver timeZoneResolver)
     : this(storage, filterProvider, timeZoneResolver, () => DateTime.UtcNow)
 {
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RecurringJobScheduler"/> class
 /// with custom background job factory, state machine and clocks.
 /// </summary>
 /// <param name="factory">Factory that will be used to create background jobs.</param>
 /// <param name="pollingDelay">Delay before another polling attempt, when no jobs scheduled yet.</param>
 /// <param name="timeZoneResolver">Function that returns a time zone object by its identifier.</param>
 /// <exception cref="ArgumentNullException"><paramref name="factory"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="timeZoneResolver"/> is null.</exception>
 public RecurringJobScheduler(
     [NotNull] IBackgroundJobFactory factory,
     TimeSpan pollingDelay,
     [NotNull] ITimeZoneResolver timeZoneResolver)
     : this(factory, pollingDelay, timeZoneResolver, () => DateTime.UtcNow)
 {
 }
Ejemplo n.º 3
0
        public static RecurringJobEntity GetOrCreateRecurringJob(
            [NotNull] this IStorageConnection connection,
            [NotNull] string recurringJobId,
            [NotNull] ITimeZoneResolver timeZoneResolver,
            DateTime now)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (recurringJobId == null)
            {
                throw new ArgumentNullException(nameof(recurringJobId));
            }
            if (timeZoneResolver == null)
            {
                throw new ArgumentNullException(nameof(timeZoneResolver));
            }

            var recurringJob = connection.GetAllEntriesFromHash($"recurring-job:{recurringJobId}");

            if (recurringJob == null || recurringJob.Count == 0)
            {
                recurringJob = new Dictionary <string, string>();
            }

            return(new RecurringJobEntity(recurringJobId, recurringJob, timeZoneResolver, now));
        }
Ejemplo n.º 4
0
        public RecurringJobScheduler(
            [NotNull] IBackgroundJobFactory factory,
            TimeSpan pollingDelay,
            [NotNull] ITimeZoneResolver timeZoneResolver,
            [NotNull] Func <DateTime> nowFactory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (nowFactory == null)
            {
                throw new ArgumentNullException(nameof(nowFactory));
            }
            if (timeZoneResolver == null)
            {
                throw new ArgumentNullException(nameof(timeZoneResolver));
            }

            _factory          = factory;
            _nowFactory       = nowFactory;
            _timeZoneResolver = timeZoneResolver;
            _pollingDelay     = pollingDelay;
            _profiler         = new SlowLogProfiler(_logger);
        }
Ejemplo n.º 5
0
 public RecurringJobManager(
     [NotNull] JobStorage storage,
     [NotNull] IJobFilterProvider filterProvider,
     [NotNull] ITimeZoneResolver timeZoneResolver,
     [NotNull] Func <DateTime> nowFactory)
     : this(storage, new BackgroundJobFactory(filterProvider), timeZoneResolver, nowFactory)
 {
 }
Ejemplo n.º 6
0
 public CommentController(
     IMediator mediator,
     IBlogConfig blogConfig,
     ITimeZoneResolver timeZoneResolver)
 {
     _mediator         = mediator;
     _blogConfig       = blogConfig;
     _timeZoneResolver = timeZoneResolver;
 }
Ejemplo n.º 7
0
        public SystemInfoController(
            SystemInfoManager systemInfoManager,
            IOptions <UIOptions> uiOptionsAccessor,
            ITimeZoneResolver timeZoneResolver
            )
        {
            systemInfo = systemInfoManager;

            this.timeZoneResolver = timeZoneResolver;
            uiOptions             = uiOptionsAccessor.Value;
        }
Ejemplo n.º 8
0
 public CommentController(
     ICommentService commentService,
     IBlogConfig blogConfig,
     ITimeZoneResolver timeZoneResolver,
     IBlogNotificationClient notificationClient)
 {
     _commentService     = commentService;
     _blogConfig         = blogConfig;
     _timeZoneResolver   = timeZoneResolver;
     _notificationClient = notificationClient;
 }
Ejemplo n.º 9
0
 internal RecurringJobManager(
     [NotNull] JobStorage storage,
     [NotNull] IBackgroundJobFactory factory,
     [NotNull] ITimeZoneResolver timeZoneResolver,
     [NotNull] Func <DateTime> nowFactory)
 {
     _storage          = storage ?? throw new ArgumentNullException(nameof(storage));
     _factory          = factory ?? throw new ArgumentNullException(nameof(factory));
     _timeZoneResolver = timeZoneResolver ?? throw new ArgumentNullException(nameof(timeZoneResolver));
     _nowFactory       = nowFactory ?? throw new ArgumentNullException(nameof(nowFactory));
 }
        public SystemInfoController(
            SystemInfoManager systemInfoManager,
            IOptions<UIOptions> uiOptionsAccessor,
            ITimeZoneResolver timeZoneResolver
            )
        {
            systemInfo = systemInfoManager;

            this.timeZoneResolver = timeZoneResolver;
            uiOptions = uiOptionsAccessor.Value;

        }
Ejemplo n.º 11
0
 public EditPostModel(IMediator mediator, ITimeZoneResolver timeZoneResolver)
 {
     _mediator         = mediator;
     _timeZoneResolver = timeZoneResolver;
     ViewModel         = new()
     {
         IsPublished   = false,
         Featured      = false,
         EnableComment = true,
         FeedIncluded  = true
     };
 }
Ejemplo n.º 12
0
 public PostController(
     IMediator mediator,
     IBlogConfig blogConfig,
     ITimeZoneResolver timeZoneResolver,
     IPingbackSender pingbackSender,
     ILogger <PostController> logger)
 {
     _mediator         = mediator;
     _blogConfig       = blogConfig;
     _timeZoneResolver = timeZoneResolver;
     _pingbackSender   = pingbackSender;
     _logger           = logger;
 }
Ejemplo n.º 13
0
 public MetaWeblogService(
     IBlogConfig blogConfig,
     ITimeZoneResolver timeZoneResolver,
     ILogger <MetaWeblogService> logger,
     IBlogImageStorage blogImageStorage,
     IFileNameGenerator fileNameGenerator,
     IMediator mediator)
 {
     _blogConfig        = blogConfig;
     _timeZoneResolver  = timeZoneResolver;
     _logger            = logger;
     _blogImageStorage  = blogImageStorage;
     _fileNameGenerator = fileNameGenerator;
     _mediator          = mediator;
 }
Ejemplo n.º 14
0
 public PostController(
     IPostQueryService postQueryService,
     IPostManageService postManageService,
     IBlogConfig blogConfig,
     ITimeZoneResolver timeZoneResolver,
     IPingbackSender pingbackSender,
     ILogger <PostController> logger)
 {
     _postQueryService  = postQueryService;
     _postManageService = postManageService;
     _blogConfig        = blogConfig;
     _timeZoneResolver  = timeZoneResolver;
     _pingbackSender    = pingbackSender;
     _logger            = logger;
 }
Ejemplo n.º 15
0
 public EditPostModel(
     ICategoryService catService,
     IPostQueryService postQueryService,
     ITimeZoneResolver timeZoneResolver)
 {
     _catService       = catService;
     _postQueryService = postQueryService;
     _timeZoneResolver = timeZoneResolver;
     ViewModel         = new()
     {
         IsPublished      = false,
         Featured         = false,
         EnableComment    = true,
         ExposedToSiteMap = true,
         FeedIncluded     = true
     };
 }
Ejemplo n.º 16
0
 public MetaWeblogService(
     IBlogConfig blogConfig,
     ITimeZoneResolver timeZoneResolver,
     ILogger <MetaWeblogService> logger,
     ITagService tagService,
     ICategoryService categoryService,
     IPostQueryService postQueryService,
     IPostManageService postManageService,
     IBlogPageService blogPageService,
     IBlogImageStorage blogImageStorage,
     IFileNameGenerator fileNameGenerator)
 {
     _blogConfig        = blogConfig;
     _timeZoneResolver  = timeZoneResolver;
     _logger            = logger;
     _tagService        = tagService;
     _categoryService   = categoryService;
     _postQueryService  = postQueryService;
     _blogPageService   = blogPageService;
     _blogImageStorage  = blogImageStorage;
     _fileNameGenerator = fileNameGenerator;
     _postManageService = postManageService;
 }
Ejemplo n.º 17
0
 public RecurringJobManager([NotNull] JobStorage storage, [NotNull] IBackgroundJobFactory factory, [NotNull] ITimeZoneResolver timeZoneResolver)
     : this(storage, factory, timeZoneResolver, () => DateTime.UtcNow)
 {
 }
Ejemplo n.º 18
0
        public RecurringJobEntity(
            [NotNull] string recurringJobId,
            [NotNull] IDictionary <string, string> recurringJob,
            [NotNull] ITimeZoneResolver timeZoneResolver,
            DateTime now)
        {
            if (timeZoneResolver == null)
            {
                throw new ArgumentNullException(nameof(timeZoneResolver));
            }

            _recurringJob = recurringJob ?? throw new ArgumentNullException(nameof(recurringJob));

            RecurringJobId = recurringJobId ?? throw new ArgumentNullException(nameof(recurringJobId));

            if (recurringJob.ContainsKey("Queue") && !String.IsNullOrWhiteSpace(recurringJob["Queue"]))
            {
                Queue = recurringJob["Queue"];
            }

            TimeZone = recurringJob.ContainsKey("TimeZoneId") && !String.IsNullOrWhiteSpace(recurringJob["TimeZoneId"])
                ? timeZoneResolver.GetTimeZoneById(recurringJob["TimeZoneId"])
                : TimeZoneInfo.Utc;

            if (recurringJob.ContainsKey("Cron") && !String.IsNullOrWhiteSpace(recurringJob["Cron"]))
            {
                Cron = recurringJob["Cron"];
            }

            if (recurringJob.ContainsKey("Job") && !String.IsNullOrWhiteSpace(recurringJob["Job"]))
            {
                Job = InvocationData.DeserializePayload(recurringJob["Job"]).DeserializeJob();
            }

            if (recurringJob.ContainsKey("LastJobId") && !String.IsNullOrWhiteSpace(recurringJob["LastJobId"]))
            {
                LastJobId = recurringJob["LastJobId"];
            }

            if (recurringJob.ContainsKey("LastExecution") && !String.IsNullOrWhiteSpace(recurringJob["LastExecution"]))
            {
                LastExecution = JobHelper.DeserializeDateTime(recurringJob["LastExecution"]);
            }

            if (recurringJob.ContainsKey("NextExecution") && !String.IsNullOrWhiteSpace(recurringJob["NextExecution"]))
            {
                NextExecution = JobHelper.DeserializeDateTime(recurringJob["NextExecution"]);
            }

            if (recurringJob.ContainsKey("CreatedAt") && !String.IsNullOrWhiteSpace(recurringJob["CreatedAt"]))
            {
                CreatedAt = JobHelper.DeserializeDateTime(recurringJob["CreatedAt"]);
            }
            else
            {
                CreatedAt = now;
            }

            if (recurringJob.ContainsKey("V") && !String.IsNullOrWhiteSpace(recurringJob["V"]))
            {
                Version = int.Parse(recurringJob["V"], CultureInfo.InvariantCulture);
            }
        }
Ejemplo n.º 19
0
    public async Task <IActionResult> General([FromForm] MagicWrapper <GeneralSettings> wrapperModel, [FromServices] ITimeZoneResolver timeZoneResolver)
    {
        var model = wrapperModel.ViewModel;

        _blogConfig.GeneralSettings = model;
        _blogConfig.GeneralSettings.TimeZoneUtcOffset = timeZoneResolver.GetTimeSpanByZoneId(model.TimeZoneId).ToString();

        await _blogConfig.SaveAsync(_blogConfig.GeneralSettings);

        AppDomain.CurrentDomain.SetData("CurrentThemeColor", null);

        return(NoContent());
    }
Ejemplo n.º 20
0
        public async Task <IActionResult> General([FromForm] MagicWrapper <GeneralSettingsViewModel> wrapperModel, [FromServices] ITimeZoneResolver timeZoneResolver)
        {
            var model = wrapperModel.ViewModel;

            var settings = _blogConfig.GeneralSettings;

            settings.MetaKeyword                = model.MetaKeyword;
            settings.MetaDescription            = model.MetaDescription;
            settings.CanonicalPrefix            = model.CanonicalPrefix;
            settings.SiteTitle                  = model.SiteTitle;
            settings.Copyright                  = model.Copyright;
            settings.LogoText                   = model.LogoText;
            settings.SideBarCustomizedHtmlPitch = model.SideBarCustomizedHtmlPitch;
            settings.SideBarOption              = Enum.Parse <SideBarOption>(model.SideBarOption);
            settings.FooterCustomizedHtmlPitch  = model.FooterCustomizedHtmlPitch;
            settings.TimeZoneUtcOffset          = timeZoneResolver.GetTimeSpanByZoneId(model.SelectedTimeZoneId).ToString();
            settings.TimeZoneId                 = model.SelectedTimeZoneId;
            settings.ThemeId            = model.SelectedThemeId;
            settings.OwnerName          = model.OwnerName;
            settings.OwnerEmail         = model.OwnerEmail;
            settings.Description        = model.OwnerDescription;
            settings.ShortDescription   = model.OwnerShortDescription;
            settings.AutoDarkLightTheme = model.AutoDarkLightTheme;

            await _blogConfig.SaveAsync(_blogConfig.GeneralSettings);

            AppDomain.CurrentDomain.SetData("CurrentThemeColor", null);

            await _blogAudit.AddEntry(BlogEventType.Settings, BlogEventId.SettingsSavedGeneral, "General Settings updated.");

            return(NoContent());
        }
Ejemplo n.º 21
0
 public GeneralModel(IBlogConfig blogConfig, ITimeZoneResolver timeZoneResolver, IThemeService themeService)
 {
     _blogConfig       = blogConfig;
     _timeZoneResolver = timeZoneResolver;
     _themeService     = themeService;
 }
 ScheduleRecurringMessageConsumer(IRecurringJobManager recurringJobManager, ITimeZoneResolver timeZoneResolver)
 {
     _recurringJobManager = recurringJobManager;
     _timeZoneResolver    = timeZoneResolver;
 }
Ejemplo n.º 23
0
        public RecurringJobEntity(
            [NotNull] string recurringJobId,
            [NotNull] IDictionary <string, string> recurringJob,
            [NotNull] ITimeZoneResolver timeZoneResolver,
            DateTime now)
        {
            if (timeZoneResolver == null)
            {
                throw new ArgumentNullException(nameof(timeZoneResolver));
            }

            _recurringJob = recurringJob ?? throw new ArgumentNullException(nameof(recurringJob));
            _now          = now;

            RecurringJobId = recurringJobId ?? throw new ArgumentNullException(nameof(recurringJobId));

            if (recurringJob.ContainsKey("Queue") && !String.IsNullOrWhiteSpace(recurringJob["Queue"]))
            {
                Queue = recurringJob["Queue"];
            }

            try
            {
                TimeZone = recurringJob.ContainsKey("TimeZoneId") && !String.IsNullOrWhiteSpace(recurringJob["TimeZoneId"])
                    ? timeZoneResolver.GetTimeZoneById(recurringJob["TimeZoneId"])
                    : TimeZoneInfo.Utc;
            }
            catch (Exception ex)
            {
                _errors.Add(ex);
            }

            if (recurringJob.ContainsKey("Cron") && !String.IsNullOrWhiteSpace(recurringJob["Cron"]))
            {
                Cron = recurringJob["Cron"];
            }

            try
            {
                if (!recurringJob.ContainsKey("Job") || String.IsNullOrWhiteSpace(recurringJob["Job"]))
                {
                    throw new InvalidOperationException("The 'Job' field has a null or empty value");
                }

                Job = InvocationData.DeserializePayload(recurringJob["Job"]).DeserializeJob();
            }
            catch (Exception ex)
            {
                _errors.Add(ex);
            }

            if (recurringJob.ContainsKey("LastJobId") && !String.IsNullOrWhiteSpace(recurringJob["LastJobId"]))
            {
                LastJobId = recurringJob["LastJobId"];
            }

            if (recurringJob.ContainsKey("LastExecution") && !String.IsNullOrWhiteSpace(recurringJob["LastExecution"]))
            {
                LastExecution = JobHelper.DeserializeDateTime(recurringJob["LastExecution"]);
            }

            if (recurringJob.ContainsKey("NextExecution") && !String.IsNullOrWhiteSpace(recurringJob["NextExecution"]))
            {
                NextExecution = JobHelper.DeserializeDateTime(recurringJob["NextExecution"]);
            }

            if (recurringJob.ContainsKey("CreatedAt") && !String.IsNullOrWhiteSpace(recurringJob["CreatedAt"]))
            {
                CreatedAt = JobHelper.DeserializeDateTime(recurringJob["CreatedAt"]);
            }
            else
            {
                CreatedAt = now;
            }

            if (recurringJob.ContainsKey("V") && !String.IsNullOrWhiteSpace(recurringJob["V"]))
            {
                Version = int.Parse(recurringJob["V"], CultureInfo.InvariantCulture);
            }

            if (recurringJob.TryGetValue("RetryAttempt", out var attemptString) &&
                int.TryParse(attemptString, out var retryAttempt))
            {
                RetryAttempt = retryAttempt;
            }
        }
Ejemplo n.º 24
0
 public GeneralModel(IBlogConfig blogConfig, ITimeZoneResolver timeZoneResolver, IMediator mediator)
 {
     _blogConfig       = blogConfig;
     _timeZoneResolver = timeZoneResolver;
     _mediator         = mediator;
 }