Пример #1
0
        private void run (object state) {
            try {

                Dispatcher.Invoke(new Action(() => {
                    panelLogin.IsEnabled = false;
                    progressBarLoading.Visibility = Visibility.Visible;
                }));

                Database database = new Database { IpAddress = Settings.Default.databaseHost, Port = 3306, Username = Settings.Default.databaseUsername, Password = Settings.Default.databasePassword };
                query = new Query(database);

                displayMessage("Connecting to " + database.IpAddress + "...");

                query.getCompany(company);
                displayMessage("Checking Company...");

                query.getUser(company, user);
                displayMessage("Checking User...");


                if (user.AccessLevel != 1) {

                    int isExpired = company.DateTimeExpired.CompareTo(DateTime.Now);

                    if (isExpired == -1)
                        throw new QueryException(1, "This company is expired.");
                    if (!company.IsActive)
                        throw new QueryException(1, "Company is deactivated.");

                    isExpired = user.DateTimeExpired.CompareTo(DateTime.Now);

                    if (isExpired == -1)
                        throw new QueryException(1, "This user is expired.");
                    if (!user.IsActive)
                        throw new QueryException(1, "User is deactivated.");
                }
                //=============================Login successful
                query.fillUsers(company, user);
                displayMessage("Loading Users...");

                query.fillPois(company);
                displayMessage("Loading Pois...");

                query.fillGeofences(company);
                displayMessage("Loading Geofences...");

                query.fillCollection(company);
                displayMessage("Loading Collections...");

                query.fillTrackers(company);
                displayMessage("Loading Trackers...");


                Dispatcher.Invoke(new Action(() => {
                    Settings.Default.accountCompanyUsername = panelLogin.CompanyUsername;
                    Settings.Default.accountUsername = panelLogin.Username;
                    Settings.Default.accountPassword = panelLogin.Password;
                    Settings.Default.accountRememberMe = (bool)panelLogin.RememberMe;
                    Settings.Default.Save();
                    FormMain formMain = new FormMain(company, user, database);
                    formMain.Show();
                    this.Close();
                }));

            } catch (DatabaseException databaseException) {
                Debug.Print(databaseException.Message);
                displayMessage(databaseException.Message);
                TextLog.Write(databaseException);
            } catch (Exception exception) {
                Debug.Print(exception.Message);
                displayMessage(exception.Message);
                TextLog.Write(exception);
            } finally {
                Dispatcher.Invoke(new Action(() => {
                    panelLogin.IsEnabled = true;
                    progressBarLoading.Visibility = Visibility.Hidden;
                }));
            }
        }
Пример #2
0
        private void run(object state) {
            try {

                Dispatcher.Invoke(new Action(() => {
                    panelLogin.IsEnabled = false;
                    progressBarLoading.Visibility = Visibility.Visible;
                }));
           
                Database database = new Database { IpAddress = Settings.Default.databaseHost, Username = Settings.Default.databaseUsername, Password = Settings.Default.databasePassword };
                query = new Query(database);


                companies = query.getCompanies();
                //query.fillGeofences(company);
                //users = query.getUsers(company, user);
                int count = 0;
                foreach (Company companyItem in companies) {
                    query.getUser(companyItem, user);
                    //users = query.fillUsers(companyItem, user);
                    //companyItem.Trackers = query.getTrackers(companyItem, users);
                    Dispatcher.Invoke(new Action(() => {
                        panelLogin.ErrorNote = "Loading companies... " + (++count).ToString() + "/" + companies.Count.ToString();
                    }));
                }


                Dispatcher.Invoke(new Action(() => {
                    Settings.Default.accountCompanyUsername = panelLogin.CompanyUsername;
                    Settings.Default.accountUsername = panelLogin.Username;
                    Settings.Default.accountPassword = panelLogin.Password;
                    Settings.Default.accountRememberMe = (bool)panelLogin.RememberMe;
                    Settings.Default.Save();
                    FormMain formMain = new FormMain(company, user, companies, database);
                    formMain.Show();
                    this.Close();
                }));

            } catch (DatabaseException databaseException) {
                Debug.Print(databaseException.Message);
                Dispatcher.Invoke(new Action(() => {
                    panelLogin.ErrorNote = databaseException.Message;
                    TextLog.Write(databaseException);
                }));
            } catch (Exception exception) {
                Debug.Print(exception.Message);
                Dispatcher.Invoke(new Action(() => {
                    panelLogin.ErrorNote = exception.Message;
                    TextLog.Write(exception);
                }));
            } finally {
                Dispatcher.Invoke(new Action(() => {
                    panelLogin.IsEnabled = true;
                    progressBarLoading.Visibility = Visibility.Hidden;
                }));
            }
        }