protected override void OnStart(string[] args) { var appPath = AppDomain.CurrentDomain.BaseDirectory; var manager = new ConfigManager(); var pathOption = manager.GetOption <PathOption>(appPath + "config.xml"); var logs = manager.GetOption <Logs>(appPath + "config.xml"); try { var repositories = new UnitOfWork(pathOption.DBPath1); PersonService employeeService = new PersonService(repositories); var employeesInfo = employeeService.GetListOfEmployees(); XmlGenerateService <Persons> persons = new XmlGenerateService <Persons>(pathOption.SourceDirectory + "\\Persons.xml"); persons.XmlGenerate(employeesInfo); } catch (Exception trouble) { using (var writer = new StreamWriter(logs.Log, true)) { writer.WriteLine(trouble.Message); } } }
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)); } }); }