Exemplo n.º 1
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != Constants.CleanupSnapshots)
            {
                return;
            }

            try
            {
                var idsToRetain = new List <int>();

                foreach (var retentionPolicy in _retentionPolicies)
                {
                    idsToRetain.AddRange(retentionPolicy.GetSnapshotIdsToRetain());
                }

                var recordsToDelete = _repository.Table.Where(r => !idsToRetain.Contains(r.Id));

                foreach (var record in recordsToDelete)
                {
                    _repository.Delete(record);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Failed to cleanup Content Sync Snapshots. An exception was thrown by the task handler.");
            }

            //now reschedule the task
            _scheduledTaskManager.DeleteTasks(null, a => a.TaskType == Constants.CleanupSnapshots);
            _scheduledTaskManager.CreateTask(Constants.CleanupSnapshots, _clock.UtcNow.AddMinutes(1), null);
        }
Exemplo n.º 2
0
        public void Process(ScheduledTaskContext context)
        {
            if (context.Task.TaskType != Constants.TakeSnapshotTaskName)
            {
                return;
            }

            try {
                //the default export service impl makes an assumption that there is an associated user, so we need to set the owner here
                var siteOwner = _membershipService.GetUser(_orchardServices.WorkContext.CurrentSite.As <SiteSettingsPart>().SuperUser);
                _authenticationService.SetAuthenticatedUserForRequest(siteOwner);

                _snapshotService.TakeSnaphot();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Failed to generate a scheduled Content Sync Snapshot. An exception was thrown by the task handler.");
            }

            //now reschedule the task
            _scheduledTaskManager.DeleteTasks(null, a => a.TaskType == Constants.TakeSnapshotTaskName);

            var snapshotFrequency = _orchardServices.WorkContext.CurrentSite.As <ContentSyncSettingsPart>().SnapshotFrequencyMinutes;

            if (snapshotFrequency == 0)
            {
                return;
            }

            _scheduledTaskManager.CreateTask(Constants.TakeSnapshotTaskName, _clock.UtcNow.AddMinutes(snapshotFrequency), null);
        }
Exemplo n.º 3
0
        public void ScheduleEvent(SchedulingPart eventDefinitionPart)
        {
            // Delete ongoing schedules
            // TODO: also the other taskTypes, see Constants -> Scheduling Constants
            _scheduledTaskManager.DeleteTasks(eventDefinitionPart.ContentItem, task => task.TaskType == Constants.EventStartedName);

            if (eventDefinitionPart.StartDateTime.HasValue)
            {
                _scheduledTaskManager.CreateTask(Constants.EventStartedName, eventDefinitionPart.StartDateTime.Value, eventDefinitionPart.ContentItem);
            }
        }
        public FeedSyncProfilePartHandler(
            IJsonConverter jsonConverter,
            IScheduledTaskManager scheduledTaskManager,
            IClock clock)
        {
            OnActivated <FeedSyncProfilePart>((context, part) =>
            {
                part.MappingsField.Loader(() =>
                {
                    return(string.IsNullOrEmpty(part.MappingsSerialized)
                        ? new List <Mapping>()
                        : jsonConverter.Deserialize <List <Mapping> >(part.MappingsSerialized));
                });
            });

            OnRemoved <FeedSyncProfilePart>((context, part) =>
            {
                scheduledTaskManager.DeleteTasks(part.ContentItem);
            });

            OnPublished <FeedSyncProfilePart>((context, part) =>
            {
                part.PublishedCount++;

                if (context.PreviousItemVersionRecord != null)
                {
                    scheduledTaskManager.DeleteTasks(part.ContentItem);

                    // Because of the ContentType-first editor, we want to create the task only after
                    // the second successful saving.
                    scheduledTaskManager
                    .CreateTask(
                        part.ContentItem.GetFeedSyncProfileUpdaterTaskName(),
                        clock.UtcNow.AddMinutes(1),
                        part.ContentItem);
                }
            });
        }
