コード例 #1
0
        static void Import(ProgramSetting testing)
        {
            ExcelReaderImporter  excelReaderImporter  = new ExcelReaderImporter();
            LinqToExcelImporter  linqToExcelImporter  = new LinqToExcelImporter();
            ExcelInteropImporter excelInteropImporter = new ExcelInteropImporter();

            string        output = "Data\\Imports";
            List <string> files  = new List <string>();

            if (testing == ProgramSetting.Import)
            {
                files.AddRange(ListFilesRecursively(GlobalSettings.ImportPathCorpus));
            }
            else if (testing == ProgramSetting.ImportTest)
            {
                files.AddRange(Directory.EnumerateFiles("Data\\Corpus"));
            }
            else if (testing == ProgramSetting.HandmadeImport)
            {
                files.AddRange(Directory.EnumerateFiles("Data\\Handmade Examples"));
            }

            //excelReaderImporter.ImportFiles();
            //linqToExcelImporter.ImportFiles();
            excelInteropImporter.ImportFiles(files, output);
        }
コード例 #2
0
        private static void SpreadsheetTestrun()
        {
            ExcelInteropImporter excelInteropImporter = new ExcelInteropImporter();

            string logPath     = Path.Combine("Persistent", "Logs");
            string logFilePath = Path.Combine(logPath, $"importLog_{DateTime.Now.ToFileFormatString()}.txt");

            //Create Logfile and Path
            Directory.CreateDirectory(logPath);
            File.WriteAllText(logFilePath, "");

            string file = GetSpreadsheetFilePathFromUser();

            HandleSpreadsheet(file, excelInteropImporter, "", logFilePath);
        }
コード例 #3
0
        private static void CorpusTestrun(Func <string, bool> acceptCriterion = null, string fileOverwrite = "")
        {
            ExcelInteropImporter excelInteropImporter = new ExcelInteropImporter();

            string remainingOutput = "";
            //string input = Path.Combine("Data", "Handmade Examples");
            string input              = GlobalSettings.ImportPathCorpus;
            string logPath            = Path.Combine("Persistent", "Logs");
            string logFilePath        = Path.Combine(logPath, $"importLog_{DateTime.Now.ToFileFormatString()}.txt");
            string testrunCounterPath = Path.Combine("Persistent", "TestrunCounter.txt");
            //files.AddRange(Directory.EnumerateFiles(input));

            //Init File list
            List <string> files = new List <string>();

            files.AddRange(ListFilesRecursively(input));

            //Set Counter to previous testrun if there was one
            int testrunCounter = getTestrunCounter(testrunCounterPath);

            File.WriteAllText(testrunCounterPath, "" + testrunCounter);

            //Create Logfile and Path
            Directory.CreateDirectory(logPath);
            File.WriteAllText(logFilePath, "");

            for (int i = testrunCounter; i < files.Count; i++)
            {
                string file = files[i];
                if (Path.GetExtension(file).Equals(".txt"))
                {
                    continue;
                }
                if (acceptCriterion != null && !acceptCriterion(file))
                {
                    Logger.DebugLine($"acceptCriterion for file {file} failed.", 7);
                    continue;
                }

                remainingOutput = HandleSpreadsheet(file, excelInteropImporter, remainingOutput, logFilePath);

                File.WriteAllText(testrunCounterPath, "" + i);
            }
        }
コード例 #4
0
        private static string HandleSpreadsheet(string file, ExcelInteropImporter excelInteropImporter, string remainingOutput, string logFilePath)
        {
            string outputPath = Path.Combine("Data", "Imports");

            Logger.DebugLine($"Handmade Testrun file {file} start.", 10);
            Stopwatch stopwatchImport = Stopwatch.StartNew();
            string    output          = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(file));

            Directory.CreateDirectory(output);
            excelInteropImporter.ImportFile(file, output);

            stopwatchImport.Stop();
            Stopwatch stopwatchTypecheck = Stopwatch.StartNew();

            int cellsTotal            = 0;
            int formulasTotal         = 0;
            int errorsTotal           = 0;
            int errorInvocationsTotal = 0;

            List <string> outputFiles = new List <string>();

            outputFiles.AddRange(Directory.EnumerateFiles(output));
            foreach (var outputFile in outputFiles)
            {
                TypecheckFile(outputFile);

                cellsTotal            += LastCells;
                formulasTotal         += LastFormulas;
                errorsTotal           += LastErrors;
                errorInvocationsTotal += LastErrorInvocations;
            }
            stopwatchTypecheck.Stop();
            Logger.DebugLine($"Handmade Testrun file {file} finish.", 10);

            long   typecheckTime = stopwatchTypecheck.ElapsedMilliseconds;
            long   importTime    = stopwatchImport.ElapsedMilliseconds;
            long   totalTime     = typecheckTime + importTime;
            double importPercent = (double)importTime / (double)totalTime;
            long   fileSize      = (long)Math.Round(new FileInfo(file).Length / 1024.0);
            string importOutput  = $"========= {Path.GetFileName(file)} =========\n";

            importOutput += $"Filesize (KB): {fileSize}\n";
            importOutput += $"\n";
            importOutput += $"Cells Total: {cellsTotal}\n";
            importOutput += $"Formulas Total: {formulasTotal}\n";
            importOutput += $"Formulas Percent: {(double)formulasTotal / (double)cellsTotal}\n";
            importOutput += $"\n";
            importOutput += $"Errors Total: {errorsTotal}\n";
            importOutput += $"Error Invocations Total: {errorInvocationsTotal}\n";
            importOutput += $"\n";
            importOutput += $"Typecheck time: {typecheckTime}\n";
            importOutput += $"Import time: {importTime}\n";
            importOutput += $"Total time: {totalTime}\n";
            importOutput += $"Import time Percent: {importPercent}\n";
            importOutput += "===========================================\n";
            importOutput += "\n";
            importOutput += $"\n";
            Logger.DebugLine(importOutput, 10);
            remainingOutput += importOutput;

            try
            {
                File.AppendAllText(logFilePath, remainingOutput);
                remainingOutput = "";
            }
            catch (Exception e)
            {
                Logger.DebugLine("Exception while trying to save Log output", 10);
            }

            return(remainingOutput);
        }