private void BtnImportConnectionFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = QPDFILE_FILTER; var ret = ofd.ShowDialog(); if (ret == DialogResult.Cancel) { return; } try { var file = ofd.FileName; ConnectionInfo connectionInfo = QpdFileUtils.Load(file); connectionInfo.Name = Path.GetFileNameWithoutExtension(file); addConnection(connectionInfo); QpdFileUtils.SaveQpbFile(connectionInfo); MessageBox.Show("导入成功!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show($"导入失败,原因:{ExceptionUtils.GetExceptionMessage(ex)}", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public IActionResult Create([FromBody] CreateContainerConfig config) { try { string id = null; DockerClientUtils.UseDockerClient(client => { var ret = client.Containers.CreateContainerAsync(new CreateContainerParameters() { Shell = config.Shell, Entrypoint = config.Entrypoint, WorkingDir = config.WorkingDir, Volumes = config.Volumes, Image = config.Image, Cmd = config.Cmd, Env = config.Env, ExposedPorts = config.ExposedPorts, Name = config.Name, HostConfig = config.HostConfig, NetworkingConfig = config.NetworkingConfig }).Result; id = ret.ID; }); return(new ObjectResult(Get(id))); } catch (Exception ex) { return(base.StatusCode(500, $"Add Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}")); } }
private async void btnSend_Click(object sender, EventArgs e) { var commandRequestTypeName = txtCommandRequestTypeName.Text.Trim(); if (string.IsNullOrEmpty(commandRequestTypeName)) { txtCommandRequestTypeName.Focus(); return; } var requestContent = txtTestRequest.Text.Trim(); if (string.IsNullOrEmpty(requestContent)) { txtTestRequest.Focus(); return; } var qpClient = connectionContext.QpClient; if (qpClient == null) { txtTestResponse.AppendText($"{DateTime.Now.ToLongTimeString()}: 当前未连接,无法执行!{Environment.NewLine}"); return; } btnSend.Enabled = false; txtTestRequest.Focus(); txtTestResponse.Clear(); txtTestResponse.AppendText($"{DateTime.Now.ToLongTimeString()}: 开始执行...{Environment.NewLine}"); try { var ret = await qpClient.SendCommand(commandRequestTypeName, requestContent); if (txtTestResponse.IsDisposed) { return; } txtTestResponse.AppendText($"{DateTime.Now.ToLongTimeString()}: 执行成功{Environment.NewLine}"); txtTestResponse.AppendText($"命令响应类型:{ret.TypeName}{Environment.NewLine}"); txtTestResponse.AppendText($"响应内容{Environment.NewLine}"); txtTestResponse.AppendText($"--------------------------{Environment.NewLine}"); txtTestResponse.AppendText(ret.Content); } catch (Exception ex) { if (txtTestResponse.IsDisposed) { return; } txtTestResponse.AppendText($"{DateTime.Now.ToLongTimeString()}: 执行失败{Environment.NewLine}"); txtTestResponse.AppendText($"错误信息{Environment.NewLine}"); txtTestResponse.AppendText($"--------------------------{Environment.NewLine}"); txtTestResponse.AppendText(ExceptionUtils.GetExceptionMessage(ex)); } btnSend.Enabled = true; }
public IActionResult Delete(string id) { try { DockerClientUtils.UseDockerClient(client => { client.Images.DeleteImageAsync(id, new ImageDeleteParameters()).Wait(); }); return(base.Ok()); } catch (Exception ex) { return(base.StatusCode(500, $"Delete Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}")); } }
private void btnDelete_Click() { if (SelectedItem == null) { return; } if (SelectedItem is FileInfo) { var file = (FileInfo)SelectedItem; alert.Show(TextConfirm, string.Format(TextConfirmDeleteFile, file.Name), () => { loading.Show(TextConfirm, file.Name, true, null); try { file.Delete(); alert.Show(TextDelete, TextSuccess); } catch (Exception ex) { alert.Show(TextDelete, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex)); } refresh(); loading.Close(); InvokeAsync(StateHasChanged); }, () => { }); } else if (SelectedItem is DirectoryInfo) { var dir = (DirectoryInfo)SelectedItem; alert.Show(TextConfirm, string.Format(TextConfirmDeleteFolder, dir.Name), () => { loading.Show(TextDelete, dir.Name, true, null); try { dir.Delete(true); alert.Show(TextDelete, TextSuccess); } catch (Exception ex) { alert.Show(TextDelete, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex)); } refresh(); loading.Close(); InvokeAsync(StateHasChanged); }, () => { }); } }
private void refresh() { SelectedItem = null; Dirs = null; Files = null; if (CurrentDir == null) { if (DisplayFolder) { Dirs = DriveInfo.GetDrives().Where(t => t.IsReady).Select(t => t.RootDirectory).ToArray(); } } else { if (CurrentDir.Exists) { try { if (DisplayFolder) { Dirs = CurrentDir.GetDirectories(); } if (DisplayFile) { if (string.IsNullOrEmpty(FileFilter)) { Files = CurrentDir.GetFiles(); } else { Files = CurrentDir.GetFiles("*" + FileFilter); } } } catch (Exception ex) { alert.Show(TextFailed, ExceptionUtils.GetExceptionMessage(ex)); } } else { alert.Show(TextFailed, string.Format(TextFolderNotExist, CurrentDir.FullName)); } } }
private void btnRename_Click() { if (SelectedItem == null) { return; } if (SelectedItem is DirectoryInfo) { var dir = (DirectoryInfo)SelectedItem; prompt.Show(string.Format(TextInputNewName, dir.Name), dir.Name, name => { try { var newPath = Path.Combine(CurrentPath, name); dir.MoveTo(newPath); alert.Show(TextRename, TextSuccess); refresh(); InvokeAsync(StateHasChanged); } catch (Exception ex) { alert.Show(TextRename, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex)); } }, () => { }); } else if (SelectedItem is FileInfo) { var file = (FileInfo)SelectedItem; prompt.Show(string.Format(TextInputNewName, file.Name), file.Name, name => { try { var newPath = Path.Combine(CurrentPath, name); file.MoveTo(newPath); alert.Show(TextRename, TextSuccess); refresh(); InvokeAsync(StateHasChanged); } catch (Exception ex) { alert.Show(TextRename, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex)); } }, () => { }); } }
private void btnCreateFolder_Click() { prompt.Show(TextNewFolderPrompt, TextNewFolder, dir_name => { try { var newDirPath = Path.Combine(CurrentPath, dir_name); Directory.CreateDirectory(newDirPath); alert.Show(TextNewFolder, TextSuccess); refresh(); InvokeAsync(StateHasChanged); } catch (Exception ex) { alert.Show(TextNewFolder, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex)); } }, () => { }); }
private async void BtnConnectConnection_Click(object sender, EventArgs e) { var connectionNode = tvQpInstructions.SelectedNode; var connectionContext = connectionNode.Tag as ConnectionContext; if (connectionContext == null) { return; } this.Enabled = false; try { var preConnectionInfoContent = Quick.Xml.XmlConvert.Serialize(connectionContext.ConnectionInfo); await connectionContext.Connect(); connectionNode.ImageIndex = connectionNode.SelectedImageIndex = 1; connectionContext.QpClient.Disconnected += (sender, e) => { Invoke(new Action(() => { connectionNode.ImageIndex = connectionNode.SelectedImageIndex = 0; connectionContext.Dispose(); })); }; displayInstructions(connectionNode, connectionContext.ConnectionInfo.Instructions); connectionNode.ExpandAll(); var currentConnectionInfoContent = Quick.Xml.XmlConvert.Serialize(connectionContext.ConnectionInfo); if (currentConnectionInfoContent != preConnectionInfoContent) { QpdFileUtils.SaveQpbFile(connectionContext.ConnectionInfo); } } catch (Exception ex) { MessageBox.Show($"连接失败,原因:{ExceptionUtils.GetExceptionMessage(ex)}", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } this.Enabled = true; }
public IActionResult Delete(string id) { try { if (id.StartsWith(Environment.MachineName)) { return(base.StatusCode(403, $"Can't operate SimpleDockerUI container.")); } DockerClientUtils.UseDockerClient(client => { client.Containers.RemoveContainerAsync(id, new ContainerRemoveParameters() { }).Wait(); }); return(base.Ok()); } catch (Exception ex) { return(base.StatusCode(500, $"Delete Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}")); } }
public IActionResult Stop(string id) { try { if (id.StartsWith(Environment.MachineName)) { return(base.StatusCode(403, $"Can't operate SimpleDockerUI container.")); } bool ret = false; DockerClientUtils.UseDockerClient(client => { ret = client.Containers.StopContainerAsync(id, new ContainerStopParameters()).Result; }); if (ret) { return(base.Ok()); } return(base.StatusCode(500, $"Stop Error.\r\nStop Method return 'false'.")); } catch (Exception ex) { return(base.StatusCode(500, $"Stop Error.\r\n{ExceptionUtils.GetExceptionMessage(ex)}")); } }
private async Task onInputFileChanged() { IFileInfo fileInfo = null; try { //1MB缓存 var buffer = new byte[1 * 1024 * 1024]; System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); foreach (var file in await fileReaderService.CreateReference(inputFile).EnumerateFilesAsync()) { loading.Show(TextUpload, TextUploadReadFileInfo, false, cts.Cancel); fileInfo = await file.ReadFileInfoAsync(); var tmpFile = Path.Combine(CurrentPath, fileInfo.Name); if (File.Exists(tmpFile)) { throw new IOException(string.Format(TextUploadFileExist, fileInfo.Name)); } var fileSize = fileInfo.Size; var fileInfoStr = $"{fileInfo.Name} ({storageUSC.GetString(fileSize, 0, true)}B)"; loading.Show(TextUpload, string.Format(TextUploadFileUploading, fileInfoStr), false, cts.Cancel); var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); DateTime lastDisplayTime = DateTime.MinValue; long readTotalCount = 0; using (Stream stream = await file.OpenReadAsync()) using (var fileStream = System.IO.File.OpenWrite(tmpFile)) { while (true) { //如果已取消 if (cts.IsCancellationRequested) { break; } var ret = await stream.ReadAsync(buffer, 0, buffer.Length); if (ret == 0) { await Task.Delay(100); continue; } else { readTotalCount += ret; fileStream.Write(buffer, 0, ret); if (readTotalCount >= fileSize) { break; } if ((DateTime.Now - lastDisplayTime).TotalSeconds > 0.5 && stopwatch.ElapsedMilliseconds > 0) { StringBuilder sb = new StringBuilder(); var speed = Convert.ToDouble(readTotalCount / stopwatch.ElapsedMilliseconds); sb.Append(TextTransferSpeed + ": " + storageUSC.GetString(Convert.ToDecimal(speed * 1000), 1, true) + "B/s"); var remainingTime = TimeSpan.FromMilliseconds((fileSize - readTotalCount) / speed); sb.Append("," + TextRemainingTime + ": " + remainingTime.ToString(@"hh\:mm\:ss")); loading.UpdateProgress(Convert.ToInt32(readTotalCount * 100 / fileSize), sb.ToString()); await InvokeAsync(StateHasChanged); lastDisplayTime = DateTime.Now; } } } } stopwatch.Stop(); if (cts.IsCancellationRequested) { alert.Show(TextUpload, TextCanceled); File.Delete(tmpFile); return; } alert.Show(TextUpload, TextSuccess); } } catch (TaskCanceledException) { alert.Show(TextUpload, TextCanceled); } catch (Exception ex) { alert.Show(TextUpload, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex)); } finally { await fileReaderService.CreateReference(inputFile).ClearValue(); loading.Close(); refresh(); SelectedItem = Files?.FirstOrDefault(t => t.Name == fileInfo?.Name); } }
private async void btnDownload_Click() { var file = SelectedItem as FileInfo; if (file == null) { return; } if (DownloadFileAction != null) { DownloadFileAction.Invoke(JSRuntime, file.FullName); return; } System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); loading.Show(TextDownload, file.Name, false, cts.Cancel); var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); DateTime lastDisplayTime = DateTime.MinValue; byte[] buffer = new byte[24 * 1024]; var fileSize = file.Length; long readTotalCount = 0; try { using (var fs = file.OpenRead()) { while (!cts.IsCancellationRequested) { var ret = fs.Read(buffer, 0, buffer.Length); if (ret <= 0) { break; } readTotalCount += ret; if ((DateTime.Now - lastDisplayTime).TotalSeconds > 0.5 && stopwatch.ElapsedMilliseconds > 0) { StringBuilder sb = new StringBuilder(); var speed = Convert.ToDouble(readTotalCount / stopwatch.ElapsedMilliseconds); sb.Append(TextTransferSpeed + ": " + storageUSC.GetString(Convert.ToDecimal(speed * 1000), 1, true) + "B/s"); var remainingTime = TimeSpan.FromMilliseconds((fileSize - readTotalCount) / speed); sb.Append("," + TextRemainingTime + ": " + remainingTime.ToString(@"hh\:mm\:ss")); loading.UpdateProgress(Convert.ToInt32(readTotalCount * 100 / fileSize), sb.ToString()); await InvokeAsync(StateHasChanged); lastDisplayTime = DateTime.Now; } await BlazorDownloadFileService.AddBuffer(new ArraySegment <byte>(buffer, 0, ret), cts.Token); } } if (cts.IsCancellationRequested) { alert.Show(TextUpload, TextCanceled); return; } var result = await BlazorDownloadFileService.DownloadBinaryBuffers(file.Name, cts.Token); if (!result.Succeeded) { alert.Show(TextDownload, TextFailed + Environment.NewLine + result.ErrorName + Environment.NewLine + result.ErrorMessage); } } catch (TaskCanceledException) { alert.Show(TextUpload, TextCanceled); } catch (Exception ex) { alert.Show(TextUpload, TextFailed + Environment.NewLine + ExceptionUtils.GetExceptionMessage(ex)); } finally { await BlazorDownloadFileService.ClearBuffers(); stopwatch.Stop(); loading.Close(); } }