Ejemplo n.º 1
0
        private void UpdateTasksInDatabase(IList <ITask> allTaskTypes, IList <ScheduledTask> availableScheduledTasks)
        {
            foreach (var iTask in allTaskTypes)
            {
                if (availableScheduledTasks.Any(x => x.SystemName == iTask.SystemName))
                {
                    var t = availableScheduledTasks.First(x => x.SystemName == iTask.SystemName);
                    if (t.Name != iTask.Name)
                    {
                        t.Name = iTask.Name;
                        _scheduledTaskService.Update(t);
                    }
                    continue; //it's there so no need to do anything except update name
                }

                //if we are here, we'll need to add the task
                var st = new ScheduledTask()
                {
                    Enabled     = false,
                    IsRunning   = false,
                    Name        = iTask.Name,
                    SystemName  = iTask.SystemName,
                    StopOnError = false,
                    Seconds     = iTask.DefaultCycleDurationInSeconds
                };
                _scheduledTaskService.Insert(st);
                availableScheduledTasks.Add(st);
            }
        }