Exemplo n.º 5
0
        private void ScheduleNextTask(DateTime date)
        {
            if (date > DateTime.UtcNow)
            {
                var tasks = this._taskManager.GetTasks(TASK_TYPE);
                foreach (var item in tasks)
                {
                    if (item.ScheduledUtc <= DateTime.UtcNow)
                    {
                        _taskManager.DeleteTasks(item.ContentItem);
                    }
                }
                tasks = this._taskManager.GetTasks(TASK_TYPE);

                if (tasks == null || tasks.Count() == 0)
                {
                    this._taskManager.CreateTask(TASK_TYPE, date, null);
                }
            }
        }
Exemplo n.º 6
0
        public ContentSyncSettingsPartHandler(IRepository <ContentSyncSettingsRecord> repository, IScheduledTaskManager scheduledTaskManager, IClock clock)
        {
            _scheduledTaskManager = scheduledTaskManager;
            _clock = clock;
            T      = NullLocalizer.Instance;

            Filters.Add(new ActivatingFilter <ContentSyncSettingsPart>("Site"));
            Filters.Add(StorageFilter.For(repository));

            OnUpdated <ContentSyncSettingsPart>((ctx, part) =>
            {
                //schedule the snapshot task
                _scheduledTaskManager.DeleteTasks(null, a => a.TaskType == Constants.TakeSnapshotTaskName);

                if (part.SnapshotFrequencyMinutes == 0)
                {
                    return;
                }

                _scheduledTaskManager.CreateTask(Constants.TakeSnapshotTaskName, _clock.UtcNow, null);
            });
        }
Exemplo n.º 7
0
 public void Activated()
 {
     _scheduledTaskManager.DeleteTasks(null, a => a.TaskType == Constants.CleanupSnapshots);
     _scheduledTaskManager.CreateTask(Constants.CleanupSnapshots, _clock.UtcNow, null);
 }
 public void DeleteExistingScheduleTasks(ContentItem contentItem)
 {
     _scheduledTaskManager.DeleteTasks(contentItem, t => Constants.DefaultEventNames.Contains(t.TaskType));
 }
Exemplo n.º 9
0
        public MarkdownRepoPartHandler(
            IMarkdownContentItemManager markdownContentItemManager,
            IRepository <MarkdownRepoPartRecord> repository,
            IScheduledTaskManager scheduledTaskManager,
            IClock clock,
            IContentManager contentManager,
            IEncryptionService encryptionService)
        {
            Filters.Add(StorageFilter.For(repository));

            OnActivated <MarkdownRepoPart>((context, part) =>
            {
                part.AccessTokenField.Loader(() =>
                {
                    return(string.IsNullOrEmpty(part.EncodedAccessToken)
                        ? ""
                        : Encoding.UTF8.GetString(encryptionService.Decode(Convert.FromBase64String(part.EncodedAccessToken))));
                });

                part.AccessTokenField.Setter((value) =>
                {
                    part.EncodedAccessToken = string.IsNullOrEmpty(value)
                        ? ""
                        : Convert.ToBase64String(encryptionService.Encode(Encoding.UTF8.GetBytes(value)));

                    return(value);
                });

                part.PasswordField.Loader(() =>
                {
                    return(string.IsNullOrEmpty(part.EncodedPassword)
                        ? ""
                        : Encoding.UTF8.GetString(encryptionService.Decode(Convert.FromBase64String(part.EncodedPassword))));
                });

                part.PasswordField.Setter((value) =>
                {
                    part.EncodedPassword = string.IsNullOrEmpty(value)
                        ? ""
                        : Convert.ToBase64String(encryptionService.Encode(Encoding.UTF8.GetBytes(value)));

                    return(value);
                });
            });

            OnRemoved <MarkdownRepoPart>((ctx, part) =>
            {
                scheduledTaskManager.DeleteTasks(part.ContentItem);

                if (part.DeleteMarkdownPagesOnRemoving == true)
                {
                    markdownContentItemManager.DeleteAll(part);
                }
                // Since the repo is deleted we doesn't want to prevent the deletion of the markdown pages.
                else
                {
                    var correspondingMarkdownPages = contentManager
                                                     .Query(part.ContentType)
                                                     .Where <MarkdownPagePartRecord>(record => record.MarkdownRepoId == part.ContentItem.Id)
                                                     .List();

                    foreach (var correspondingMarkdownPage in correspondingMarkdownPages)
                    {
                        correspondingMarkdownPage.As <MarkdownPagePart>().DeletionAllowed = true;
                    }
                }
            });

            OnPublished <MarkdownRepoPart>((ctx, part) =>
            {
                if (ctx.PreviousItemVersionRecord != null)
                {
                    scheduledTaskManager.DeleteTasks(part.ContentItem);
                }

                scheduledTaskManager
                .CreateTask(
                    TaskNameHelper.GetMarkdownContentUpdaterTaskName(part.ContentItem),
                    clock.UtcNow.AddMinutes(1),
                    part.ContentItem);
            });
        }
