public static void InicializeTodayTasks() { _tournamentRepo = new TournamentRepository(); ServerConfig.SynchronizeData = true; todayTasks = new List<TodaySystemTask>(); DateTime today = DateTime.Now; LastSynchronized = today; //TURNIEJE START var startTour = _tournamentRepo.Tournaments .Where(x => !x.IsActive) .Where(x => x.StartDate.Date == today.Date && x.IsConfigured) .Where(x => x.StartDate.TimeOfDay > today.TimeOfDay); if (startTour != null) { foreach (var item in startTour) { var task = new TodaySystemTask(); task.TaskId = item.Id; task.FlagSwitch += SetTournament; task.ExecuteTime = item.StartDate; task.Flag = true; task.TaskType = TaskType.StartTournament; todayTasks.Add(task); } } //TURNIEJE STOP var endTour = _tournamentRepo.Tournaments .Where(x => x.EndDate.Date == today.Date && x.IsConfigured) .Where(x => x.EndDate.TimeOfDay > today.TimeOfDay) .Where(x => x.IsActive); if (endTour != null) { foreach (var item in endTour) { var task = new TodaySystemTask(); task.TaskId = item.Id; task.FlagSwitch += SetTournament; task.ExecuteTime = item.EndDate; task.Flag = false; task.TaskType = TaskType.EndTournament; todayTasks.Add(task); } } //ZADANIA START var startTasks = _tournamentRepo.Tasks .Where(x => x.StartDate.Date == today.Date) .Where(x => x.Tournament.IsActive); foreach (var item in startTasks) { if (item.Order == 1) { var activePhase = new TodaySystemTask(); var activeTask = new TodaySystemTask(); activeTask.TaskId = item.Id; activeTask.Flag = true; activeTask.ExecuteTime = item.StartDate; activeTask.FlagSwitch += SetTask; activeTask.TaskType = TaskType.StartTask; activePhase.TaskId = item.PhaseId; activePhase.Flag = true; activePhase.ExecuteTime = item.StartDate; activePhase.FlagSwitch += SetPhase; activePhase.TaskType = TaskType.StartPhase; if (item.Phase.Order != 1) { var setPromo = new TodaySystemTask(); setPromo.TournamentId = item.TournamentId; setPromo.PhaseId = item.PhaseId; setPromo.ExecuteTime = item.StartDate; setPromo.CountScores += SetPromotions; setPromo.TaskType = TaskType.SetPromotions; todayTasks.Add(setPromo); } todayTasks.Add(activeTask); todayTasks.Add(activePhase); } else { var activeTask = new TodaySystemTask(); activeTask.TaskId = item.Id; activeTask.Flag = true; activeTask.ExecuteTime = item.StartDate; activeTask.FlagSwitch += SetTask; activeTask.TaskType = TaskType.StartTask; todayTasks.Add(activeTask); } } //ZADANIA KTÓRE STARTUJA W DNIU STARTU TURNIEJU var startTaskSameDayWithTour = _tournamentRepo.Tasks .Where(x => x.StartDate.Date == today.Date) .Where(x => x.Tournament.StartDate.Date == today.Date) .Where(x => x.Tournament.IsConfigured); foreach (var item in startTaskSameDayWithTour) { var activeTask = new TodaySystemTask(); var activePhase = new TodaySystemTask(); activeTask.TaskId = item.Id; activeTask.Flag = true; activeTask.ExecuteTime = item.StartDate; activeTask.FlagSwitch += SetTask; activeTask.TaskType = TaskType.StartTask; activePhase.TaskId = item.PhaseId; activePhase.Flag = true; activePhase.ExecuteTime = item.StartDate; activePhase.FlagSwitch += SetPhase; activePhase.TaskType = TaskType.StartPhase; todayTasks.Add(activeTask); todayTasks.Add(activePhase); } //ZADANIA STOP var endTask = _tournamentRepo.Tasks .Where(x => x.EndDate.Date == today.Date) .Where(x => x.Tournament.IsActive); foreach (var item in endTask) { if (item.Order == item.Phase.MaxTasks) { var disableTask = new TodaySystemTask(); var disablePhase = new TodaySystemTask(); var countScore = new TodaySystemTask(); disableTask.TaskId = item.Id; disableTask.ExecuteTime = item.EndDate; disableTask.Flag = false; disableTask.FlagSwitch += SetTask; disableTask.TaskType = TaskType.EndTask; disablePhase.TaskId = item.PhaseId; disablePhase.ExecuteTime = item.EndDate; disablePhase.Flag = false; disablePhase.FlagSwitch += SetPhase; disablePhase.TaskType = TaskType.EndPhase; countScore.PhaseId = item.PhaseId; countScore.ExecuteTime = item.EndDate; countScore.TournamentId = item.TournamentId; countScore.CountScores += CountScores; countScore.TaskType = TaskType.ScoreCount; todayTasks.Add(disablePhase); todayTasks.Add(disableTask); todayTasks.Add(countScore); } else { var disableTask = new TodaySystemTask(); disableTask.TaskId = item.Id; disableTask.ExecuteTime = item.EndDate; disableTask.Flag = false; disableTask.FlagSwitch += SetTask; disableTask.TaskType = TaskType.EndTask; todayTasks.Add(disableTask); } } ServerConfig.SynchronizeData = false; }
public static void InicializeTodayTasks() { _tournamentRepo = new TournamentRepository(); ServerConfig.SynchronizeData = true; todayTasks = new List <TodaySystemTask>(); DateTime today = DateTime.Now; LastSynchronized = today; //TURNIEJE START var startTour = _tournamentRepo.Tournaments .Where(x => !x.IsActive) .Where(x => x.StartDate.Date == today.Date && x.IsConfigured) .Where(x => x.StartDate.TimeOfDay > today.TimeOfDay); if (startTour != null) { foreach (var item in startTour) { var task = new TodaySystemTask(); task.TaskId = item.Id; task.FlagSwitch += SetTournament; task.ExecuteTime = item.StartDate; task.Flag = true; task.TaskType = TaskType.StartTournament; todayTasks.Add(task); } } //TURNIEJE STOP var endTour = _tournamentRepo.Tournaments .Where(x => x.EndDate.Date == today.Date && x.IsConfigured) .Where(x => x.EndDate.TimeOfDay > today.TimeOfDay) .Where(x => x.IsActive); if (endTour != null) { foreach (var item in endTour) { var task = new TodaySystemTask(); task.TaskId = item.Id; task.FlagSwitch += SetTournament; task.ExecuteTime = item.EndDate; task.Flag = false; task.TaskType = TaskType.EndTournament; todayTasks.Add(task); } } //ZADANIA START var startTasks = _tournamentRepo.Tasks .Where(x => x.StartDate.Date == today.Date) .Where(x => x.Tournament.IsActive); foreach (var item in startTasks) { if (item.Order == 1) { var activePhase = new TodaySystemTask(); var activeTask = new TodaySystemTask(); activeTask.TaskId = item.Id; activeTask.Flag = true; activeTask.ExecuteTime = item.StartDate; activeTask.FlagSwitch += SetTask; activeTask.TaskType = TaskType.StartTask; activePhase.TaskId = item.PhaseId; activePhase.Flag = true; activePhase.ExecuteTime = item.StartDate; activePhase.FlagSwitch += SetPhase; activePhase.TaskType = TaskType.StartPhase; if (item.Phase.Order != 1) { var setPromo = new TodaySystemTask(); setPromo.TournamentId = item.TournamentId; setPromo.PhaseId = item.PhaseId; setPromo.ExecuteTime = item.StartDate; setPromo.CountScores += SetPromotions; setPromo.TaskType = TaskType.SetPromotions; todayTasks.Add(setPromo); } todayTasks.Add(activeTask); todayTasks.Add(activePhase); } else { var activeTask = new TodaySystemTask(); activeTask.TaskId = item.Id; activeTask.Flag = true; activeTask.ExecuteTime = item.StartDate; activeTask.FlagSwitch += SetTask; activeTask.TaskType = TaskType.StartTask; todayTasks.Add(activeTask); } } //ZADANIA KTÓRE STARTUJA W DNIU STARTU TURNIEJU var startTaskSameDayWithTour = _tournamentRepo.Tasks .Where(x => x.StartDate.Date == today.Date) .Where(x => x.Tournament.StartDate.Date == today.Date) .Where(x => x.Tournament.IsConfigured); foreach (var item in startTaskSameDayWithTour) { var activeTask = new TodaySystemTask(); var activePhase = new TodaySystemTask(); activeTask.TaskId = item.Id; activeTask.Flag = true; activeTask.ExecuteTime = item.StartDate; activeTask.FlagSwitch += SetTask; activeTask.TaskType = TaskType.StartTask; activePhase.TaskId = item.PhaseId; activePhase.Flag = true; activePhase.ExecuteTime = item.StartDate; activePhase.FlagSwitch += SetPhase; activePhase.TaskType = TaskType.StartPhase; todayTasks.Add(activeTask); todayTasks.Add(activePhase); } //ZADANIA STOP var endTask = _tournamentRepo.Tasks .Where(x => x.EndDate.Date == today.Date) .Where(x => x.Tournament.IsActive); foreach (var item in endTask) { if (item.Order == item.Phase.MaxTasks) { var disableTask = new TodaySystemTask(); var disablePhase = new TodaySystemTask(); var countScore = new TodaySystemTask(); disableTask.TaskId = item.Id; disableTask.ExecuteTime = item.EndDate; disableTask.Flag = false; disableTask.FlagSwitch += SetTask; disableTask.TaskType = TaskType.EndTask; disablePhase.TaskId = item.PhaseId; disablePhase.ExecuteTime = item.EndDate; disablePhase.Flag = false; disablePhase.FlagSwitch += SetPhase; disablePhase.TaskType = TaskType.EndPhase; countScore.PhaseId = item.PhaseId; countScore.ExecuteTime = item.EndDate; countScore.TournamentId = item.TournamentId; countScore.CountScores += CountScores; countScore.TaskType = TaskType.ScoreCount; todayTasks.Add(disablePhase); todayTasks.Add(disableTask); todayTasks.Add(countScore); } else { var disableTask = new TodaySystemTask(); disableTask.TaskId = item.Id; disableTask.ExecuteTime = item.EndDate; disableTask.Flag = false; disableTask.FlagSwitch += SetTask; disableTask.TaskType = TaskType.EndTask; todayTasks.Add(disableTask); } } ServerConfig.SynchronizeData = false; }