Ejemplo n.º 1
0
        /// <summary>
        /// configures the repository to handle a new kind of data-format (row placement of data)
        /// </summary>
        /// <param name="headerRowIndex">index (1-Based) of the header row</param>
        /// <param name="dataStartRowIndex">index (1-Based) of the first data row</param>
        /// <param name="dataEndRowIndex">index (1-Based) of last valid Row; use 0 = unlimited but EndRowIndicator must be supplied.</param>
        /// <param name="endRowIndicator">returns true if parsed entry is not a valid row anymore. this marked row will be discarded</param>
        protected virtual void ValidateExcelSourceConfiguration(ExcelFileOptions options, ExcelContext context)
        {
            var excelEntityTypeBuilder = (context.ObtainEntityFromDictionary <TEntity>() as ExcelEntityBuilder <TEntity>);

            if (excelEntityTypeBuilder == null)
            {
                throw new ArgumentOutOfRangeException(nameof(options.HeaderLineNumber), $"Excel-{nameof(options.HeaderLineNumber)} indices are 1-Based.");
            }

            #region ParameterChecks
            if (options.HeaderLineNumber < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(options.HeaderLineNumber), $"Excel-{nameof(options.HeaderLineNumber)} indices are 1-Based.");
            }
            if (options.DataStartLineNumber < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(options.DataStartLineNumber), $"Excel-{nameof(options.DataStartLineNumber)} indices are 1-Based.");
            }

            if (options.DataMaximumLineNumber != ExcelFileOptions.DEFAULT_END_UNLIMITED && options.DataStartLineNumber > options.DataMaximumLineNumber)
            {
                throw new ArgumentOutOfRangeException($"{nameof(options.DataStartLineNumber)}{nameof(options.DataMaximumLineNumber)}"
                                                      , $"{nameof(options.DataStartLineNumber)} must not be higher than {nameof(options.DataMaximumLineNumber)}");
            }
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// create new instance of <see cref="EPPlusDomainRepository"/> <br/>
        /// </summary>
        /// <param name="context">inforamtion about the data context i.e. entity mapping, general file options</param>
        /// <param name="excelFileOptions">data and options related to file specific information i.e. file location, data start, data length</param>
        /// <param name="logger">used for internal logging prints</param>
        public EPPlusDomainRepository(ExcelContext context, ExcelFileOptions excelFileOptions,
                                      ILogger <EPPlusDomainRepository <TEntity, TKey> > logger = null)
        {
            _logger = logger;

            Context          = context;
            ExcelFileOptions = excelFileOptions;

            TargetProperties = Context.GetPropertyBuilders <TEntity>();

            ValidateExcelSourceConfiguration(excelFileOptions, context);

            if (excelFileOptions.ExcelFileStream != null)
            {
                SetExcelDataSource(excelFileOptions.ExcelFileStream, excelFileOptions.WorksheetName, excelFileOptions.FilePassword);
            }
        }
Ejemplo n.º 3
0
            public static IExcelRepository <DomainObject_FluentApi, int> GetRepo_EndIndicator(ExcelContext context,
                                                                                              ExcelFileOptions fileOptions,
                                                                                              ILogger <EPPlusDomainRepository <DomainObject_FluentApi, int> > logger = null)
            {
                //how does the Domain object look like when no data is available anymore?
                //in our case primary key will still have the row id but both name fields will be null or empty string
                context.AddEndDelimiter <DomainObject_FluentApi>(x => string.IsNullOrEmpty(x.Prename) && string.IsNullOrEmpty(x.Surname));

                return(new EPPlusDomainRepository <DomainObject_FluentApi, int>(context,
                                                                                fileOptions,
                                                                                logger));;
            }
Ejemplo n.º 4
0
            public static IExcelRepository <DomainObject_FluentApi, int> GetRepo_LengthDelimited(ExcelContext context,
                                                                                                 ExcelFileOptions fileOptions,
                                                                                                 ILogger <EPPlusDomainRepository <DomainObject_FluentApi, int> > logger = null)
            {
                fileOptions.DataMaximumLineNumber = UnitTestMetadata.DelimitedExcelRepo_MaxmimumLineNumber;

                return(new EPPlusDomainRepository <DomainObject_FluentApi, int>(context,
                                                                                fileOptions,
                                                                                logger));
            }