Exemple #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);
        }
Exemple #2
0
        private async void BtnTestAccount_Click(object sender, RoutedEventArgs e)
        {
            txtUserName.IsEnabled = false;
            txtPassword.IsEnabled = false;
            try
            {
                if (string.IsNullOrWhiteSpace(txtUserName.Text))
                {
                    MessageBox.Show("Please enter your username.", "Missing Data", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if (string.IsNullOrWhiteSpace(txtPassword.Password))
                {
                    MessageBox.Show("Please enter your password.", "Missing Data", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                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);
                }
                else
                {
                    MessageBox.Show($"Logged in successfully as {testUser.Name}.", "Logged in successfully", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            finally
            {
                txtUserName.IsEnabled = true;
                txtPassword.IsEnabled = true;
            }
        }
Exemple #3
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);
        }
Exemple #4
0
 void CompleteRegistration()
 {
     Dispatcher.Invoke(() =>
     {
         _regestrationStatusTimer?.Dispose();
         _user = null;
         lblRegestrationStatus.Content    = "Unknown";
         lblRegestrationStatus.Foreground = Brushes.Orange;
         tabInfo.IsEnabled         = true;
         btnStartProcess.IsEnabled = true;
         btnStopProcess.IsEnabled  = true;
         MessageBox.Show("Registration is done.\r\nPlease open regnew and confirm your schedule.", "Done", MessageBoxButton.OK, MessageBoxImage.Information);
     });
 }
        private async void btnTest_Click(object sender, RoutedEventArgs e)
        {
            btnTest.IsEnabled = false;
            UClass[]  cls = JsonConvert.DeserializeObject <UClass[]>(File.ReadAllText(@"C:\Users\abdal\Desktop\Courses.json"));
            Stopwatch sw  = new Stopwatch();

            sw.Start();
            var user = await RegnewUser.Create("20170112", "C#8sQlC++", false);

            var reg = await user.RegisterClass(cls);

            sw.Stop();
            GC.Collect(3, GCCollectionMode.Forced, true);
            MessageBox.Show(string.Join <UClass>("\r\n", reg), "Registered classes.", MessageBoxButton.OK, MessageBoxImage.Information);
            MessageBox.Show($"It took {sw.ElapsedMilliseconds}ms to register {reg.Length} classes.", "Performance", MessageBoxButton.OK, MessageBoxImage.Information);
            btnTest.IsEnabled = true;
        }
Exemple #6
0
        void StopProcess()
        {
            _regestrationStatusTimer?.Dispose();
            //just to ensure that the timer has stopped
            Thread.Sleep(200);
            _user = null;

            Dispatcher.Invoke(() =>
            {
                _lstClassesModels.Clear();
                lblRegestrationStatus.Content    = "Unknown";
                lblRegestrationStatus.Foreground = Brushes.Orange;
                tabInfo.IsEnabled         = true;
                btnStartProcess.IsEnabled = true;
                btnStopProcess.IsEnabled  = true;
                MessageBox.Show("Regestration process is aborted.", "Aborted", MessageBoxButton.OK, MessageBoxImage.Warning);
            });
        }