Пример #1
0
        public void CreateSchedule(ProgramMode pm)
        {
            if (pm == ProgramMode.XML)
            {
                this.GetDataFromXML();
            }
            else
            {
                this.GetDataFromDb();
            }

            this.CreatingClasses();

            List <Class> FirstGroup  = new List <Class>();
            List <Class> SecondGroup = new List <Class>();

            this.Dividing(FirstGroup, SecondGroup);

            this.create(0, FirstGroup);
            this.create(3, SecondGroup);

            if (pm == ProgramMode.Database)
            {
                ClassRepo.AddToDb(ResSchedule);
            }
            else if (pm == ProgramMode.XML)
            {
                ClassRepo.SerializeArray("../../Data/classes.xml", ResSchedule.ToArray());
            }
            else
            {
                ClassRepo.AddToDb(ResSchedule);
                ClassRepo.SerializeDb("../../Data/classes.xml");
            }
        }
Пример #2
0
        public DataRes <bool> Edit([FromBody] ResSchedule model)
        {
            var res = new DataRes <bool>()
            {
                code = ResCode.Success, data = true
            };

            try
            {
                using (var uow = _uowProvider.CreateUnitOfWork())
                {
                    var    repository = uow.GetRepository <ResSchedule>();
                    string us         = User.Claims.FirstOrDefault(p => p.Type.Equals(ClaimTypes.Sid)).Value;
                    int    userid     = Convert.ToInt32(us);
                    model.WriteUid  = userid;
                    model.WriteDate = DateTime.Now;
                    repository.Update(model);
                    uow.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                res.code = ResCode.Error;
                res.msg  = $"{ex.Message}:{ex.InnerException.Message}";
            }
            return(res);
        }
Пример #3
0
        public static async Task <BaseQuartzNetResult> ResumeScheduleAsync(ResSchedule resSchedule)
        {
            try
            {
                var jk = new JobKey(resSchedule.JobName, resSchedule.JobGroup);
                if (!await _scheduler.CheckExists(jk))
                {
                    return(QuartzHelper.addJobAsync(resSchedule).Result);
                }
                await QuartzHelper._scheduler.ResumeJob(jk);

                return(new BaseQuartzNetResult
                {
                    Code = 1000,
                    Msg = resSchedule.JobName + "重启任务成功"
                });
            }
            catch (Exception ex)
            {
                return(new BaseQuartzNetResult
                {
                    Code = -1,
                    Msg = resSchedule.JobName + "重启任务失败"
                });
            }
        }
Пример #4
0
        public static async Task <BaseQuartzNetResult> addJobAsync(ResSchedule resSchedule)
        {
            try
            {
                Assembly   assembly = Assembly.Load(new AssemblyName(resSchedule.AssemblyName));
                Type       type     = assembly.GetType(resSchedule.ClassName);
                IJobDetail job      = new JobDetailImpl(resSchedule.JobName, resSchedule.JobGroup, type);
                ITrigger   trigger  = TriggerBuilder.Create()
                                      .WithIdentity(resSchedule.JobName, resSchedule.JobGroup)
                                      .StartAt(resSchedule.BeginTime)
                                      .WithCronSchedule(resSchedule.Cron)//指定cron表达式
                                      .Build();
                await _scheduler.ScheduleJob(job, trigger);

                return(new BaseQuartzNetResult
                {
                    Code = 1000,
                    Msg = "启动成功"
                });
            }
            catch (Exception ex)
            {
                return(new BaseQuartzNetResult
                {
                    Code = -1
                });
            }
        }
Пример #5
0
        private void create(int DayShuffle, List <Class> Group)
        {
            List <Room> LectureRoom  = new List <Room>();
            List <Room> ComputerRoom = new List <Room>();
            List <Room> DefaultRoom  = new List <Room>();

            foreach (Room r in Rooms)
            {
                if (r.Type == ClassType.Lecture)
                {
                    LectureRoom.Add(r);
                }
                else if (r.Type == ClassType.Computer)
                {
                    ComputerRoom.Add(r);
                }
                else
                {
                    DefaultRoom.Add(r);
                }
            }
            Random rnd = new Random();

            foreach (Class c in Group)
            {
                if (DictionaryOfSubjects[c.SubjectId].Type == ClassType.Computer)
                {
                    int index = rnd.Next(ComputerRoom.Count);
                    c.RoomId = ComputerRoom[index].Id;
                }
                else if (DictionaryOfSubjects[c.SubjectId].Type == ClassType.Lecture)
                {
                    int index = rnd.Next(LectureRoom.Count);
                    c.RoomId = LectureRoom[index].Id;
                }
                else
                {
                    int index = rnd.Next(DefaultRoom.Count);
                    c.RoomId = DefaultRoom[index].Id;
                }
            }
            int          n = 15;
            List <Class> CalculatedClasses = new List <Class>();

            while (true)
            {
                if (generate(Group, n, CalculatedClasses))
                {
                    break;
                }
            }
            foreach (var cl in CalculatedClasses)
            {
                cl.Number += DayShuffle;
                ResSchedule.Add(cl);
            }
        }
Пример #6
0
 private void ResetAlgorithm()
 {
     ResSchedule?.Clear();
     Rooms?.Clear();
     Classes?.Clear();
     DictionaryOfSubjects?.Clear();
     DictionaryOfGroups?.Clear();
     Groups?.Clear();
     Subjects?.Clear();
     GroupSubjects?.Clear();
     Teachers?.Clear();
     TeacherSubjects?.Clear();
     ClassRepo.DeleteAllFromDb();
 }