private async Task <bool> FillTerminalFilesTreeAsync(TerminalFile terminalFileParent) { if (terminalFileParent.IsDirectory) { using (HttpClient httpClient = new HttpClient()) { AuthenticationHeaderValue authenticationHeaderValue = new AuthenticationHeaderValue(this.CredentialsMethod, this.CredentialsBase64); httpClient.DefaultRequestHeaders.Authorization = authenticationHeaderValue; httpClient.Timeout = new TimeSpan(0, 0, Settings.Default.TerminalConnectionTimeoutSeconds); HttpResponseMessage result = null; try { if (!cancellationToken.IsCancellationRequested) { result = await httpClient.GetAsync(terminalFileParent.FullPath, HttpCompletionOption.ResponseContentRead, this.cancellationToken.Token); } else { return(false); } } catch (HttpRequestException exception) { MessageBox.Show($"Nie udało się pobrać listy plików. Wyjątek: \n{GetAllMessages(exception)}", "Terminal", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (TaskCanceledException exception) { if (!exception.CancellationToken.IsCancellationRequested) { MessageBox.Show($"Upłynął limit czasu żądania. Wyjątek: \n{GetAllMessages(exception)}", "Terminal", MessageBoxButton.OK, MessageBoxImage.Error); } return(false); } if (result != null && result.IsSuccessStatusCode) { string responseBody = await result.Content.ReadAsStringAsync(); List <TerminalFile> terminalFiles = this.ParseHtmlForUsbFiles(responseBody); terminalFileParent.Children = terminalFiles; foreach (TerminalFile terminalFile in terminalFiles) { await FillTerminalFilesTreeAsync(terminalFile); } } else { MessageBox.Show($"Nie udało się pobrać listy plików. Http status: {result.StatusCode} {result.ReasonPhrase}", "Terminal", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } } return(true); }
void SetupFileSystems() { TerminalFile helloWorld = new TerminalFile("Hello World!", "This is the first file ever made in this universe, hello world."); TerminalFolder desktop = new TerminalFolder("Desktop", null, new TerminalFile[] { helloWorld }); TerminalDrive c = new TerminalDrive("C", new TerminalFolder[] { desktop }); TerminalFileSystem terminal1 = new TerminalFileSystem(1, new TerminalDrive[] { c }); SaveSystem.SaveFileSystem(terminal1); }
private async void GetTerminalFilesTreeAsync() { IsConnecting = true; this.TerminalFiles.Clear(); TerminalFile terminalFile = await Task.Run(() => this.terminalService.GetTerminalFilesTreeAsync()); IsConnecting = false; if (terminalFile != null) { this.TerminalFiles.Add(terminalFile); } }
public async Task <TerminalFile> GetTerminalFilesTreeAsync() { terminalFileRoot = new TerminalFile("/disk/usb1", BaseAddress, "/disk/usb1", true); cancellationToken = new CancellationTokenSource(); var result = await this.FillTerminalFilesTreeAsync(terminalFileRoot); if (result && !cancellationToken.IsCancellationRequested) { return(terminalFileRoot); } else { return(null); } }
private void TreeViewSelectItemCommandAction(object obj) { TerminalFile terminalFile = obj as TerminalFile; SelectedTerminalFile = terminalFile; }