/// <summary> /// Occurs after user triggers download event. /// </summary> /// <param name="obj">The object.</param> private async void Download(object obj) { var dialog = new SaveFileDialog() { Filter = "Text file (.txt)|*.txt", FileName = SelectedRemoteProgram.Name }; if (dialog.ShowDialog().GetValueOrDefault(false)) { DialogHostIsOpen = true; var host = CreateDialogHost(true, $"Downloading {SelectedRemoteProgram.Name}"); var program = await programService.DownloadProgram(SelectedRemoteProgram, host.CancellationToken); var programWithoutLineNumbers = ProgramContentConverter.ToPC(program.Content); program.Content = programWithoutLineNumbers; File.WriteAllText(dialog.FileName, program.Content); } DialogHostIsOpen = false; }
/// <summary> /// Occurs after user triggers upload event. /// </summary> /// <param name="obj">The object.</param> private async void Upload(object obj) { var dialog = new OpenFileDialog { Filter = "Text files (.txt)|*.txt", CheckFileExists = true }; if (dialog.ShowDialog().GetValueOrDefault(false)) { var path = dialog.FileName; if (string.IsNullOrWhiteSpace(path) || Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute)) { return; } var name = Path.GetFileNameWithoutExtension(path); var content = File.ReadAllText(dialog.FileName); var program = new Program(name) { Content = content }; DialogHostIsOpen = true; uploadDialog = new DialogHost(); uploadDialog.CurrentAction = "Preparing upload"; uploadDialog.Message = "Please wait..."; uploadDialog.CurrentProgress = "0%"; DialogHost = uploadDialog; //only temporary var contentWithLineNumbers = ProgramContentConverter.ToManipulator(program.Content); program.Content = contentWithLineNumbers; await programService.UploadProgram(program, uploadDialog.CancellationToken); } }