private List <LogFileNameAndPath> GetFilesFromFolder(string sourcePath) { List <LogFileNameAndPath> logsInFolder = new List <LogFileNameAndPath>(); try { Directory.GetFiles(sourcePath, "*.log", SearchOption.AllDirectories).ToList() .ForEach(filePath => { string fileName = Path.GetFileName(filePath); string fileDate = fileName.Split('-', '.')[1]; logsInFolder.Add(new LogFileNameAndPath() { LogsFullPath = filePath, LogsFileName = fileName, LogsDate = fileDate }); }); return(logsInFolder); } catch (Exception ex) { MessageShowMethod.ShowMethod(ex.Message); return(null); } }
public int BulkCopyInsert(int productTypeId, List <YokogawaLog> logReaderCurerntDay) { Table.Rows.Clear(); //LogReaderViewModelCollection.ForEach(currentParsedLine => logReaderCurerntDay.Distinct().ToList().ForEach(currentParsedLine => { DataRow row; row = Table.NewRow(); row["ProductTypeId"] = productTypeId; row["DateTimeUMTEvent"] = currentParsedLine.DateTimeUMTEvent; if (currentParsedLine.UnknownColumn1Id != 0) { row["UnknownColumn1Id"] = currentParsedLine.UnknownColumn1Id; } row["TypeEvent"] = currentParsedLine.TypeEvent; row["IindexNumberEvent"] = currentParsedLine.IindexNumberEvent; if (currentParsedLine.WriterId != 0) { row["WriterId"] = currentParsedLine.WriterId; } row["ExactDateTime"] = currentParsedLine.ExactDateTime; row["DateUMTEvent"] = currentParsedLine.ExactDateTime.Date; row["TimeUMTEvent"] = currentParsedLine.ExactDateTime.TimeOfDay; row["UnknownColumn2"] = currentParsedLine.UnknownColumn2; row["UnknownColumn3"] = currentParsedLine.UnknownColumn3; if (currentParsedLine.ControllersAndStationsId != 0) { row["ControllersAndStationsId"] = currentParsedLine.ControllersAndStationsId; } if (currentParsedLine.PositionOrAlarmOrBlockName == "") { row["PositionOrAlarmOrBlockName"] = currentParsedLine.PositionOrAlarmOrBlockName; } row["MessageText"] = currentParsedLine.MessageText; Table.Rows.Add(row); }); int addedRows = 0; try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection)) { bulkCopy.DestinationTableName = "dbo.LogYokogawa"; bulkCopy.BatchSize = 10000; bulkCopy.WriteToServer(Table); } } addedRows = Table.Rows.Count; } catch (Exception ex) { MessageShowMethod.ShowMethod(ex.Message); } return(addedRows); }
private void ReadCurrentDate(string currentDate, int productTypeId, List <LogFileNameAndPath> logsInFolder) { List <YokogawaLog> logReaderCurerntDay = new List <YokogawaLog>(); logsInFolder.Where(y => y.LogsDate == currentDate).ToList().ForEach(z => ReadCurrentFile(z.LogsFullPath, logReaderCurerntDay) ); DBConnetcor.BulkCopyInsert(productTypeId, logReaderCurerntDay); MessageShowMethod.ShowMethod(DateTime.Now + " Id: " + productTypeId + " Date: " + currentDate); }
private void ReadCurrentFile(string currentFilePath, List <YokogawaLog> logReaderCurerntDay) { try { var stringsFromFile = File.ReadLines(currentFilePath, Encoding.Default).ToList(); stringsFromFile.ForEach(x => ParseAndWriteToList(x, logReaderCurerntDay)); } catch (Exception ex) { MessageShowMethod.ShowMethod("Ошибка при выполнении метода ReadCurrentFile"); } }
private void GetAllFolders() { try { var directories = Directory.GetDirectories(SourcePath); foreach (var dir in directories) { ParseProductType(dir); } } catch (Exception ex) { MessageShowMethod.ShowMethod("Ошибка при выполнении метода GetAllFolders"); } }