/// <summary> /// Logic that defines the behaviour for the Login command. /// This uses the _apiService to LoginAsync with a LoginDTO, it also displays an error if something goes wrong and updates the Customer object if login is successful /// </summary> private async void OnLoginCommand() { User customer = User.GetCustomer(); if (!customer.LoggedIn) { LoginDTO dto = new LoginDTO() { Username = Username, Password = Password, }; try { string token = await RestClient.LoginAsync(dto); if (token != null) { customer.UserToken = token; customer.UserName = Username; Application.Current.Properties["Token"] = customer.UserToken; Application.Current.Properties["Username"] = customer.UserName; BarRepresentative barrep = await RestClient.GetSpecificBarRepresentative(customer.UserName); if (barrep.Name != null) { customer.FavoriteBar = barrep.BarName; customer.IsBarRep = true; } await NavigationService.GoBackAsync(); } else { await Alerter.Alert("Error", "Something went wrong in the login!", "OK"); } } catch (Exception e) { await Alerter.Alert("Error", e.Message, "OK"); } } }
/// <summary> /// Logic that defines behaviour for the Signup action /// </summary> private async void OnSignupCommand() { try { if (confpass == password) { RegisterDTO dto = new RegisterDTO() { Email = email, Username = username, Password = password, Name = name, DateOfBirth = birthday, FavoriteBar = null, FavoriteDrink = null, }; bool result = await RestClient.RegisterAsync(dto); if (result) { await Alerter.Alert("Notice", "Your account has been registered!", "OK"); await _navigationService.GoBackAsync(); } else { await Alerter.Alert("Error", "Something went wrong in the registration!", "OK"); } } else { await Alerter.Alert("Error", "Passwords do not match!", "OK"); } } catch (Exception e) { await Alerter.Alert("Error", e.Message, "OK"); } }
public void SendAlerts(List <MemoryObject> memories) { foreach (var memory in memories) { if (memory.UsedPercentage >= 90) { _alerter.Alert($"Memory usage is {memory.UsedPercentage}."); } } }
public async Task RunAsync() { try { _logger.Log("Hello World! Welcome to the Cassandra Backup & Restore tool"); _logger.Log("BACKUP & RESTORE ALL THE THINGS!!!!"); // Create Backup Timestamp DateTime backupTimestamp = DateTime.UtcNow; // Create connection _logger.Log("Connecting to Cassandra cluster..."); if (_cassandraConfiguration.UserName?.Length > 0 || _cassandraConfiguration.Password?.Length > 0) { _logger.Log("Using username & password"); } var cluster = _cassandraService.GetCluster(_cassandraConfiguration.HostName, _cassandraConfiguration.UserName, _cassandraConfiguration.Password); var session = await _cassandraService.GetConnectionAsync(cluster); _logger.Log("Connected to Cassandra cluster..."); // Setup backup directory var backupDirectoryInfo = new DirectoryInfo(_backupConfiguration.BackupTargetFolder); if (!backupDirectoryInfo.Exists) { _logger.Log("Backup target folder does not exist. Creating."); backupDirectoryInfo.Create(); _logger.Log("Backup target folder created"); } if (_backupConfiguration.EmptyBackupTargetFolderBeforeBackingUp) { _logger.Log("Cleaning backup folder before starting backup"); CleanDirectory(backupDirectoryInfo); _logger.Log("Cleaned backup folder before starting backup"); } // Fetch all tables _logger.Log("Fetching all tables"); var allTableRowSet = await _cassandraService.GetAllTablesAsync(session); _logger.Log("Fetched all tables"); foreach (var tableRow in allTableRowSet) { string keyspaceName = tableRow.GetValue <string>("keyspace_name"); string tableName = tableRow.GetValue <string>("table_name"); string fullTableName = $"{keyspaceName}.{tableName}"; // Check if we need to skip this table (Exclude list) if (_patternMatching.IsInList(fullTableName, _backupConfiguration.ExcludeList)) { _logger.Log("Skipping. This table matches the exclude list", fullTableName); continue; } await DoBackupTable(cluster, session, _cassandraConfiguration.HostName, _cassandraConfiguration.UserName, _cassandraConfiguration.Password, backupTimestamp, keyspaceName, tableName, fullTableName); } if (!string.IsNullOrEmpty(_backupArchivingConfiguration.ArchiveFolder)) { _logger.Log("Archiving"); var archiveDirectoryInfo = new DirectoryInfo(_backupArchivingConfiguration.ArchiveFolder); if (!archiveDirectoryInfo.Exists) { archiveDirectoryInfo.Create(); } var timestampedArchiveDirectory = new DirectoryInfo($"{_backupArchivingConfiguration.ArchiveFolder}/{backupTimestamp.ToString(_backupConfiguration.CompressTimestampFormat)}"); if (!timestampedArchiveDirectory.Exists) { timestampedArchiveDirectory.Create(); } CopyAll(backupDirectoryInfo, timestampedArchiveDirectory); _logger.Log("Archived"); if (_backupArchivingConfiguration.KeepNumberOfArchives > 0) { _logger.Log("Old archive cleanup"); List <DirectoryInfo> timestampedArchiveDirectories = archiveDirectoryInfo.GetDirectories().OrderByDescending(x => x.CreationTime).ToList(); for (int i = _backupArchivingConfiguration.KeepNumberOfArchives; i < timestampedArchiveDirectories.Count; i++) { timestampedArchiveDirectories[i].Delete(true); } _logger.Log("Finished old archive cleanup"); } } _logger.Log("Done!"); } catch (Exception ex) { _logger.Error(ex.ToString()); _alerter.Alert(ex.ToString(), AlertPriority.Low); throw; } }
public void CheckAndAlert(Battery batteryChar, double temperature) { BreachType breachType = CheckBreachLevel.ClassifyTemperatureBreach(batteryChar.CoolingType, temperature); AlertSource.Alert(breachType); }