Exemple #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ExecutionContext"/>
        ///     class.
        /// </summary>
        public ExecutionContext(
            IProgress <int> progress,
            Func <ICustomDataProcessor, ILogger> loggerFactory,
            ICustomDataSource customDataSource,
            IEnumerable <IDataSource> dataSources,
            IEnumerable <TableDescriptor> tablesToEnable,
            IProcessorEnvironment processorEnvironment,
            ProcessorOptions commandLineOptions)
        {
            Guard.NotNull(progress, nameof(progress));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(customDataSource, nameof(customDataSource));
            Guard.NotNull(dataSources, nameof(dataSources));
            Guard.All(dataSources, x => x != null, nameof(dataSources));
            Guard.NotNull(tablesToEnable, nameof(tablesToEnable));
            Guard.All(tablesToEnable, x => x != null, nameof(tablesToEnable));
            Guard.NotNull(processorEnvironment, nameof(processorEnvironment));
            Guard.NotNull(commandLineOptions, nameof(commandLineOptions));

            this.ProgressReporter     = progress;
            this.LoggerFactory        = loggerFactory;
            this.CustomDataSource     = customDataSource;
            this.DataSources          = dataSources.ToList().AsReadOnly();
            this.TablesToEnable       = tablesToEnable.ToList().AsReadOnly();
            this.ProcessorEnvironment = processorEnvironment;
            this.CommandLineOptions   = commandLineOptions;
        }
Exemple #2
0
        /// <summary>
        ///     Extension method to return the file extension description for a <see cref="ICustomDataSource"/>.
        /// </summary>
        /// <returns>
        ///     Returns the file extension description; <c>null</c> if not defined.
        /// </returns>
        public static string TryGetFileDescription(this ICustomDataSource self)
        {
            var dataSource     = self.GetType().GetCustomAttribute <DataSourceAttribute>();
            var fileDataSource = dataSource as FileDataSourceAttribute;

            return(fileDataSource?.Description);
        }
Exemple #3
0
        /// <summary>
        ///     Extension method to check if the file is supported by the <see cref="ICustomDataSource"/>.
        /// </summary>
        /// <param name="filePath">
        ///     Full path to the file being checked.
        /// </param>
        /// <returns>
        ///     <inheritdoc cref="ICustomDataSource.IsFileSupported(string)"/>
        /// </returns>
        public static bool Supports(this ICustomDataSource self, string filePath)
        {
            var supportedExtension = FileExtensionUtils.CanonicalizeExtension(self.TryGetFileExtension());
            var fileExtension      = FileExtensionUtils.CanonicalizeExtension(Path.GetExtension(filePath));

            // Should this be invariant culture?
            return(StringComparer.CurrentCultureIgnoreCase.Equals(fileExtension, supportedExtension) &&
                   self.IsFileSupported(filePath));
        }
Exemple #4
0
        /// <summary>
        ///     Extension method to return the <see cref="Guid"/> for a <see cref="ICustomDataSource"/>.
        /// </summary>
        /// <returns>
        ///     Returns the <see cref="Guid"/> of the <see cref="ICustomDataSource"/>; <see cref="Guid.Empty"/> if not defined.
        /// </returns>
        public static Guid TryGetGuid(this ICustomDataSource self)
        {
            var dataSourceId = self.GetType().GetCustomAttribute <CustomDataSourceAttribute>()?.Guid;

            return(dataSourceId.HasValue ? dataSourceId.Value : Guid.Empty);
        }
Exemple #5
0
 /// <summary>
 ///     Extension method to return the description for a <see cref="ICustomDataSource"/>.
 /// </summary>
 /// <returns>
 ///     Returns the description of the <see cref="ICustomDataSource"/>; <c>null</c> if not defined.
 /// </returns>
 public static string TryGetDescription(this ICustomDataSource self)
 {
     return(self.GetType().GetCustomAttribute <CustomDataSourceAttribute>()?.Description);
 }
Exemple #6
0
 /// <summary>
 ///     Extension method to return the name for a <see cref="ICustomDataSource"/>.
 /// </summary>
 /// <returns>
 ///     Returns the name of the <see cref="ICustomDataSource"/>; <c>null</c> if not defined.
 /// </returns>
 public static string TryGetName(this ICustomDataSource self)
 {
     return(self.GetType().GetCustomAttribute <CustomDataSourceAttribute>()?.Name);
 }