Exemplo n.º 1
0
        public async Task InsertCronTaskAsync(int scheduleTaskId, string cronExpression)
        {
            var ga = _genericAttributeRepository.Table
                     .FirstOrDefault(gar => gar.KeyGroup == nameof(ScheduleTask) && gar.Key == CronTasksDefaults.CronExpressionGenericAttributeKey && gar.EntityId == scheduleTaskId);

            if (ga == null)
            {
                ga = new GenericAttribute()
                {
                    StoreId  = 0,
                    KeyGroup = nameof(ScheduleTask),
                    Key      = CronTasksDefaults.CronExpressionGenericAttributeKey,
                    EntityId = scheduleTaskId,
                    Value    = cronExpression
                };
                await _genericAttributeService.InsertAttributeAsync(ga);
            }
            else
            {
                ga.Value = cronExpression;
                await _genericAttributeService.UpdateAttributeAsync(ga);
            }

            var scheduledTask = await _scheduleTaskService.GetTaskByIdAsync(scheduleTaskId);

            if (scheduledTask != null)
            {
                scheduledTask.Enabled = false;
                await _scheduleTaskService.UpdateTaskAsync(scheduledTask);
            }

            await RescheduleQuartzJobAsync(scheduleTaskId, cronExpression);
        }
Exemplo n.º 2
0
        public async Task ShouldUpdateCreatedOrUpdatedDateUtcInUpdateAttribute()
        {
            var attribute = new global::Nop.Core.Domain.Common.GenericAttribute {
                Key = "test", KeyGroup = "test", Value = "test"
            };

            await _genericAttributeService.InsertAttributeAsync(attribute);

            attribute.CreatedOrUpdatedDateUTC = DateTime.UtcNow.AddDays(-30);
            await _genericAttributeService.UpdateAttributeAsync(attribute);

            var createdOrUpdatedDate = attribute.CreatedOrUpdatedDateUTC;

            await _genericAttributeService.DeleteAttributeAsync(attribute);

            Assert.That(createdOrUpdatedDate,
                        Is.EqualTo(DateTime.UtcNow).Within(1).Minutes);
        }