Example #1
0
        async Task StartChecking()
        {
            Dispatcher.Invoke(() =>
            {
                lblRegestrationStatus.Content    = "Unknown";
                lblRegestrationStatus.Foreground = Brushes.Orange;
            });
            _user = await RegnewUser.Login(Dispatcher.Invoke(() => txtUserName.Text), Dispatcher.Invoke(() => txtPassword.Password), false);

            if (_user is null)
            {
                Dispatcher.Invoke(() => MessageBox.Show("CANT LOGIN.", "FATAL ERROR", MessageBoxButton.OK, MessageBoxImage.Error));
                StopProcess();
            }

            await Dispatcher.Invoke(async() =>
            {
                _lstClassesModels.Clear();
                USchedule schedule = await USchedule.FromFile(txtSchedulePath.Text);
                foreach (var cls in schedule.Classes.OrderByDescending(c => c.Capacity - c.NumberOfRegisteredStudents))
                {
                    var classModel = new UClassClassesListModel(cls)
                    {
                        Status = "Waiting",
                        StatusForegroundBrush = Brushes.Black
                    };
                    _lstClassesModels.Add(classModel);
                }
            });

            _regestrationStatusTimer = new Timer(RegestrationStatusTimerCallback, null, TimeSpan.Zero, tmeDelay.Value.Value);
        }
Example #2
0
        async Task <bool> VerfiyInfo()
        {
            //verify that all fields are entered
            if (string.IsNullOrWhiteSpace(txtUserName.Text))
            {
                MessageBox.Show("Please enter your username.", "Missing Data", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtPassword.Password))
            {
                MessageBox.Show("Please enter your password.", "Missing Data", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            if (string.IsNullOrWhiteSpace(txtSchedulePath.Text))
            {
                MessageBox.Show("Please enter your schedule path.", "Missing Data", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            if (tmeDelay.Value == null)
            {
                MessageBox.Show("Please the delay between checks.", "Missing Data", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            //login
            var testUser = await RegnewUser.Login(txtUserName.Text, txtPassword.Password, false);

            if (testUser is null)
            {
                MessageBox.Show("Invalid username or password.\r\nIn case you are sure about your username and password please login from the browser then try again.", "Can't login", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            //verify the existinse and validity of the schedule
            try
            {
                USchedule testSchedule = await USchedule.FromFile(txtSchedulePath.Text);
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Schedule file doesn't exist.", "Invalid Path", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception)
            {
                MessageBox.Show("Corrupt Schedule file.", "Corrupt File", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            //verify that the delay is not more than 5000ms
            if (tmeDelay.Value.Value.TotalMilliseconds > 5000 &&
                MessageBox.Show("The delay between the checks is too large.\r\nDo you want to proceed ?",
                                "Propably Invalid Data", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            {
                return(false);
            }
            return(true);
        }
        private USchedule GetTestSchedule()
        {
            var result = new USchedule();

            foreach (var uClass in s_testClasses)
            {
                result.Add(uClass);
            }
            return(result);
        }
Example #4
0
 public UScheduleListModel(USchedule src)
 {
     Source = src;
     DayOfWeek[] srcDays = src.Days.ToArray();
     Info               = $"{srcDays.Length} day{(srcDays.Length == 1 ? string.Empty : "s")} | {Source.FinancialHours} hour";
     ClassesModels      = Source.Classes.OrderBy(x => s_daysEqualityComparer.GetHashCode(x.Days)).ThenBy(c => c.StartTime).ThenBy(c => c.EndTime).Select(c => new UClassListModel(c)).ToArray();
     Days               = DayOfWeekConverter.ToString(srcDays);
     FinancialHours     = Source.FinancialHours.ToString();
     FirstStartTime     = Source.FirstStartTime.ToString("hh\\:mm");
     LastEndTime        = Source.LastEndTime.ToString("hh\\:mm");
     LongestDayDuration = Source.LongestDayDuration.ToString("hh\\:mm");
     MaximumBreaksTotal = Source.MaximumBreaksTotal.ToString("hh\\:mm");
 }
        public void MaximumBreak_UScheduleHasMultipleBreaks_ReturnsMaxBreak()
        {
            USchedule schedule = GetTestSchedule();

            Assert.Equal(schedule.MaximumBreaksTotal, TimeSpan.FromHours(4));
        }