예제 #1
0
 public override async void OnCreate()
 {
     if (!Jobs.Any())
     {
         await GetMostRecentJobs();
     }
 }
예제 #2
0
파일: Scheduler.cs 프로젝트: ichttt/Twice
        public Scheduler(string fileName, ITwitterContextList contextList, ITwitterConfiguration twitterConfig)
        {
            FileName = fileName;
            JobProcessors.Add(SchedulerJobType.DeleteStatus, new DeleteStatusProcessor(contextList));
            JobProcessors.Add(SchedulerJobType.CreateStatus, new CreateStatusProcessor(contextList, twitterConfig));

            if (File.Exists(FileName))
            {
                var json = File.ReadAllText(FileName);
                try
                {
                    Jobs.AddRange(JsonConvert.DeserializeObject <List <SchedulerJob> >(json));
                }
                catch (Exception ex)
                {
                    LogTo.WarnException("Failed to load joblist from file", ex);
                }
            }

            JobIdCounter = Jobs.Any()
                                ? Jobs.Max(j => j.JobId) + 1
                                : 0;

            SleepTime = 1000;
        }
예제 #3
0
        public IEnumerable <Event> PlanMaintenanceJob(PlanMaintenanceJob command)
        {
            // check business rules

            // maintenance jobs may not span multiple days
            if (command.StartTime.Date != command.EndTime.Date)
            {
                throw new BusinessRuleViolationException("Start-time and end-time of a Maintenance Job must be within a 1 day.");
            }

            // no more than 3 jobs can be planned at the same time (limited resources)
            if (Jobs.Count(j => (j.StartTime >= command.StartTime && j.StartTime <= command.EndTime) ||
                           (j.EndTime >= command.StartTime && j.EndTime <= command.EndTime)) >= MAX_PARALLEL_JOBS)
            {
                throw new BusinessRuleViolationException($"Maintenancejob overlaps with more than {MAX_PARALLEL_JOBS} other jobs.");
            }

            // only 1 maintenance job can be executed on a vehicle during a certain time-slot
            if (Jobs.Any(j => j.Vehicle.Matricula == command.VehicleInfo.Matricula &&
                         (j.StartTime >= command.StartTime && j.StartTime <= command.EndTime ||
                          j.EndTime >= command.StartTime && j.EndTime <= command.EndTime)))
            {
                throw new BusinessRuleViolationException($"Only 1 maintenance job can be executed on a vehicle during a certain time-slot.");
            }

            // handle event
            MaintenanceJobPlanned e = Mapper.Map <MaintenanceJobPlanned>(command);

            return(HandleEvent(e));
        }
        public void Save(IJob obj)
        {
            var job = (Job)obj;

            if (!Jobs.Any(j => job.JobId == j.JobId))
            {
                Jobs.Add(job);
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="jobId"></param>
        public void AddJob(int jobId)
        {
            // already exists
            if (Jobs.Any(job => job.JobId == jobId))
            {
                return;
            }

            // will implicitly added to the list of job because it has the same reference
            CharacterJobRepository.Instance.Create(m_character.Id, jobId);
        }
        public string SetStandartData()
        {
            if (!Jobs.Any())
            {
                try
                {
                    Jobs.AddRange(new List <Job>()
                    {
                        new Job()
                        {
                            Jobtype = "Менеджер"
                        },
                        new Job()
                        {
                            Jobtype = "Повар"
                        },
                        new Job()
                        {
                            Jobtype = "Доставка"
                        },
                        new Job()
                        {
                            Jobtype = "Официант"
                        }
                    });

                    if (!EatTypes.Any())
                    {
                        EatTypes.AddRange(new List <EatType>()
                        {
                            new EatType()
                            {
                                EatTypeName = "Завтрак"
                            },
                            new EatType()
                            {
                                EatTypeName = "Обед"
                            },
                            new EatType()
                            {
                                EatTypeName = "Ужин"
                            },
                        });
                    }
                    SaveChanges();
                    return(0.ToString());
                }
                catch (Exception e)
                {
                    return(e.ToString());
                }
            }
            return("1");
        }
예제 #7
0
        /// <summary>
        /// Get job name that doesn't overlap with an existing one
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private string GetJobName(string name)
        {
            string newName = name;
            int    counter = 1;

            while (Jobs.Any(x => x.Name == newName))
            {
                newName = name + counter;
                counter++;
            }
            return(newName);
        }
예제 #8
0
        public void AddNewJob(int id)
        {
            if (Jobs.Any(x => x.ID == id))
            {
                return;
            }

            Jobs.Add(new Jobs.Job(id, 1, 0));

            SendJobs();
            SendJobsXP();
            SendJobOptions();
        }
예제 #9
0
        public void ScheduleRecurringResend(int miliseconds, Guid messageId, Action <Guid> func)
        {
            //return if the task exists
            if (Jobs.Any(x => x.Item2 == messageId))
            {
                return;
            }
            var cts   = new CancellationTokenSource();
            var token = cts.Token;

            Jobs.Add(new Tuple <CancellationTokenSource, Guid>(cts, messageId));
            Task.Delay(miliseconds).ContinueWith(t => { CreateDelayedRecurringResend(miliseconds, messageId, func, token); }, token);
        }
예제 #10
0
 public void CancelTask(Guid messageId, string clientId, int seqNo)
 {
     if (JobsWithClientId.ContainsKey(clientId + seqNo))
     {
         JobsWithClientId[clientId + seqNo].Cancel();
         JobsWithClientId.Remove(clientId + seqNo);
     }
     else if (Jobs.Any(x => x.Item2 == messageId))
     {
         var job = Jobs.Find(x => x.Item2 == messageId);
         job.Item1.Cancel();
         Jobs.Remove(job);
     }
 }
예제 #11
0
        private async Task ExecuteSearchCommand()
        {
            IsBusy = true;
            var jobsList = await SearchJob();

            if (Jobs.Any())
            {
                Jobs.Clear();
            }
            if (jobsList != null)
            {
                Jobs.AddRange(jobsList);
            }
            IsBusy = false;
        }
        public void Remove(IJob obj)
        {
            var job = (Job)obj;

            foreach (var note in job.Notes.ToList())
            {
                Remove(note);
            }

            foreach (var task in job.Tasks.ToList())
            {
                Remove(task);
            }

            if (Jobs.Any(j => job.JobId == j.JobId))
            {
                Jobs.Remove(job);
            }
        }
예제 #13
0
        public void CreateJob(Job protoJob, Tile tile, float amountDone = 0)
        {
            if (protoJob?.CanCreate == null || tile == null || world == null || Jobs == null ||
                world?.Resources < protoJob.Cost && amountDone == 0 ||
                Jobs.Any(j => tile == j.Tile) || !protoJob.CanCreate(tile))
            {
                return;
            }
            if (amountDone == 0)
            {
                world.Resources -= protoJob.Cost;
            }
            var jobToCreate = new Job(protoJob)
            {
                Tile = tile, AmountDone = amountDone
            };

            AvailableJobs?.Add(jobToCreate);
            world.OnChange();
        }
예제 #14
0
        public void Can_prepare_mock_data()
        {
            Assert.That(StartLocation != null);
            Assert.That(Locations != null && Locations.Any(), "Mock Locations not ready");
            Assert.That(Drivers != null && Drivers.Any(), "Mock Drivers not ready");
            Assert.That(Jobs != null && Jobs.Any(), "Mock Jobs not ready");

            var hazmatJobs    = Jobs.Where(p => p.IsHazmat);
            var shortHaulJobs = Jobs.Where(p => p.IsShortHaul);
            var longHaulJobs  = Jobs.Where(p => p.IsLongHaul);
            var type1Jobs     = Jobs.Where(p => p.OrderType == 1);
            var type2Jobs     = Jobs.Where(p => p.OrderType == 2);
            var type3Jobs     = Jobs.Where(p => p.OrderType == 3);
            var p1Jobs        = Jobs.Where(p => p.Priority == 1);
            var p2Jobs        = Jobs.Where(p => p.Priority == 2);
            var p3Jobs        = Jobs.Where(p => p.Priority == 3);

            Assert.That(hazmatJobs != null && hazmatJobs.Any());
            Assert.That(shortHaulJobs != null && shortHaulJobs.Any());
            Assert.That(longHaulJobs != null && longHaulJobs.Any());
            Assert.That(type1Jobs != null && type1Jobs.Any());
            Assert.That(type2Jobs != null && type2Jobs.Any());
            Assert.That(type3Jobs != null && type3Jobs.Any());
            Assert.That(p1Jobs != null && p1Jobs.Any());
            Assert.That(p2Jobs != null && p2Jobs.Any());
            Assert.That(p3Jobs != null && p3Jobs.Any());

            var hazmatDrivers    = Drivers.Where(p => p.IsHazmatEligible);
            var shortHaulDrivers = Drivers.Where(p => p.IsShortHaulEligible);
            var longHaulDrivers  = Drivers.Where(p => p.IsLongHaulEligible);
            var type1Drivers     = Drivers.Where(p => p.OrderType == 1);
            var type2Drivers     = Drivers.Where(p => p.OrderType == 2);
            var type3Drivers     = Drivers.Where(p => p.OrderType == 3);

            Assert.That(hazmatDrivers != null && hazmatDrivers.Any());
            Assert.That(shortHaulDrivers != null && shortHaulDrivers.Any());
            Assert.That(longHaulDrivers != null && longHaulDrivers.Any());
            Assert.That(type1Drivers != null && type1Drivers.Any());
            Assert.That(type2Drivers != null && type2Drivers.Any());
            Assert.That(type3Drivers != null && type3Drivers.Any());
        }
예제 #15
0
        private void JobStopping(ThenExecute thenExecute)
        {
            if (this.waitJobStopped == null || this.waitJobStopped.Status != TaskStatus.Running)
            {
                this.waitJobStopped = new Task(() =>
                {
                    while (Jobs.Any((job) => job.IsExecuting))
                    {
                        Thread.Sleep(1000);
                    }
                });

                this.waitJobStopped.ContinueWith((wAitjobStopped) =>
                {
                    this.InvokeIfNecessary(() =>
                    {
                        switch (thenExecute)
                        {
                        case ThenExecute.Stop:
                            {
                                Log.Info("作業停止");
                                this.SwitchStoppedState();
                            }

                            break;

                        case ThenExecute.Exit:
                            {
                                Application.Exit();
                            }

                            break;
                        }
                    });
                });

                this.waitJobStopped.Start();
            }
        }
예제 #16
0
 public bool HasJob(int id)
 {
     return(Jobs.Any(x => x.ID == id));
 }
예제 #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="jobId"></param>
 /// <returns></returns>
 public bool HasJob(int jobId)
 {
     return(Jobs.Any(job => job.JobId == jobId));
 }
예제 #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="skillId"></param>
 /// <returns></returns>
 public bool HasSkill(int skillId)
 {
     return(Jobs.Any(job => job.HasSkill(m_character, skillId)));
 }