private void updateEdsmConfiguration() { StarMapConfiguration edsmConfiguration = new StarMapConfiguration(); if (!string.IsNullOrWhiteSpace(edsmApiKeyTextBox.Text)) { edsmConfiguration.apiKey = edsmApiKeyTextBox.Text.Trim(); } if (!string.IsNullOrWhiteSpace(edsmCommanderNameTextBox.Text)) { edsmConfiguration.commanderName = edsmCommanderNameTextBox.Text.Trim(); } edsmConfiguration.ToFile(); EDDI.Instance.Reload("EDSM responder"); }
/// <summary> /// Obtain the EDSM log and sync it with the local datastore /// </summary> private async void edsmObtainLogClicked(object sender, RoutedEventArgs e) { StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile(); if (string.IsNullOrEmpty(starMapConfiguration.apiKey)) { edsmFetchLogsButton.IsEnabled = false; edsmFetchLogsButton.Content = Properties.EDSMResources.log_button_empty_api_key; return; } string commanderName; if (string.IsNullOrEmpty(starMapConfiguration.commanderName)) { // Fetch the commander name from the companion app Commander cmdr = EDDI.Instance.Cmdr; if (cmdr != null && cmdr.name != null) { commanderName = cmdr.name; } else { edsmFetchLogsButton.IsEnabled = false; edsmFetchLogsButton.Content = Properties.EDSMResources.log_button_companion_unconfigured; return; } } else { commanderName = starMapConfiguration.commanderName; } edsmFetchLogsButton.IsEnabled = false; edsmFetchLogsButton.Content = Properties.EDSMResources.log_button_fetching; var progress = new Progress <string>(s => edsmFetchLogsButton.Content = s); IEdsmService edsmService = new StarMapService(); await Task.Factory.StartNew(() => obtainEdsmLogs(edsmService, progress), TaskCreationOptions.LongRunning); starMapConfiguration.lastFlightLogSync = DateTime.UtcNow; starMapConfiguration.ToFile(); }
/// <summary> /// Obtain the EDSM log and sync it with the local datastore /// </summary> private async void edsmObtainLogClicked(object sender, RoutedEventArgs e) { StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile(); if (string.IsNullOrEmpty(starMapConfiguration.apiKey)) { edsmFetchLogsButton.IsEnabled = false; edsmFetchLogsButton.Content = "Please enter EDSM API key to obtain log"; return; } string commanderName; if (string.IsNullOrEmpty(starMapConfiguration.commanderName)) { // Fetch the commander name from the companion app Commander cmdr = EDDI.Instance.Cmdr; if (cmdr != null && cmdr.name != null) { commanderName = cmdr.name; } else { edsmFetchLogsButton.IsEnabled = false; edsmFetchLogsButton.Content = "EDSM API not configured; cannot obtain logs"; return; } } else { commanderName = starMapConfiguration.commanderName; } edsmFetchLogsButton.IsEnabled = false; edsmFetchLogsButton.Content = "Obtaining log..."; var progress = new Progress <string>(s => edsmFetchLogsButton.Content = s); await Task.Factory.StartNew(() => obtainEdsmLogs(starMapConfiguration, commanderName, progress), TaskCreationOptions.LongRunning); starMapConfiguration.lastSync = DateTime.UtcNow; starMapConfiguration.ToFile(); }