/// <summary>
 ///     Attempts to get the argument of a given option.
 ///     If the option allows for multiple options or the
 ///     option is not present, then this method will return
 ///     <c>false</c>.
 /// </summary>
 /// <param name="self">
 ///     The instance to interrogate.
 /// </param>
 /// <param name="option">
 ///     The option whose argument is to be retrieved.
 /// </param>
 /// <param name="argument">
 ///     The argument, if it exists; <c>null</c> otherwise.
 /// </param>
 /// <returns>
 ///     <c>true</c> if the argument was found; <c>false</c>
 ///     otherwise.
 /// </returns>
 /// <exception cref="System.ArgumentNullException">
 ///     <paramref name="option"/> is <c>null</c>.
 ///     - or -
 ///     <paramref name="self"/> is <c>null</c>.
 /// </exception>
 public static bool TryGetOptionArgument(
     this ProcessorOptions self,
     Option option,
     out string argument)
 {
     return(self.TryGetOptionArgument(option.Id, out argument));
 }
        /// <summary>
        ///     Attempts to get the argument of a given option.
        ///     If the option allows for multiple options or the
        ///     option is not present, then this method will return
        ///     <c>false</c>.
        /// </summary>
        /// <param name="self">
        ///     The instance to interrogate.
        /// </param>
        /// <param name="id">
        ///     The option whose argument is to be retrieved.
        /// </param>
        /// <param name="argument">
        ///     The argument, if it exists; <c>null</c> otherwise.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the argument was found; <c>false</c>
        ///     otherwise.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="id"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="self"/> is <c>null</c>.
        /// </exception>
        public static bool TryGetOptionArgument(
            this ProcessorOptions self,
            object id,
            out string argument)
        {
            Guard.NotNull(self, nameof(self));
            Guard.NotNull(id, nameof(id));

            if (self.Options.TryGetOptionArguments(id, out IEnumerable <string> allArguments))
            {
                var enumerator = allArguments.GetEnumerator();
                if (enumerator.MoveNext())
                {
                    // save the first argument.
                    argument = enumerator.Current;
                    if (enumerator.MoveNext())
                    {
                        // we have more than one argument, so fail.
                        argument = null;
                    }
                }
                else
                {
                    // no arguments
                    argument = null;
                }
            }
            else
            {
                // no arguments
                argument = null;
            }

            return(argument != null);
        }
        /// <summary>
        ///     Determines whether the given instance contains the
        ///     given option.
        /// </summary>
        /// <param name="self">
        ///     The instance to interrogate.
        /// </param>
        /// <param name="id">
        ///     The flag to check.
        /// </param>
        /// <returns>
        ///     <c>true</c> if <paramref name="id"/> is present in
        ///     <paramref name="self"/>; <c>false</c> otherwise.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="self"/> is <c>null</c>.
        /// </exception>
        public static bool IsOptionPresent(
            this ProcessorOptions self,
            object id)
        {
            Guard.NotNull(self, nameof(self));

            return(self.Options.Any(x => x.Id.Equals(id)));
        }
        /// <summary>
        ///     Determines whether the given instance contains the
        ///     given option.
        /// </summary>
        /// <param name="self">
        ///     The instance to interrogate.
        /// </param>
        /// <param name="flag">
        ///     The flag to check.
        /// </param>
        /// <returns>
        ///     <c>true</c> if <paramref name="flag"/> is present in
        ///     <paramref name="self"/>; <c>false</c> otherwise.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="flag"/> is <c>null</c>.
        ///     - or -
        ///     <paramref name="self"/> is <c>null</c>.
        /// </exception>
        public static bool IsOptionPresent(
            this ProcessorOptions self,
            Option flag)
        {
            Guard.NotNull(flag, nameof(flag));

            return(self.IsOptionPresent(flag.Id));
        }
        /// <summary>
        ///     Attempts to get all of the arguments passed to a given
        ///     option.
        /// </summary>
        /// <param name="self">
        ///     The instance to interrogate.
        /// </param>
        /// <param name="id">
        ///     The option whose arguments are to be retrieved.
        /// </param>
        /// <param name="arguments">
        ///     The arguments, if the option is found. If the option
        ///     exists but there are no arguments, this method will still
        ///     return <c>true</c> and this parameter will be set to
        ///     the empty collection.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the option was found; <c>false</c>
        ///     otherwise.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="self"/> is <c>null</c>.
        /// </exception>
        public static bool TryGetOptionArguments(
            this ProcessorOptions self,
            char id,
            out IEnumerable <string> arguments)
        {
            Guard.NotNull(self, nameof(self));

            return(self.Options.TryGetOptionArguments(id, out arguments));
        }
