public void Add(DatasList DatasList, Data Data, DataChecker DataChecker) { if (DataChecker.DataCheck(Data)) { DatasList.Add(Data); } }
public static void CreateTraceFile(DatasList dataList, string traceFileNamePath, string logFileName, string traceFileName) { int filesCount = dataList.Data.Count() / 100; if (dataList.Data.Count() % 100 > 0) { filesCount++; } FileTraceModel model = new FileTraceModel() { FileName = logFileName, FileItemsList = new List <FileItemModel>(), FilesItemCount = filesCount }; for (int i = 0; i < filesCount; i++) { StringBuilder itemName = new StringBuilder(logFileName); FileItemModel fileItem = new FileItemModel() { FileItemName = itemName.Replace(".log", "-000" + (i + 1)).Append(".log").ToString(), FileState = FileStatus.Empty }; model.FileItemsList.Add(fileItem); } model.TotalCount = dataList.Data.Count(); FileHelper.WriteTextFile(traceFileNamePath, string.Empty, false); FileHelper.WriteTextFile(traceFileNamePath, JsonConvert.SerializeObject(model), false); }
private void CreateUpdateTraceFile(DatasList dataList, string fileName) { string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), DirectoryConfig.DirectoryName); string dataTypeFileName = dataList.Data.FirstOrDefault()?.Type; string traceFileName = "Trace"; traceFileName = TraceHelper.TraceNameCreator(fileName, dataTypeFileName, directoryPath); string directoryTracePath = Path.Combine(directoryPath, dataTypeFileName + "-Trace"); string traceFileNamePath = Path.Combine(directoryTracePath, traceFileName); if (!Directory.Exists(directoryTracePath)) { DirectoryInfo di = Directory.CreateDirectory(directoryTracePath); } if (!System.IO.File.Exists(traceFileNamePath)) { TraceHelper.CreateTraceFile(dataList, traceFileNamePath, fileName, traceFileName); } else { TraceHelper.UpdateTraceFile(dataList, traceFileNamePath, fileName, traceFileName); } }
public Value GetValue(DatasList DatasList, Key Key, DataChecker DataChecker) { if (DataChecker.KeyCheck(Key)) { return(DatasList.GetValue(Key)); } return(new NullValue()); }
public bool Reduce(DatasList DatasList, Key Key, Value Value, DataChecker DataChecker) { if (DataChecker.KeyCheck(Key)) { return(DatasList.Reduce(Key, Value)); } return(false); }
public ActionResult <object> DataLogger([FromBody] DatasList request) { request.TotalCount = request.Data.Count(); _loggerService.CreateFilesByDataType(request); return(Ok(request)); }
private DatasList ReadTraceData(string fileItemNamePath) { string fileString = ""; DatasList data = new DatasList { Data = new List <Data>() }; if (System.IO.File.Exists(fileItemNamePath)) { fileString = System.IO.File.ReadAllText(fileItemNamePath); data = JsonConvert.DeserializeObject <DatasList>(fileString); } return(data); }
public void CreateFilesByDataType(DatasList request) { foreach (var typedList in request.Data.GroupBy(x => x.Type)) { DatasList dataList = new DatasList { Data = new List <Data>() }; dataList.Data.AddRange(typedList); dataList.TotalCount = dataList.Data.Count(); string date = $"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}"; string fileName = $"{typedList.Key}-{date}.log"; string path = Path.Combine(Directory.GetCurrentDirectory(), DirectoryConfig.DirectoryName); if (!Directory.Exists(path)) { DirectoryInfo di = Directory.CreateDirectory(path); } string newPath = Path.Combine(path, fileName); string list = ""; DatasList data = null; if (System.IO.File.Exists(newPath)) { list = System.IO.File.ReadAllText(newPath); data = JsonConvert.DeserializeObject <DatasList>(list); } if (data != null) { dataList.Data.AddRange(data.Data); dataList.TotalCount = dataList.Data.Count(); System.IO.File.WriteAllText(newPath, string.Empty); } DatasList traceListData = new DatasList() { Data = new List <Data>() }; traceListData.Data.AddRange(typedList); CreateUpdateTraceFile(dataList, fileName); FileHelper.WriteTextFile(newPath, JsonConvert.SerializeObject(dataList), false); } }
public static void UpdateTraceFile(DatasList dataList, string traceFileNamePath, string fileName, string traceFileName) { FileTraceModel model = ReadTraceFile(traceFileNamePath); //model.Data.AddRange(dataList.Data); int filesCount = 0; int itemsCount = dataList.Data.Count(); while (itemsCount >= 100) { filesCount++; itemsCount -= 100; } if (itemsCount % 100 > 0 || itemsCount > 0) { filesCount++; } for (int i = model.FilesItemCount + 1; i <= filesCount; i++) { StringBuilder itemName = new StringBuilder(fileName); int nameNumber = model.FilesItemCount + 1; FileItemModel fileItem = new FileItemModel() { FileItemName = itemName.Replace(".log", "-000" + (nameNumber)).Append(".log").ToString(), FileState = FileStatus.Empty }; model.FileItemsList.Add(fileItem); model.FilesItemCount = filesCount; } model.TotalCount = dataList.Data.Count(); FileHelper.WriteTextFile(traceFileNamePath, string.Empty, false); FileHelper.WriteTextFile(traceFileNamePath, JsonConvert.SerializeObject(model), false); }
public void CreateOrUpdateLoggerTraceInDirectory() { string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), DirectoryConfig.DirectoryName); DirectoryInfo rootDi = new DirectoryInfo(directoryPath); foreach (FileInfo file in rootDi.GetFiles()) { DatasList data = null; FileTraceModel traceData = null; string filePath = Path.Combine(directoryPath, file.Name); DatasList dataList = new DatasList { Data = new List <Data>() }; ReadLogDataFile(filePath, out data); if (data != null) { dataList.Data.AddRange(data.Data); dataList.TotalCount = dataList.Data.Count(); string dataTypeFileName = dataList.Data.FirstOrDefault()?.Type; string traceFileName = TraceHelper.TraceNameCreator(file.Name, dataTypeFileName, directoryPath); string directoryTracePath = Path.Combine(directoryPath, dataTypeFileName + "-Trace"); string traceFileNamePath = Path.Combine(directoryTracePath, traceFileName); string traceString = ""; if (System.IO.File.Exists(traceFileNamePath)) { traceString = System.IO.File.ReadAllText(traceFileNamePath); traceData = JsonConvert.DeserializeObject <FileTraceModel>(traceString); } else { TraceHelper.CreateTraceFile(dataList, traceFileNamePath, file.Name, traceFileName); } if (traceData != null) { foreach (var item in traceData.FileItemsList) { if (item.FileState == FileStatus.Full) { continue; } string fileItemNamePath = Path.Combine(directoryTracePath, item.FileItemName); DatasList organizedList = new DatasList() { Data = new List <Data>() }; var toBeFetchedData = data.Data.Where(x => x.IsProcessed == false).Take(100).ToList(); organizedList.Data.AddRange(toBeFetchedData); organizedList.TotalCount = toBeFetchedData.Count(); organizedList.Data.ForEach(UpdateProcessedItems); if (item.FileState == FileStatus.Empty) { if (organizedList.Data.Any()) { FileHelper.WriteTextFile(fileItemNamePath, JsonConvert.SerializeObject(organizedList), false); } } if (item.FileState == FileStatus.HavingSize) { DatasList traceFileData = ReadTraceData(fileItemNamePath); if (organizedList.Data.Any()) { organizedList.Data.AddRange(traceFileData.Data); organizedList.TotalCount = organizedList.Data.Count(); FileHelper.WriteTextFile(fileItemNamePath, JsonConvert.SerializeObject(organizedList), false); } } if (organizedList.Data.Count == 100) { item.FileState = FileStatus.Full; } if (organizedList.Data.Count < 100) { item.FileState = FileStatus.HavingSize; } traceData.TotalCount = data.Data.Count(); //FileHelper.WriteTextFile(traceFileNamePath, string.Empty, false); FileHelper.WriteTextFile(traceFileNamePath, JsonConvert.SerializeObject(traceData), false); foreach (var addeditem in organizedList.Data) { Data first = null; foreach (var data1 in data.Data) { if (addeditem != null && data1 == addeditem) { first = data1; break; } } if (first != null) { first.IsProcessed = true; } } var x = data.Data.Where(data1 => data1.IsProcessed == true).ToList(); //data.Data.ForEach(UpdateProcessedItems); data.TotalCount = data.Data.Count(); data.ProcessedCount = data.Data.Count(data1 => data1.IsProcessed == true); //FileHelper.WriteTextFile(filePath, string.Empty, false); FileHelper.WriteTextFile(filePath, JsonConvert.SerializeObject(data), false); } } } } }
public InventoryCounter() { inventoryList = new InventoryList(); DataChecker = new InvenrtoryDataChecker(); }
// public void Load(DatasList DatasList,List<List<Data>> Dataslist){ // DatasList.Load(Dataslist); // // } public PublicDatasList GetDatasList(DatasList DatasList) { return(DatasList.GetDatasList()); }
public ItemLibrary() { itemLibrary = new ItemDatasList(); DataChecker = new ItemLibraryChecker(); }