private void threadMysqlTestFunc () { try { Database database = new Database() { IpAddress = Settings.Default.databaseHost, Username = Settings.Default.databaseUsername, Password = Settings.Default.databasePassword, Port = Settings.Default.databasePort }; Query query = new Query(database); query.checkConnection(); Dispatcher.Invoke(new Action(() => { MessageBox.Show("Successful", "Successful", MessageBoxButton.OK, MessageBoxImage.Information); })); } catch (DatabaseException databaseException) { Dispatcher.Invoke(new Action(() => { MessageBox.Show(databaseException.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); })); } catch (Exception exception) { Dispatcher.Invoke(new Action(() => { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); })); } }
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; })); } }
private void asyncTrackerUpdate (object state) { Task.Run(() => { try { lock (threadProperties) { threadProperties.CurrentThreadCount++; } TrackerItem trackerItem = (TrackerItem)state; Query query = new Query(database); TrackerData trackerData; if (trackerItem.IsChecked) { //trackerData = query.getTrackerLatestData(company, trackerItem.getTracker()); trackerData = query.getTrackerLatestData(company, trackerItem.getTracker(), server); } else { trackerData = new TrackerData(); trackerData.Tracker = trackerItem.getTracker(); trackerData.IsDataEmpty = true; Dispatcher.Invoke(new Action(() => { for (int index = 0; listViewTrackersData.Items.Count > index; index++) { TrackerData trackerDataItem = (TrackerData)listViewTrackersData.Items[index]; if (trackerDataItem.Tracker.Id == trackerData.Tracker.Id) { listViewTrackersData.Items.RemoveAt(index); } } })); } Dispatcher.Invoke(new Action(() => { if (!webBrowserMap.IsLoaded) { lock (threadProperties) { threadProperties.CurrentThreadCount--; } return; } //lock (map) { try { map.loadTracker(webBrowserMap, trackerItem, trackerData, (string)ribbonGalleryComboBoxDisplayMember.SelectedValue); } catch (Exception exception) { TextLog.Write(exception); } //} if (trackerItem.IsChecked) { bool isExisting = false; for (int index = 0; listViewTrackersData.Items.Count > index; index++) { TrackerData trackerDataItem = (TrackerData)listViewTrackersData.Items[index]; if (trackerDataItem.Tracker.Id == trackerData.Tracker.Id) { listViewTrackersData.Items.RemoveAt(index); listViewTrackersData.Items.Insert(index, trackerData); isExisting = true; break; } } if (isExisting == false) { listViewTrackersData.Items.Add(trackerData); } } })); lock (threadProperties) { threadProperties.CurrentThreadCount--; } } catch (Exception exception) { Debug.Print(exception.Message); } }); }
private void threadMysqlTestFunc () { try { Database database = new Database { IpAddress = Settings.Default.DatabaseIp, Port = Int32.Parse(Settings.Default.DatabasePort), DatabaseName = Settings.Default.DatabaseName, Username = Settings.Default.DatabaseUsername, Password = Settings.Default.DatabasePassword }; Query query = new Query(database); query.checkConnection(); Dispatcher.Invoke(new Action(() => { MessageBox.Show("Successful...", "Successful", MessageBoxButton.OK, MessageBoxImage.Information); })); } catch (Exception exception) { Dispatcher.Invoke(new Action(() => { MessageBox.Show(exception.Message, "Failed", MessageBoxButton.OK, MessageBoxImage.Error); })); } }
private void processBufferIn (Object state) { TcpManager tcpManager = (TcpManager)state; while (!tcpManager.BufferIn.IsEmpty) { Database database = new Database { IpAddress = Settings.Default.DatabaseIp, Port = Int32.Parse(Settings.Default.DatabasePort), DatabaseName = Settings.Default.DatabaseName, Username = Settings.Default.DatabaseUsername, Password = Settings.Default.DatabasePassword }; Query query = null; Object obj = null; Gm gm = null; Tracker tracker = null; //Get data from the buffer. if (!tcpManager.BufferIn.TryDequeue(out obj)) continue; //Cast Obj into Gm try { gm = null; gm = (Gm)obj; if (gm == null) { return; } } catch (Exception exception) { if (debug) { TextLog.Write(exception); } return; } //Check Database Connection try { query = new Query(database); query.checkConnection(); } catch (Exception exception) { object object1 = obj; tcpManager.BufferIn.Enqueue(obj); if (debug) { TextLog.Write(exception); } continue; } //Check tracker if registered to the database, return try { tracker = query.getTracker(gm.Unit); } catch (Exception exception) { if (debug) { TextLog.Write(exception); } continue; } //Insert Data to the database server try { query.insertTrackerData(tracker, gm); } catch (Exception exception) { if (debug) { TextLog.Write(exception); } } Thread.Sleep(10); } }
private void optimizeDatabase(object state) { TrackerDatabaseSizeItem trackerDatabaseSizeItem = (TrackerDatabaseSizeItem)state; try { Query query = new Query(database); TrackerDatabaseSize trackerDatabaseSize = query.getDatabaseSize(trackerDatabaseSizeItem.Name); trackerDatabaseSizeItem.TrackerDatabaseSize = trackerDatabaseSize; trackerDatabaseSizeItem.Status = MaintenanceServerStatus.DONE; trackerDatabaseSizeItem.DateTimeUpdated = DateTime.Now; } catch (Exception exception) { MaintenanceServerLog maintenanceServerLog = new MaintenanceServerLog(); maintenanceServerLog.Status = MaintenanceServerStatus.ERROR; maintenanceServerLog.Description = exception.Message; log(maintenanceServerLog); trackerDatabaseSizeItem.DateTimeUpdated = DateTime.Now; trackerDatabaseSizeItem.Status = MaintenanceServerStatus.ERROR; } finally { threadProperties.CurrentThreadCount++; if (threadProperties.CurrentThreadCount == threadProperties.MaxThreadCount) { MaintenanceServerLog maintenanceServerLog = new MaintenanceServerLog(); maintenanceServerLog.Status = MaintenanceServerStatus.DONE; maintenanceServerLog.Description = "Optimizing " + threadProperties.CurrentThreadCount + " databases are done."; log(maintenanceServerLog); } Dispatcher.Invoke(new Action(() => { dataGrid.Items.Refresh(); })); } }
private void getDatabaseSizes(object state) { Query query = new Query(database); trackerDatabaseSizes = query.getDatabasesSize(); ConcurrentQueue<TrackerDatabaseSizeItem> trackerDatabaseSizeItems = new ConcurrentQueue<TrackerDatabaseSizeItem>(); foreach (TrackerDatabaseSize trackerDatabaseSizeItem in trackerDatabaseSizes) { trackerDatabaseSizeItems.Enqueue(new TrackerDatabaseSizeItem(trackerDatabaseSizeItem)); } Dispatcher.BeginInvoke(new Action(() => { DataTemplate dataTemplate = (DataTemplate)Application.Current.Resources["listViewTrackersDatabaseSize"]; dataGrid.ItemTemplate = dataTemplate; dataGrid.ItemsSource = trackerDatabaseSizeItems; TabItem tabPage = new TabItem(); tabPage.Header = "Databases"; tabPage.Content = dataGrid; tabControl.Items.Add(tabPage); })); }
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; })); } }