protected virtual IEirWebClient GetWebClient() { var wc = new EirWebClient { Encoding = Encoding.UTF8, Credentials = CredentialCache.DefaultCredentials, UserAgent = _userAgent, UseHttpLog = Settings.GetBool("UseHttpLog", false) }; wc.Headers.Add(HttpRequestHeader.ContentType, "application/json"); wc.Headers.Add(HttpRequestHeader.Accept, "application/json"); if (_apiVersion > 1) { wc.Headers.Add(CustomHttpHeaders.API_VERSION, _apiVersion.ToString()); } return(wc); }
private async void cmdExport_Click(object sender, EventArgs e) { string zipFile = txtZipPath.Text; string path = ""; try { cmdClose.Enabled = false; cmdExport.Enabled = false; cmdGetZip.Enabled = false; txtResults.Text = ""; _waitingLogLines = new List <string>(); if (!File.Exists(zipFile)) { MessageBox.Show(@"Zip file does not exist"); return; } path = Path.Combine(Path.GetTempPath(), $"ProactiveExpressImport_tmp_{DateTime.Now.ToString("yyyyMMddhhmmss")}"); Directory.CreateDirectory(path); Log($"Unzipping to {path}"); System.IO.Compression.ZipFile.ExtractToDirectory(zipFile, path); using (var webClient = new EirWebClient()) { var uri = new Uri("https://proactive.qliktech.com/api/SenseStatistics"); //"https://proactive.qliktech.com/api/SenseStatistics"); "http://*****:*****@"Reading file {i} of {files.Length}"; Application.DoEvents(); } var data = File.ReadAllText(file); try { await webClient.UploadStringAsync(uri, HttpMethod.Post, data, CancellationToken.None); } catch (Exception ex) { Log($"Failed sending file, will retry {file}"); Log(ex.ToString()); try { await webClient.UploadStringAsync(uri, HttpMethod.Post, data, CancellationToken.None); } catch (Exception ex2) { Log($"Totally failed sending file {file}"); Log(ex2.ToString()); failedFiles++; } } } catch (Exception exception) { Log($"Failed reading file"); Log(exception.ToString()); continue; } Log($"Sent {file}"); } Log($"Finished with {failedFiles} failed files."); } //Directory.Delete(path); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cmdClose.Enabled = true; cmdExport.Enabled = true; cmdGetZip.Enabled = true; PurgeLog(); lblInfo.Text = $@"{lblInfo.Text}{Environment.NewLine}ZipFile:{zipFile}{Environment.NewLine}TmpPath:{path}"; txtZipPath.Text = ""; MessageBox.Show(@"Done"); } }