using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Taloyhtio.ReimariIntegration.CodeFiles; using Taloyhtio.ReimariIntegration.CodeFiles.DataAccess; namespace HausviseInitialCustomersLoad { class Program { // private static string[] cities = // { // "Jyväskylä", // "Oulu", // "Hämeenlinna", // "Helsinki", // "Tampere", // "Lahti", // "Porvoo", // "Mikkeli", // "Lappeenranta", // "Kymi", // "Imatra", // "Joensuu", // "Lohja", // "Laukaa", // "" // }; private static string[] vatCodes = { "2345678-9", "0357981-2", "2904859-3", "0614595-6" }; static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: .exe "); return; } string connString = ConfigurationManager.ConnectionStrings["TaloyhtioFBA_String"].ConnectionString; if (string.IsNullOrEmpty(connString)) { Console.WriteLine("Connections string is null or empty"); return; } var now = DateTime.Now; var logger = new Logger("_reim_hausvise_initial_load.log"); var customersRepo = new HausviseCustomersRepository(connString, logger); var service = new HausviseService(args[0], args[1], logger); //foreach (var city in cities) foreach (var code in vatCodes) { try { //Console.WriteLine("Load customers for '{0}' city", city); Console.WriteLine("Load customers for '{0}' vat code", code); //var customers = service.GetCustomers(string.Format("sijainti='{0}'", city)); var customers = service.GetCustomers(string.Format("ytunnus='{0}'", code)); if (customers == null || customers.Count == 0) { Console.WriteLine(" No customers are returned from API"); continue; } foreach (var c in customers) { try { Console.WriteLine(" Saving customer '{0}'", JsonConvert.SerializeObject(c)); if (!customersRepo.AddOrUpdate(c.yhtio, c.ytunnus, c.yhtiotunnus, c.osoite, c.postinro, c.postitp, c.sijainti, c.a_pvm, c.cid, now)) { Console.WriteLine("There was error during saving of customer. See log for details"); } } catch (Exception x) { Console.WriteLine("Error occured when try to save customer: {0}", x.Message); } } } catch (Exception x) { Console.WriteLine("Error occured: {0}", x.Message); } } } } }