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);
        }