public async void ExportChannel(Channel channel) { try { // Set busy state and indeterminate progress IsEnabled = false; Progress = -1; // Get last used token var token = _settingsService.LastToken; // Create dialog var dialog = _viewModelFactory.CreateExportSetupViewModel(); dialog.Guild = SelectedGuild; dialog.Channel = channel; // Show dialog, if canceled - return if (await _dialogManager.ShowDialogAsync(dialog) != true) { return; } // Create progress handler var progressHandler = new Progress <double>(p => Progress = p); // Get chat log var chatLog = await _dataService.GetChatLogAsync(token, dialog.Guild, dialog.Channel, dialog.From, dialog.To, progressHandler); // Export _exportService.ExportChatLog(chatLog, dialog.FilePath, dialog.SelectedFormat, dialog.PartitionLimit); // Notify completion Notifications.Enqueue("Export complete"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden) { Notifications.Enqueue("You don't have access to this channel"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Notifications.Enqueue("This channel doesn't exist"); } finally { // Reset busy state and progress Progress = 0; IsEnabled = true; } }
public async void ExportChannels() { // Get last used token var token = _settingsService.LastToken; // Create dialog var dialog = _viewModelFactory.CreateExportSetupViewModel(SelectedGuild, SelectedChannels); // Show dialog, if canceled - return if (await _dialogManager.ShowDialogAsync(dialog) != true) { return; } // Create a progress operation for each channel to export var operations = ProgressManager.CreateOperations(dialog.Channels.Count); // Export channels for (var i = 0; i < dialog.Channels.Count; i++) { // Get operation and channel var operation = operations[i]; var channel = dialog.Channels[i]; try { // Generate file path if necessary var filePath = dialog.OutputPath; if (ExportHelper.IsDirectoryPath(filePath)) { // Generate default file name var fileName = ExportHelper.GetDefaultExportFileName(dialog.SelectedFormat, dialog.Guild, channel, dialog.From, dialog.To); // Combine paths filePath = Path.Combine(filePath, fileName); } // Get chat log var chatLog = await _dataService.GetChatLogAsync(token, dialog.Guild, channel, dialog.From, dialog.To, operation); // Export _exportService.ExportChatLog(chatLog, filePath, dialog.SelectedFormat, dialog.PartitionLimit); // Notify completion Notifications.Enqueue($"Channel [{channel.Model.Name}] successfully exported"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.Forbidden) { Notifications.Enqueue($"You don't have access to channel [{channel.Model.Name}]"); } catch (HttpErrorStatusCodeException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Notifications.Enqueue($"Channel [{channel.Model.Name}] doesn't exist"); } finally { // Dispose progress operation operation.Dispose(); } } }