Esempio n. 6
0
        /// <inheritdoc />
        public ICustomDataProcessor CreateProcessor(
            IDataSource dataSource,
            IProcessorEnvironment processorEnvironment,
            ProcessorOptions options)
        {
            Guard.NotNull(dataSource, nameof(dataSource));

            return(this.CreateProcessor(
                       new[] { dataSource, },
                       processorEnvironment,
                       options));
        }
        /// <summary>
        /// This constructor will setup the data processor so that it can use the data extension framework - allowing
        /// table and data cookers both internally and external to this plug-in.
        /// </summary>
        /// <param name="sourceParser">The source data parser</param>
        /// <param name="options">Processor options</param>
        /// <param name="applicationEnvironment">Application environment</param>
        /// <param name="processorEnvironment">Processor environment</param>
        /// <param name="allTablesMapping">Maps table descriptors to possible build actions</param>
        /// <param name="metadataTables">Metadata tables</param>
        protected CustomDataProcessorBaseWithSourceParser(
            ISourceParser <T, TContext, TKey> sourceParser,
            ProcessorOptions options,
            IApplicationEnvironment applicationEnvironment,
            IProcessorEnvironment processorEnvironment,
            IReadOnlyDictionary <TableDescriptor, Action <ITableBuilder, IDataExtensionRetrieval> > allTablesMapping,
            IEnumerable <TableDescriptor> metadataTables)
            : base(options, applicationEnvironment, processorEnvironment, allTablesMapping, metadataTables)
        {
            Guard.NotNull(sourceParser, nameof(sourceParser));

            this.SourceParser            = sourceParser;
            this.SourceProcessingSession = this.ApplicationEnvironment.SourceSessionFactory.CreateSourceSession(this);
            this.extensibilitySupport    = this.ProcessorEnvironment.CreateDataProcessorExtensibilitySupport(this);

            foreach (var metadataTable in metadataTables)
            {
                ProcessTableForExtensibility(metadataTable);
            }
        }
Esempio n. 8
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CustomDataProcessorBase"/>
        ///     class.
        /// </summary>
        protected CustomDataProcessorBase(
            ProcessorOptions options,
            IApplicationEnvironment applicationEnvironment,
            IProcessorEnvironment processorEnvironment,
            IReadOnlyDictionary <TableDescriptor, Action <ITableBuilder, IDataExtensionRetrieval> > allTablesMapping,
            IEnumerable <TableDescriptor> metadataTables)
        {
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(applicationEnvironment, nameof(applicationEnvironment));
            Guard.NotNull(allTablesMapping, nameof(allTablesMapping));
            Guard.NotNull(metadataTables, nameof(metadataTables));
            Guard.NotNull(processorEnvironment, nameof(processorEnvironment));

            this.enabledTables = new HashSet <TableDescriptor>(metadataTables);

            this.ApplicationEnvironment = applicationEnvironment;
            this.ProcessorEnvironment   = processorEnvironment;
            this.EnabledTables          = new ReadOnlyHashSet <TableDescriptor>(this.enabledTables);
            this.Options = options;
            this.TableDescriptorToBuildAction = allTablesMapping;
            this.Logger = processorEnvironment.CreateLogger(this.GetType());
        }
Esempio n. 9
0
        /// <inheritdoc />
        public ICustomDataProcessor CreateProcessor(
            IEnumerable <IDataSource> dataSources,
            IProcessorEnvironment processorEnvironment,
            ProcessorOptions options)
        {
            Guard.NotNull(dataSources, nameof(dataSources));
            Guard.NotNull(processorEnvironment, nameof(processorEnvironment));
            Guard.NotNull(options, nameof(options));
            Guard.All(dataSources, x => x != null, nameof(dataSources));

            var processor = this.CreateProcessorCore(
                dataSources,
                processorEnvironment,
                options);

            if (processor is null)
            {
                throw new InvalidOperationException("CreateProcessorCore is not allowed to return null.");
            }

            return(processor);
        }
Esempio n. 10
0
 /// <summary>
 ///     When implemented in a derived class, creates a new
 ///     instance implementing <see cref="ICustomDataProcessor"/>
 ///     to process the specified data sources.
 /// </summary>
 /// <param name="dataSources">
 ///     The data sources to be processed by the processor.
 ///     This parameter is guaranteed to be non-null, and all
 ///     elements in the collection are guaranteed to be non-null.
 /// </param>
 /// <param name="processorEnvironment">
 ///     The environment for this specific processor instance.
 /// </param>
 /// <param name="options">
 ///     The options to pass to the processor.
 /// </param>
 /// <returns>
 ///     A new <see cref="ICustomDataProcessor"/>. It is an error
 ///     to return <c>null</c> from this method.
 /// </returns>
 protected abstract ICustomDataProcessor CreateProcessorCore(
     IEnumerable <IDataSource> dataSources,
     IProcessorEnvironment processorEnvironment,
     ProcessorOptions options);