public List <ConfigViewModel> GetConfigsFromSources() { var list = new List <ConfigViewModel>(); foreach (var source in Globals.obSettings.Sources.Sources) { try { WebClient wc = new WebClient(); switch (source.Auth) { case Source.AuthMode.ApiKey: wc.Headers.Add(HttpRequestHeader.Authorization, source.ApiKey); break; case Source.AuthMode.UserPass: var header = BlockFunction.Base64Encode($"{source.Username}:{source.Password}"); wc.Headers.Add(HttpRequestHeader.Authorization, $"Basic {header}"); break; default: break; } var file = wc.DownloadData(source.ApiUrl); using (var zip = new ZipArchive(new MemoryStream(file), ZipArchiveMode.Read)) { foreach (var entry in zip.Entries) { using (var stream = entry.Open()) { using (TextReader tr = new StreamReader(stream)) { var text = tr.ReadToEnd(); var cfg = IOManager.DeserializeConfig(text); list.Add(new ConfigViewModel("", "Remote", cfg, true)); } } } } } catch { } } return(list); }
public List <ConfigViewModel> GetConfigsFromSources() { var list = new List <ConfigViewModel>(); cachedConfigs = new List <ConfigViewModel>(); foreach (var source in Globals.obSettings.Sources.Sources) { WebClient wc = new WebClient(); switch (source.Auth) { case Source.AuthMode.ApiKey: wc.Headers.Add(HttpRequestHeader.Authorization, source.ApiKey); break; case Source.AuthMode.UserPass: var header = BlockFunction.Base64Encode($"{source.Username}:{source.Password}"); wc.Headers.Add(HttpRequestHeader.Authorization, $"Basic {header}"); break; default: break; } byte[] file = new byte[] { }; try { file = wc.DownloadData(source.ApiUrl); } catch (Exception ex) { MessageBox.Show($"Could not contact API {source.ApiUrl}\r\nReason: {ex.Message}"); continue; } var status = wc.ResponseHeaders["Result"]; if (status != null && status == "Error") { MessageBox.Show($"Error from API {source.ApiUrl}\r\nThe server says: {Encoding.ASCII.GetString(file)}"); continue; } try { using (var zip = new ZipArchive(new MemoryStream(file), ZipArchiveMode.Read)) { foreach (var entry in zip.Entries) { var subCategory = Path.GetDirectoryName(entry.FullName).Replace("\\", " - "); var category = subCategory == "" ? "Remote" : $"Remote - {subCategory}"; using (var stream = entry.Open()) { using (TextReader tr = new StreamReader(stream)) { var text = tr.ReadToEnd(); var cfg = IOManager.DeserializeConfig(text); list.Add(new ConfigViewModel("", category, cfg, true)); cachedConfigs.Add(new ConfigViewModel("", category, cfg, true)); } } } } } catch { } } return(list); }