private static void TestFileImporter() { string file = GenerateFile(); BenFatto.CLF.Service.FileProcessor processor = new BenFatto.CLF.Service.FileProcessor(file); using (ClfContext context = new ClfContext()) processor.ProcessFile(context); WriteOut($"File imported successfuly: {file} at {DateTime.Now.ToString(BenFatto.CLF.ClfAppSettings.Current.DateFormat, BenFatto.CLF.ClfAppSettings.Current.CultureInfo)}"); }
public Import ProcessFile(ClfContext context) { ImportService importService = new ImportService(context); importService.InsertOrUpdate(Import); List <string> errors = new List <string>(); LogRowService service = new LogRowService(context); LogRowMismatchService mismatchService = new LogRowMismatchService(context); using (StreamReader file = new StreamReader(Import.FileName)) { string line; while (null != (line = file.ReadLine())) { try { Import.RowCount++; service.InsertCollection(Model.LogRow.Parse(line, Import.Id, Import.RowCount)); Import.SuccessCount++; } catch (Exception ex) { Import.ErrorCount++; errors.Add(line); mismatchService.InsertCollection(LogRowMismatch.Parse(line, Import.Id, Import.RowCount, Import.ErrorCount, ex)); } } } if (Import.ErrorCount > 0) { Import.MismatchRowsFileName = Import.FileName + ".err"; context.SaveChanges(); using (StreamWriter file = File.CreateText(Import.MismatchRowsFileName)) { foreach (string line in errors) { file.WriteLine(line); } file.Flush(); } } return(Import); }
public ImportService(ClfContext context) : base(context) { }
public ModelServiceBase(ClfContext context) { Context = context; }
public LogRowMismatchService(ClfContext context) : base(context) { }
public LogRowService(ClfContext context) : base(context) { }