/// <summary> /// Get reports for all accounts /// </summary> /// <param name="session"></param> public static void GetReports(O2GSession session) { O2GLoginRules loginRules = session.getLoginRules(); if (loginRules == null) { throw new Exception("Cannot get login rules"); } O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory(); O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.Accounts); O2GAccountsTableResponseReader accountsReader = responseFactory.createAccountsTableReader(accountsResponse); System.Net.WebClient webClient = new System.Net.WebClient(); for (int i = 0; i < accountsReader.Count; i++) { O2GAccountRow account = accountsReader.getRow(i); string url = session.getReportURL(account, DateTime.Now.AddMonths(-1), DateTime.Now, "html", null, null, 0); Console.WriteLine("AccountID={0}; Balance={1}; UsedMargin={2}; Report URL={3}", account.AccountID, account.Balance, account.UsedMargin, url); string content = webClient.DownloadString(url); string filename = account.AccountID + ".html"; System.IO.File.WriteAllText(filename, content); Console.WriteLine("Report is saved to {0}", filename); } }
/// <summary> /// Get reports for all accounts /// </summary> /// <param name="session"></param> public static void GetReports(O2GSession session) { O2GLoginRules loginRules = session.getLoginRules(); if (loginRules == null) { throw new Exception("Cannot get login rules"); } O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory(); O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.Accounts); O2GAccountsTableResponseReader accountsReader = responseFactory.createAccountsTableReader(accountsResponse); System.Net.WebClient webClient = new System.Net.WebClient(); for (int i = 0; i < accountsReader.Count; i++) { O2GAccountRow account = accountsReader.getRow(i); Uri url = new Uri(session.getReportURL(account.AccountID, DateTime.Now.AddMonths(-1), DateTime.Now, "html", null)); Console.WriteLine("AccountID={0}; Balance={1}; Report URL={2}", account.AccountID, account.Balance, url); string content = webClient.DownloadString(url); string prefix = url.Scheme + Uri.SchemeDelimiter + url.Host; string report = O2GHtmlContentUtils.ReplaceRelativePathWithAbsolute(content, prefix); string filename = account.AccountID + ".html"; System.IO.File.WriteAllText(filename, report); Console.WriteLine("Report is saved to {0}", filename); } }
/// <summary> /// Get reports for all accounts /// </summary> /// <param name="session"></param> public static void GetReports(O2GSession session) { O2GLoginRules loginRules = session.getLoginRules(); if (loginRules == null) { throw new Exception("Cannot get login rules"); } O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory(); O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.Accounts); O2GAccountsTableResponseReader accountsReader = responseFactory.createAccountsTableReader(accountsResponse); using (System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient()) { for (int i = 0; i < accountsReader.Count; i++) { O2GAccountRow account = accountsReader.getRow(i); Uri url = new Uri(session.getReportURL(account.AccountID, DateTime.Now.AddMonths(-1), DateTime.Now, "html", null)); Console.WriteLine("AccountID={0}; Balance={1}; BaseUnitSize={2}; Report URL={3}", account.AccountID, account.Balance, account.BaseUnitSize, url); var response = httpClient.GetAsync(url).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; // by calling .Result you are synchronously reading the result string content = responseContent.ReadAsStringAsync().Result; string filename = account.AccountID + ".html"; string prefix = url.Scheme + "://" + url.Host + "/"; string report = O2GHtmlContentUtils.ReplaceRelativePathWithAbsolute(content, prefix); System.IO.File.WriteAllText(filename, report); Console.WriteLine("Report is saved to {0}", filename); } else { throw new Exception("Report is not received."); } } } }