protected override void OnStart(string[] args) { ThreadPool.QueueUserWorkItem(async state => { logger = new Logger(); string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; try { var repositories = new UnitOfWork(connectionString); OrderService orderService = new OrderService(repositories); var ordersInfo = await orderService.GetOrders(); //making proper file name DateTime now = DateTime.Now; var currTime = now.ToString("yyyy_MM_dd_HH_mm_ss"); XmlGenerator <Order> orders = new XmlGenerator <Order>(logger.parsedOptions.options.PathsOptions.SourceDirectory + "Sales_" + currTime + ".txt"); await orders.XmlGenerate(ordersInfo); this.OnStop(); } catch (Exception trouble) { var repositories2 = new UnitOfWork(connectionString); ErrorService service = new ErrorService(repositories2); service.AddErrors(new Error(trouble.GetType().Name, trouble.Message, DateTime.Now)); } Thread loggerThread = new Thread(new ThreadStart(logger.Start)); loggerThread.Start(); }); }
protected override void OnStart(string[] args) { /* when we start our service we are generating xml files according to data from database */ var projectPath = AppDomain.CurrentDomain.BaseDirectory; var manager = new MyConfigurationManager.ConfigurationManager(); var pathOption = manager.GetOptions <PathsOptions>(projectPath + "xmlConfig.xml"); try { var repositories = new UnitOfWork(pathOption.DBpath1); OrderService orderService = new OrderService(repositories); /* now getting list of orders */ var ordersInfo = orderService.GetListOfOrders(); XmlGenerateService <Order> orders = new XmlGenerateService <Order>(pathOption.ClientDirectory + "\\Orders.xml"); /* generating xml file */ orders.XmlGenerate(ordersInfo); } catch (Exception trouble) { /* if something went wrong */ var repositories2 = new UnitOfWork(pathOption.DBpath2); ErrorService service = new ErrorService(repositories2); service.AddErrors(new Errors(trouble.GetType().Name, trouble.Message, DateTime.Now)); } }
protected override void OnStart(string[] args) { ThreadPool.QueueUserWorkItem(async state => { try { var repositories = new UnitOfWork(options.PathsOptions.DBpath1); OrderService orderService = new OrderService(repositories); /* now getting list of orders */ var ordersList = await orderService.GetListOfOrders(); /* now we need to make a file name */ string fileName = options.PathsOptions.DestinationDirectory; fileName += @"\Orders_"; DateTime now = DateTime.Now; var currTime = now.ToString("yyyy_MM_dd_HH_mm_ss"); fileName += currTime; /* file name almost ready. now we create xmlgenerator instance and pass the xml path */ XmlGenerateService <Order> orders = new XmlGenerateService <Order>(fileName + ".xml"); /* now we generating xml file with orders */ await orders.XmlGenerate(ordersList); this.OnStop(); } catch (Exception trouble) { /* if something went wrong */ var repositories2 = new UnitOfWork(options.PathsOptions.DBpath2); ErrorService service = new ErrorService(repositories2); service.AddErrors(new Error(trouble.GetType().Name, trouble.Message, DateTime.Now)); } }); }