コード例 #1
0
        public void GenerateFileGrowhFactStats()
        {
            var fileInfoList = GetServerLogFileInfoList();
            var factFileList = GetServerLogFactInfoList();
            ServerLogFactGrowthInfoGenerator <ServerLogFactGrowthInfo> slfg = new ServerLogFactGrowthInfoGenerator <ServerLogFactGrowthInfo>(fileInfoList.Cast <IServerLogFileInfo>().ToList(), factFileList.Cast <IServerLogFactInfo>().ToList());
            var sliced = slfg.GenerateSlicedList();

            sliced.Count().Should().Be(6, "Six files should be in the list");
            foreach (var grp in sliced)
            {
                grp.Count().Should().Be(2, "Each file should contain two entries");
            }
        }
コード例 #2
0
        static void WriteCsvFileFinally(List <ServerLogFileInfo> serverLogFileInfoList, List <ServerLogFactInfo> serverLogFactInfoList)
        {
            try
            {
                ServerLogFactGrowthInfoGenerator <ServerLogFactGrowthInfo> slfg =
                    new ServerLogFactGrowthInfoGenerator <ServerLogFactGrowthInfo>(
                        serverLogFileInfoList.Cast <IServerLogFileInfo>().ToList(),
                        serverLogFactInfoList.Cast <IServerLogFactInfo>().ToList());

                var sliced = slfg.GenerateSlicedList();
                PrintHelper.WriteToConsoleAndLog($"Calculation Completed for file growth rate, got back {sliced.Count()} data sets", true, true);
                PrintHelper.WriteToConsoleAndLog($"Attempting writing to csv files at {Parameters.OutputFolder}", true, true);
                ICsvToObjectMapper <ServerLogFactGrowthInfo> mapper = new CsvToObjectMapper <ServerLogFactGrowthInfo>();
                mapper.AddMap(t => t.FileId, "FileID");
                mapper.AddMap(t => t.FileName, "Name");
                mapper.AddMap(t => t.TimeStampFormatted, "Timestamp");
                mapper.AddMap(t => t.SizeInBytes, "SizeInBytes");
                mapper.AddMap(t => t.GrowthRateInBytesPerHour, "GrowthRateInBytesPerHour");
                ReflectionHelper <ServerLogFactGrowthInfo> rh = new ReflectionHelper <ServerLogFactGrowthInfo>();
                List <string> fileNames = sliced.Select(list => list?.FirstOrDefault()?.FileId + ".csv").ToList();
                ObjectToCsvWriter <ServerLogFactGrowthInfo> objCsvWriter =
                    new ObjectToCsvWriter <ServerLogFactGrowthInfo>(sliced, mapper, new LoggerFactory(), rh,
                                                                    new FileService(), Parameters.OutputFolder, fileNames);
                objCsvWriter.Write();
                PrintHelper.WriteToConsoleAndLog($"Completed writing to {Parameters.OutputFolder}. No of files created {sliced.Count()}", true, true);
            }
            catch (CsvReadWriteException csvException)
            {
                PrintHelper.WriteToConsoleAndLog($"{csvException.ErrorCode}\n{csvException.Message}\n{csvException.StackTrace}", true, false);
                PrintHelper.WriteToConsoleAndLog($"{csvException.ErrorCode}\n{csvException.Message}\nCheck Log for more details", false, true);
                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                PrintHelper.WriteToConsoleAndLog($"{ex.Message}\n{ex.StackTrace}", true, false);
                PrintHelper.WriteToConsoleAndLog($"{ex.Message}\nCheck Log for more details", true, true);
                Environment.Exit(0);
            }
        }