public void PrepareTaskSchedule(string systemJobId, bool allowMultipleInstances)
		{
			lock (keylock)
			{
				var job = SystemJobs.FirstOrDefault(sj => sj.SystemJobId == systemJobId);
				var taskSchedule = TaskSchedules.SingleOrDefault(ts => ts.SystemJobId == systemJobId);
				if (taskSchedule == null)
				{
					var startedDateTime = DateTime.UtcNow;
					var originalFrequency = SchedulerDbContext.PeriodToFrequency(job.Period);
					var newTaskSchedule = new TaskSchedule
					{
						Frequency = originalFrequency,
						NextScheduledStartTime = startedDateTime.AddMinutes(originalFrequency),
						SystemJobId = systemJobId
					};
					TaskSchedules.Add(newTaskSchedule);
				}
			}
		}
		public void UpdateTaskSchedule(string systemJobId)
		{
			lock (keylock)
			{
				var job = SystemJobs.FirstOrDefault(sj => sj.SystemJobId == systemJobId);
				var task = TaskSchedules.SingleOrDefault(ts => ts.SystemJobId == systemJobId);
				if (task != null)
				{
					TaskSchedules.Remove(task);
				}
				if (job != null && job.IsEnabled && job.Period > 0)
				{
					var startedDateTime = DateTime.UtcNow;
					var originalFrequency = SchedulerDbContext.PeriodToFrequency(job.Period);
					var newTaskSchedule = new TaskSchedule
					{
						Frequency = originalFrequency,
						NextScheduledStartTime = startedDateTime.AddMinutes(originalFrequency),
						SystemJobId = systemJobId
					};
					TaskSchedules.Add(newTaskSchedule);
				}
			}
		}
        /// <summary>
        /// Updates the task schedule.
        /// </summary>
        /// <param name="systemJobId">The system job identifier.</param>
        public void UpdateTaskSchedule(string systemJobId)
        {
            var repository = _repositoryFactory();

            using (SqlDbConfiguration.ExecutionStrategySuspension)
            using (var transaction = new TransactionScope(TransactionScopeOption.Required,
                new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
            {
                var job = repository.SystemJobs.FirstOrDefault(sj => sj.SystemJobId == systemJobId);
                var task = repository.TaskSchedules.SingleOrDefault(ts => ts.SystemJobId == systemJobId);
                if (task != null)
                {
                    repository.Remove(task);
                }
                if (job != null && job.IsEnabled && job.Period > 0)
                {
                    var startedDateTime = DateTime.UtcNow;
                    var originalFrequency = PeriodToFrequency(job.Period);
                    var newTaskSchedule = new TaskSchedule
                    {
                        Frequency = originalFrequency,
                        NextScheduledStartTime = startedDateTime.AddMinutes(originalFrequency),
                        SystemJobId = systemJobId
                    };
                    repository.Add(newTaskSchedule);
                }
                repository.UnitOfWork.Commit();
                transaction.Complete();
            }
        }