Ejemplo n.º 1
0
        /// <summary>
        /// Create a copy of a transformer.
        /// </summary>
        /// <param name="id">New id of the transformer, must be unique</param>
        /// <param name="transformer">The transformer to copy.</param>
        /// <returns>A new transformer</returns>
        public static ITransformer CloneTransformer(string id, ITransformer transformer)
        {
            try
            {
                var newConfig = new TransformerConfiguration()
                {
                    Id       = id,
                    ReaderId = transformer.Config.ReaderId,
                    Mappers  = transformer.Config.Mappers,
                    Type     = transformer.Config.Type,
                };
                var mappers = new List <IMapper>();
                foreach (var mapperConfig in newConfig.Mappers)
                {
                    var mapper = CollectorFactory.CreateMapper(mapperConfig);
                    if (mapper == null)
                    {
                        throw new NullReferenceException("Unable to create Collector.  Invalid Mapper defined.");
                    }

                    mappers.Add(mapper);
                }
                var newTransformer = ComponentRegistration.CreateInstance <ITransformer>(newConfig.Type);
                newTransformer.Configure(newConfig, transformer.Handler);
                return(transformer);
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the entire stack.  Invoke run to execute the stack.
        /// </summary>
        /// <param name="readerId">The id of the reader.</param>
        /// <returns>A new stack</returns>
        public IStack CreateStack(string readerId)
        {
            var stack = CollectorFactory.CreateStack(readerId, _config);

            _sema.WaitOne();
            _stacks.Add(stack.Reader.Id, stack);
            _sema.Release();
            return(stack);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a Transformer.
        /// </summary>
        /// <param name="type">The name of the class to create.</param>
        /// <param name="id">The id of the transformer.</param>
        /// <param name="publishers">The publishers to use to publish the JSON data to a repository.</param>
        /// <param name="mappers">The mappers to use to transform/map the data.</param>
        /// <returns>A new handler.</returns>
        public static ITransformer CreateTransformer(TransformerConfiguration config, ITransformedDataHandler handler)
        {
            var mappers = new List <IMapper>();

            foreach (var mapperConfig in config.Mappers)
            {
                var mapper = CollectorFactory.CreateMapper(mapperConfig);
                if (mapper == null)
                {
                    throw new NullReferenceException("Unable to create Collector.  Invalid Mapper defined.");
                }

                mappers.Add(mapper);
            }
            var transformer = ComponentRegistration.CreateInstance <ITransformer>(config.Type);

            transformer.Configure(config, handler);
            return(transformer);
        }