internal static IList <string[]> ReadCsvFile(string fullPath, string fileName) { IList <string[]> listStringLine = new List <string[]>(); var textFile = File.OpenText(fullPath); _currentLine = 0; var invalid = false; try { while (!textFile.EndOfStream) { _currentLine++; var stringLine = textFile.ReadLine(); listStringLine.Add(ParseCsvStringLine(fileName, stringLine)); } } catch (ParserException e) { LoggerHelper.AddErrorLog(new EventLog(), string.Join(" ", e.Message, "On line", _currentLine)); invalid = true; } finally { ((IDisposable)textFile).Dispose(); } MoveFile(fullPath, invalid); LoggerHelper.AddInfoLog(new EventLog(), string.Join(string.Empty, "File \"", fileName, "\" processing completed")); return(listStringLine); }
private void StartLoadTask(string fileName, string fullPath) { try { Task.Factory.StartNew(() => { var fileData = Parser.ReadCsvFile(fullPath, fileName); var dbLoader = new DatabaseItemLoader(_lockers, _dbContext); foreach (var lineFile in fileData) { var tupleModels = Parser.ParseEntitiesToTuple(fileName, lineFile); dbLoader.LoadItems(tupleModels); } }); } catch (FileNotFoundException e) { LoggerHelper.AddErrorLog(new EventLog(), e.Message); } catch (IOException e) { LoggerHelper.AddErrorLog(new EventLog(), e.Message); } catch (NotSupportedException e) { LoggerHelper.AddErrorLog(new EventLog(), e.Message); } catch (InvalidOperationException e) { LoggerHelper.AddErrorLog(new EventLog(), e.Message); } }
protected override void OnContinue() { if (CheckProcessConsole()) { LoggerHelper.AddErrorLog(eventLog, "The service cannot be started while the console application is running"); Environment.Exit(0); } StartTaskWatcher(); LoggerHelper.AddInfoLog(eventLog, "Resume service"); }
protected override void OnStart(string[] args) { if (CheckProcessConsole()) { LoggerHelper.AddErrorLog(eventLog, "The service cannot be started while the console application is running"); Environment.Exit(0); } LoggerHelper.AddInfoLog(eventLog, "Start service"); StartTaskWatcher(); LoggerHelper.AddInfoLog(eventLog, "Start file watcher"); }
internal void LoadItems(Tuple <Client, Item, DataSource, Sale> lineFileItems) { var searchCriteria = GetEachSearchCriteria(lineFileItems); try { var unitOfWork = new UnitOfWork(_dbContext, _lockers); unitOfWork.TryAddClient(lineFileItems.Item1, searchCriteria.Item1); unitOfWork.TryAddItem(lineFileItems.Item2, searchCriteria.Item2); unitOfWork.TryAddDataSource(lineFileItems.Item3, searchCriteria.Item3); unitOfWork.TryAddSale(lineFileItems.Item4, searchCriteria.Item4); } catch (ModelObjectException e) { LoggerHelper.AddErrorLog(new EventLog("LoadItemsError"), e.Message); } }