Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
                        }
                    }
                }
            }
        }