Exemplo n.º 10
0
 public void DeleteTasks(ContentItem item)
 {
     _scheduledTaskManager.DeleteTasks(item, task => task.TaskType == PublishTaskType);
 }
Exemplo n.º 11
0
 public void RemoveArchiveLaterTasks(ContentItem contentItem)
 {
     _scheduledTaskManager.DeleteTasks(contentItem, t => t.TaskType == UnpublishTaskType);
 }
Exemplo n.º 12
0
        public void UpdateSchedule(string typeName, GDPRPartTypeSchedulingSettings settings)
        {
            // compute the name of the scheduled task for this type
            var taskName = string.Format(Constants.ScheduledTaskFormat, typeName);
            // check whether this type has a scheduled task
            var hasTask = _taskManager.GetTasks(taskName).Any();

            // if the settings say that the type should be processed, schedule a task
            if (settings.ScheduleAnonymization || settings.ScheduleErasure)
            {
                if (!hasTask)
                {
                    // create the task
                    _taskManager.CreateTask(taskName, _clock.UtcNow, null);
                }
                else
                {
                    // We run the risk of never processing some ContentItem in some conditions related to
                    // changes that happened to the configuration.
                    var oldSettings = SettingsFromType(typeName);
                    // Conditions describing the fact that the configuration has changed:
                    // - I should anonymize, but this was not the case before
                    var taskChanged = settings.ScheduleAnonymization && !oldSettings.ScheduleAnonymization;
                    // - I should erase, but this was not the case before
                    taskChanged |= settings.ScheduleErasure && !oldSettings.ScheduleErasure;
                    // - I should anonymize, as was the case before, but the time frame now is smaller
                    taskChanged |= (settings.ScheduleAnonymization && oldSettings.ScheduleAnonymization) &&
                                   settings.AnonymizationDaysToWait < oldSettings.AnonymizationDaysToWait;
                    // - I should erase, as was the case before, but the time frame now is smaller
                    taskChanged |= (settings.ScheduleErasure && oldSettings.ScheduleErasure) &&
                                   settings.ErasureDaysToWait < oldSettings.ErasureDaysToWait;
                    // - I should anonymize, as was the case before, but the event to check for anonymization has changed
                    taskChanged |= (settings.ScheduleAnonymization && oldSettings.ScheduleAnonymization) &&
                                   settings.EventForAnonymization != oldSettings.EventForAnonymization;
                    // - I should erase, as was the case before, but event to check for erasure has changed
                    taskChanged |= (settings.ScheduleErasure && oldSettings.ScheduleErasure) &&
                                   settings.EventForErasure != oldSettings.EventForErasure;

                    // If the configuration has changed, recreate the task
                    if (taskChanged)
                    {
                        _taskManager.DeleteTasks(null, st => st.TaskType == taskName);
                        _taskManager.CreateTask(taskName, _clock.UtcNow, null);
                    }
#if DEBUG
                    else
                    {
                        // we are debugging, so we recreate the task, passing a ContentItem to simulate the n-th execution
                        _taskManager.DeleteTasks(null, st => st.TaskType == taskName);
                        _taskManager.CreateTask(taskName, _clock.UtcNow, _siteService.GetSiteSettings().ContentItem);
                    }
#endif
                }
            }
            else
            {
                // this type is set to have no processing done
                if (hasTask)
                {
                    // destroy the task
                    _taskManager.DeleteTasks(null, st => st.TaskType == taskName);
                }
            }
        }