private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var logFiles = DBMLogFileManager.Instance.DetectLogs(path); if (logFiles.Count > 0) { progressBar1.Invoke(new Action(() => { progressBar1.Maximum = logFiles.Count - 1; })); zipPath = $"{zipPath}.zip"; using (ZipArchive zip = ZipFile.Open(zipPath, ZipArchiveMode.Create)) { for (int i = 0; i < logFiles.Count; i++) { backgroundWorker.ReportProgress(i); DBMLogFileManager.Instance.SaveLogs(zipPath, zip, logFiles[i]); } } if (MessageBox.Show("Do you want to delete the Log-Files ?", AppConstants.WindowCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DBMLogFileManager.Instance.DeleteLogs(this, logFiles); } if (MessageBox.Show("Do you want to transmit the Log-Files ?", AppConstants.WindowCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (DBMUtils.IsZipFileGenerated(zipPath)) { DBMLogFileManager.Instance.SendWebReq(zipPath); File.Delete(zipPath); } else { MessageBox.Show("There is no Zip-File to transmit !", AppConstants.WindowCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Error); } } } else { MessageBox.Show("No Log-Files found!", AppConstants.WindowCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void SendWebReq(string zipPath) { try { if (DBMUtils.IsZipFileGenerated(zipPath) == true) { System.Net.WebClient Client = new System.Net.WebClient(); Client.Headers.Add("Content-Type", "binary/octet-stream"); byte[] result = Client.UploadFile("https://report.deutschebohrmaschine.de/upload.php", "POST", zipPath); string response = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); MessageBox.Show(response); } else { MessageBox.Show("No Zip-Archive has been found!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }