Beispiel #1
0
        public DiffClient(Task task, DiffClientOptions options, object exportLockObject)
        {
            task.LoadConfig(options.DefaultOutputFilePath, options.QueryParameters);

            ExportLockObject = exportLockObject;

            var leftDataSourceSetting  = task.Sources[0];
            var rightDataSourceSetting = task.Sources[1];

            ReaderOfLeftDataSource  = new SqlServerDataReader();
            ReaderOfRightDataSource = new SqlServerDataReader();

            ReadOptionsOfLeftSource = new SqlServerReaderOptions(leftDataSourceSetting.Name, task.Columns.PrimaryColumns,
                                                                 leftDataSourceSetting.ConnectionString, leftDataSourceSetting.QueryString, leftDataSourceSetting.QueryParameters, options.DefaultTimeout);
            ReadOptionsOfRightSource = new SqlServerReaderOptions(rightDataSourceSetting.Name, task.Columns.PrimaryColumns,
                                                                  rightDataSourceSetting.ConnectionString, rightDataSourceSetting.QueryString, rightDataSourceSetting.QueryParameters, options.DefaultTimeout);

            MergeOptions = new MergeOptions(leftDataSourceSetting.Name, rightDataSourceSetting.Name,
                                            task.Columns.CompareColumns, task.GapMapping);

            ColumnNameBuilder = new ExcelColumnNameBuilder(options.SuffixOfGapColumn, options.SuffixOfCompareResultColumn);

            ExcelHighlighter = new ExcelHighlighter(ColumnNameBuilder);

            DataExporter = new ExcelExporter();
            var highlightOptions = new HighlightOptions(leftDataSourceSetting.Name, rightDataSourceSetting.Name);

            ExportOptions = new ExcelExportOptions(task.Name, task.Report.Path, highlightOptions);
        }
Beispiel #2
0
        public void Highlight(IXLWorksheet worksheet, HighlightOptions options)
        {
            if (worksheet == null)
            {
                throw new ArgumentNullException("worksheet");
            }
            var headerRow             = worksheet.FirstRowUsed();
            var compareRelatedColumns =
                FindColumnsBySuffix(headerRow, options.NameOfLeftDataSource, options.NameOfRightDataSource)
                .ToList();

            var compareRelatedColumnNames = compareRelatedColumns.Select(l => l.Key);

            // hide gap & compare result column
            foreach (var column in compareRelatedColumns)
            {
                if (columnNameBuilder.IsGapColumn(column.Key) || columnNameBuilder.IsCompareResultColumn(column.Key))
                {
                    worksheet.Column(column.Value.ColumnNumber).Hide();
                }
            }

            // create formula
            var cellValueMissingFormulaFormats  = new Dictionary <string, string>();
            var cellValueNotEqualFormulaFormats = new Dictionary <string, string>();
            var cellValueSimilarFormulaFormats  = new Dictionary <string, string>();
            var cellValueEqualFormulaFormats    = new Dictionary <string, string>();

            var underlyingColumns = columnNameBuilder.GetUnderlyingColumnNames(compareRelatedColumnNames, new[] { options.NameOfLeftDataSource, options.NameOfRightDataSource });

            foreach (var underlyingColumn in underlyingColumns)
            {
                var leftColumnName    = columnNameBuilder.BuildColumName(options.NameOfLeftDataSource, underlyingColumn);
                var rightColumnName   = columnNameBuilder.BuildColumName(options.NameOfRightDataSource, underlyingColumn);
                var gapColumnName     = columnNameBuilder.BuildGapColumnName(underlyingColumn);
                var compareColumnName = columnNameBuilder.BuildCompareResultColumnName(underlyingColumn);

                var leftColumn =
                    compareRelatedColumns.FirstOrDefault(l => leftColumnName.Equals(l.Key, StringComparison.OrdinalIgnoreCase));
                var rightColumn =
                    compareRelatedColumns.FirstOrDefault(l => rightColumnName.Equals(l.Key, StringComparison.OrdinalIgnoreCase));
                var gapColumn =
                    compareRelatedColumns.FirstOrDefault(l => gapColumnName.Equals(l.Key, StringComparison.OrdinalIgnoreCase));
                var compareColumn =
                    compareRelatedColumns.FirstOrDefault(l => compareColumnName.Equals(l.Key, StringComparison.OrdinalIgnoreCase));

                CreateFormula(leftColumn, rightColumn, gapColumn, compareColumn, cellValueMissingFormulaFormats, cellValueSimilarFormulaFormats, cellValueEqualFormulaFormats, cellValueNotEqualFormulaFormats);
            }

            var contentRows = worksheet.RowsUsed().Skip(1).ToList();

            ApplyFormula(contentRows,
                         cellValueEqualFormulaFormats, cellValueMissingFormulaFormats, cellValueSimilarFormulaFormats, cellValueNotEqualFormulaFormats);
        }