/// <summary>
        /// Deletes the task.
        /// </summary>
        /// <param name="taskId">The task unique identifier.</param>
        public void DeleteTask(int taskId)
        {
            using (ISessionScope sessionScope = m_SessionScopeProvider.CreateSessionScope())
            {
                sessionScope.GetRepository <ScheduledTask>().Delete(x => x.Id == taskId);

                sessionScope.Complete();
            }
        }
        /// <summary>
        /// Inserts the task.
        /// </summary>
        /// <param name="task">The task.</param>
        public void InsertTask(ScheduledTask task)
        {
            using (ISessionScope sessionScope = m_SessionScopeProvider.CreateSessionScope())
            {
                IRepository <ScheduledTask> repository = sessionScope.GetRepository <ScheduledTask>();

                ValidateTask(repository, task);

                repository.Insert(task);

                sessionScope.Complete();
            }
        }
        /// <summary>
        /// Updates the start date.
        /// </summary>
        /// <param name="taskId">The task unique identifier.</param>
        /// <param name="startDateUtc">The start date UTC.</param>
        public void UpdateStartDate(int taskId, DateTime startDateUtc)
        {
            using (ISessionScope sessionScope = m_SessionScopeProvider.CreateSessionScope(SessionScopeOption.RequiresNew))
            {
                ScheduledTask task = new ScheduledTask {
                    Id = taskId, LastStartUtc = startDateUtc
                };

                sessionScope.GetRepository <ScheduledTask>().UpdateProperties(task, x => x.Id, x => x.LastStartUtc);

                sessionScope.Complete();
            }
        }
        /// <summary>
        /// Updates the end date.
        /// </summary>
        /// <param name="taskId">The task unique identifier.</param>
        /// <param name="endDateUtc">The end date UTC.</param>
        /// <param name="success">if set to <c>true</c> [success].</param>
        public void UpdateEndDate(int taskId, DateTime endDateUtc, bool success)
        {
            using (ISessionScope sessionScope = m_SessionScopeProvider.CreateSessionScope(SessionScopeOption.RequiresNew))
            {
                ScheduledTask task = new ScheduledTask {
                    Id = taskId, LastEndUtc = endDateUtc
                };

                IRepository <ScheduledTask> repository = sessionScope.GetRepository <ScheduledTask>();

                if (success)
                {
                    task.LastSuccessUtc = endDateUtc;

                    repository.UpdateProperties(task, x => x.Id, x => x.LastEndUtc, x => x.LastSuccessUtc);
                }
                else
                {
                    repository.UpdateProperties(task, x => x.Id, x => x.LastEndUtc);
                }

                sessionScope.Complete();
            }
        }
        /// <summary>
        /// Updates the task.
        /// </summary>
        /// <param name="task">The task.</param>
        public void UpdateTask(ScheduledTask task)
        {
            using (ISessionScope sessionScope = m_SessionScopeProvider.CreateSessionScope())
            {
                IRepository <ScheduledTask> repository = sessionScope.GetRepository <ScheduledTask>();

                ValidateTask(repository, task);

                repository
                .UpdateProperties(
                    task,
                    x => x.Id,
                    x => x.Enabled,
                    x => x.Name,
                    x => x.Description,
                    x => x.RunOnlyOnce,
                    x => x.Seconds,
                    x => x.StopOnError,
                    x => x.Type,
                    x => x.Configuration);

                sessionScope.Complete();
            }
        }