/// <summary> /// Imports the given csv file /// </summary> public void StartTransactionImport(string csvfile) { api = new SimpleRestApi(ConfigurationManager.AppSettings["ovservice"]); log4net.Config.XmlConfigurator.Configure(); parser = new TextFieldParser(csvfile) {Delimiters = new[] {","}}; parser.ReadFields(); while (!parser.EndOfData) { IList<string> csvFields = parser.ReadFields(); if (HasValidNumberOfFields(csvFields)) { Line CSVLine = new Line(csvFields); try { Retry.Repeat(3) .WithPolling(TimeSpan.FromSeconds(1)) .WithTimeout(TimeSpan.FromSeconds(10)) .Until(() => PostCSVLine(CSVLine)); } catch (Exception) { log.DebugFormat("Max retries reached, skipping line: {0}", CSVLine); } } else { log.ErrorFormat("Invalid line is skipped! (Incorrect number of fields) {0}", string.Join(",", csvFields)); } } }
/// <summary> /// Imports the given csv file /// </summary> public void StartTransactionImport(string csvfile) { api = new SimpleRestApi(ConfigurationManager.AppSettings["ovservice"]); parser = new TextFieldParser(csvfile); parser.Delimiters = new [] {","}; parser.ReadFields(); while (!parser.EndOfData) { var csvFields = parser.ReadFields(); var apiresponse = api.Post("ovtransactionimport/process", new { id = Convert.ToInt64(csvFields[0]), date = csvFields[1], station = csvFields[2], action = csvFields[3], cardid = Convert.ToInt64(csvFields[4]), userid = Convert.ToInt64(csvFields[5]) }, new { success = default(Boolean), error = default(String) }); if (apiresponse.success) { Console.WriteLine("Succesfully uploaded transaction!"); } else { throw new Exception("OMG ERROER!!!!"); } } }