Beispiel #1
0
        public static ICollection <ExecutionResult> GetQueryResults()
        {
            var resultSets = new List <ExecutionResult>();

            var progressReporter = new ProgressReporter("DataReader.GetQueryResults", Parameters.Instance.Targets.Databases.Count(), s => Console.Error.WriteLine(s));

            if (Parameters.Instance.Sequential)
            {
                foreach (var database in Parameters.Instance.Targets.Databases)
                {
                    var result = QueryDatabase(database);
                    progressReporter.Increment();

                    if (result == null)
                    {
                        continue;
                    }

                    resultSets.Add(result);
                }
            }
            else
            {
                var options = new ParallelOptions {
                    MaxDegreeOfParallelism = Parameters.Instance.Parallelism
                };

                Parallel.ForEach(Parameters.Instance.Targets.Databases, options, (database) =>
                {
                    var result = QueryDatabase(database);
                    progressReporter.Increment();

                    if (result == null)
                    {
                        return;
                    }

                    lock (resultSets)
                    {
                        resultSets.Add(result);
                    }
                });
            }

            progressReporter.Done();

            // ReSharper disable once InconsistentlySynchronizedField : Parallelization is already finished when this is reached.
            Logger.Info($"Maximum concurrent queries : {_maxConcurrentExecutingQueries} queries.");

            return(resultSets);
        }
Beispiel #2
0
        public static void Generate(ICollection <Table> tables)
        {
            if (tables == null)
            {
                throw new ArgumentNullException(nameof(tables), "Parameter cannot be null.");
            }

            MemoryManager.Clean();

            var destination = Path.IsPathRooted(Parameters.Instance.OutputFile)
                ? Parameters.Instance.OutputFile
                : Path.Combine(Parameters.Instance.OutputDirectory, Parameters.Instance.OutputFile);

            Logger.Info($"Creating excel file '{destination}'");

            using (var spreadSheet = SpreadsheetDocument.Create(destination, SpreadsheetDocumentType.Workbook))
            {
                Logger.Info("Created excel file");
                spreadSheet.AddWorkbookPart();

                var wbsp = spreadSheet.WorkbookPart.AddNewPart <WorkbookStylesPart>();
                wbsp.Stylesheet = CreateStylesheet();
                wbsp.Stylesheet.Save();

                spreadSheet.WorkbookPart.Workbook = new Workbook
                {
                    Sheets = new Sheets()
                };

                var progressReporter = new ProgressReporter("ExcelExporter.Generate", Parameters.Instance.Targets.Databases.Count(), s => Console.Error.WriteLine(s));

                var tableIndex = 0;
                foreach (var table in tables)
                {
                    Logger.Info("Adding new excel sheet.");

                    if (table.Rows.Count > ExcelTotalNumberRowsMaximumLimit - 1)
                    {
                        Logger.Error($"Table '{table.Id}' not exported in excel file because it had too many rows. The table has {table.Rows.Count} rows and {table.Columns.Length} columns. The maximum number of rows supported by excel is {ExcelTotalNumberRowsMaximumLimit}.");
                        continue;
                    }

                    var sheetNameById        = GetSheetNameFromTableId(table.Id);
                    var sheetNameByParameter = GetSheetNameFromParameter(tableIndex);
                    AddSheet(spreadSheet, table, sheetNameById ?? sheetNameByParameter);
                    progressReporter.Increment();
                    tableIndex++;
                }

                progressReporter.Done();

                var flushedTableTarget = LogManager.Configuration.FindTargetByName <AutoFlushTargetWrapper>("flushedTableTarget");
                var target             = flushedTableTarget.WrappedTarget as TableTarget;

                if (target == null)
                {
                    throw new InvalidOperationException("Logger's wrapped table target could not be recovered. It should never happens as this target should be added very early in Program.Main().");
                }

                MemoryManager.Clean();

                Logger.Info("Excel file logging horizon. Check console output to see beyond horizon.");

                if (Parameters.Instance.ShowLogSheet)
                {
                    var logTable = target.Logs;
                    AddSheet(spreadSheet, logTable, "Logs");
                }

                if (Parameters.Instance.ShowParameterSheet)
                {
                    var parameterTable = ParametersToTable(Parameters.Instance);
                    AddSheet(spreadSheet, parameterTable, "Parameters");
                }

                MemoryManager.Clean();

                Logger.Info("Finalizing excel file writing.");
            }

            Logger.Info("Excel file closed after generation.");
            MemoryManager.Clean();
        }