Exemplo n.º 1
0
        private void ExecuteJob(ScheduleJob executeJob)
        {
            _log.Write("Приступаю к выполнению джобы id: " + executeJob.Id);
            ScheduleTask executeTask = ScheduleService.Deserialize(executeJob.Task);
            Action       execute     = executeTask.Execute;

            executeJob.ExecutionDate = DateTime.Now;
            executeJob.State         = (byte)JobState.Started;
            SaveJobStatusToDb(executeJob);
            Tuple <Guid, Action, DateTime> args = new Tuple <Guid, Action, DateTime>(executeJob.Id, execute, DateTime.Now);

            execute.BeginInvoke(JobIsDone, args);
        }
Exemplo n.º 2
0
        public static ScheduleTask Deserialize(byte[] serializedTask)
        {
            var stream = new MemoryStream(serializedTask);

            stream.Position = 0; //?
            BinaryFormatter bformatter     = new BinaryFormatter();
            ScheduleTask    resultFunction = bformatter.Deserialize(stream) as ScheduleTask;

            if (resultFunction == null)
            {
                throw new Exception("Неверные данные!");
            }
            return(resultFunction);
        }
Exemplo n.º 3
0
        public ScheduleJob AddJob(ScheduleTask task, DateTime executionTime, bool doRepeat, int? repeatPeriod, bool tryRecover)
        {
            _log.Write("Добавление нового таска " + task.Name);
            ScheduleJob newJob = new ScheduleJob
                                     {
                                         CreationDate = DateTime.Now,
                                         ExecutionDate = DateTime.Now,
                                         NextExecutionDate = executionTime,
                                         Task = task.Serialize(),
                                         State = (byte)JobState.ReadyToStart,
                                         RepeatPeriod = repeatPeriod,
                                         DoRepeat = doRepeat,
                                         TryRecover = tryRecover,
                                         IsUnique = task.IsUnique,
                                         Title = task.Name,
                                         Type = task.GetType().FullName
                                     };

            if (newJob.IsUnique)
            {
                var oldjob = DataService.PerThread.ScheduleJobSet.FirstOrDefault(x => x.Type == newJob.Type && (x.State == (byte)JobState.ReadyToStart || x.State == (byte)JobState.ReadyToRecover || x.State == (byte)JobState.Started));
                if (oldjob != null)
                {
                    if (oldjob.State == (byte)JobState.Started)
                    {
                    }
                    else
                    {
                        oldjob.RepeatPeriod = newJob.RepeatPeriod;
                        oldjob.DoRepeat = newJob.DoRepeat;
                        oldjob.TryRecover = newJob.TryRecover;
                        oldjob.Title = newJob.Title;
                        DataService.PerThread.SaveChanges();
                    }

                    return oldjob;
                }
            }

            SaveJobsToDb(newJob);
            return newJob;
        }
Exemplo n.º 4
0
        public ScheduleJob AddJob(ScheduleTask task, DateTime executionTime, bool doRepeat, int?repeatPeriod, bool tryRecover)
        {
            _log.Write("Добавление нового таска " + task.Name);
            ScheduleJob newJob = new ScheduleJob
            {
                CreationDate      = DateTime.Now,
                ExecutionDate     = DateTime.Now,
                NextExecutionDate = executionTime,
                Task         = task.Serialize(),
                State        = (byte)JobState.ReadyToStart,
                RepeatPeriod = repeatPeriod,
                DoRepeat     = doRepeat,
                TryRecover   = tryRecover,
                IsUnique     = task.IsUnique,
                Title        = task.Name,
                Type         = task.GetType().FullName
            };

            if (newJob.IsUnique)
            {
                var oldjob = DataService.PerThread.ScheduleJobSet.FirstOrDefault(x => x.Type == newJob.Type && (x.State == (byte)JobState.ReadyToStart || x.State == (byte)JobState.ReadyToRecover || x.State == (byte)JobState.Started));
                if (oldjob != null)
                {
                    if (oldjob.State == (byte)JobState.Started)
                    {
                    }
                    else
                    {
                        oldjob.RepeatPeriod = newJob.RepeatPeriod;
                        oldjob.DoRepeat     = newJob.DoRepeat;
                        oldjob.TryRecover   = newJob.TryRecover;
                        oldjob.Title        = newJob.Title;
                        DataService.PerThread.SaveChanges();
                    }

                    return(oldjob);
                }
            }

            SaveJobsToDb(newJob);
            return(newJob);
        }
Exemplo n.º 5
0
 public ScheduleJob AddJob(ScheduleTask task, TimeSpan executionAfter, bool doRepeat, int? repeatPeriod, bool tryRecover)
 {
     return AddJob(task, DateTime.Now + executionAfter, doRepeat, repeatPeriod, tryRecover);
 }
Exemplo n.º 6
0
 public static ScheduleJob AddJob(ScheduleTask task, TimeSpan executeAfter, bool doRepeat, int? repeatPeriod, bool tryRecover)
 {
     return _current.AddJob(task, executeAfter, doRepeat, repeatPeriod, tryRecover);
 }
Exemplo n.º 7
0
 public static ScheduleJob AddJob(ScheduleTask task, TimeSpan executeAfter, bool doRepeat, int?repeatPeriod, bool tryRecover)
 {
     return(_current.AddJob(task, executeAfter, doRepeat, repeatPeriod, tryRecover));
 }
Exemplo n.º 8
0
 public ScheduleJob AddJob(ScheduleTask task, TimeSpan executionAfter, bool doRepeat, int?repeatPeriod, bool tryRecover)
 {
     return(AddJob(task, DateTime.Now + executionAfter, doRepeat, repeatPeriod, tryRecover));
 }