Пример #1
0
        /**
         * Protected constructor. Instances of this class should be obtained
         * through the {@link #create(SensorParams)} factory method.
         *
         * @param params
         */
        protected CustomFileSensor(SensorParams @params)
            : base(@params)
        {
            string pathStr = (string)@params.Get("PATH");

            FileInfo f = new FileInfo(pathStr);

            if (!f.Exists)
            {
                throw new ArgumentException("Passed improperly formed Tuple: invalid PATH: " + @params.Get("PATH"));
            }

            try
            {
                IStream <string> fileStream = new Stream <string>(YieldingFileReader.ReadAllLines(f.FullName, Encoding.UTF8));
                this.stream = BatchedCsvStream <string> .Batch(fileStream, BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE,
                                                               s =>
                {
                    return(s.Split('\t'));
                });
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }
        }
Пример #2
0
 /**
  * Decorator pattern to construct a new HTMSensor wrapping the specified {@link Sensor}.
  *
  * @param sensor
  */
 public HTMSensor(ISensor sensor)
 {
     this.@delegate = sensor;
     sensorParams   = sensor.GetSensorParams();
     header         = new Header(sensor.GetInputStream().GetMeta());
     if (header == null || header.Size() < 3)
     {
         throw new InvalidOperationException("Header must always be present; and have 3 lines.");
     }
     CreateEncoder();
 }
Пример #3
0
        /// <summary>
        /// <p>Creates and returns the <see cref="Sensor"/> subtype indicated by the method reference passed in for the SensorFactory <see cref="Func{SensorParams, Sensor{T}}"/>
        /// argument. <br/><br/><b>Typical usage is as follows:</b></p>
        /// <p><pre>Sensor.create(FileSensor.Create, SensorParams); //Can be URISensor, or ObservableSensor</pre></p>
        /// </summary>
        /// <param name="factoryMethod">the <see cref="Func{SensorParams, Sensor{T}}"/> or method reference. SensorFactory is a {@link FunctionalInterface}</param>
        /// <param name="t">the <see cref="SensorParams"/> which hold the configuration and data source details.</param>
        /// <returns></returns>
        public static Sensor <T> Create(Func <SensorParams, ISensor> factoryMethod, SensorParams t)
        {
            if (factoryMethod == null)
            {
                throw new InvalidOperationException("Factory cannot be null");
            }
            if (t == null)
            {
                throw new InvalidOperationException("Properties (i.e. \"SensorParams\") cannot be null");
            }

            return(new HTMSensor <T>(factoryMethod(t)));
        }
Пример #4
0
        /**
         * Creates a new {@code ObservableSensor} using the specified
         * {@link SensorParams}
         *
         * @param params
         */
        internal ObservableSensor(SensorParams @params)
        {
            if ([email protected]("ONSUB"))
            {
                throw new ArgumentException("Passed improperly formed Tuple: no key for \"ONSUB\"");
            }

            this.@params = @params;

            IObservable <string> obs = null;
            object publisher         = @params.Get("ONSUB");

            if (publisher is Publisher)
            {
                obs = ((Publisher)publisher).Observable();
            }
            else if (publisher is PublisherSupplier)
            {
                obs = ((PublisherSupplier)publisher).Get().Observable();
            }
            else
            {
                obs = (IObservable <string>)@params.Get("ONSUB");
            }
            //IEnumerator<string> observerator = obs.GetEnumerator();

            //IEnumerator<string> iterator = new CustomIterator<string>(
            //    () =>
            //    {
            //        bool moved = observerator.MoveNext();
            //        return new System.Tuple<bool, string>(moved, observerator.Current);
            //    });

            //Iterator<String> iterator = new Iterator<String>() {
            //    public boolean hasNext() { return observerator.hasNext(); }
            //    public String next()
            //    {
            //        return observerator.next();
            //    }
            //};

            //int characteristics = Spliterator.SORTED | Spliterator.ORDERED;
            //Spliterator<string> spliterator = Spliterators.spliteratorUnknownSize(iterator, characteristics);

            this.stream = BatchedCsvStream <string> .Batch(
                new Stream <string>(obs), BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE);
        }
Пример #5
0
        /**
         * Protected constructor. Instances of this class should be obtained
         * through the {@link #create(SensorParams)} factory method.
         *
         * @param params
         */
        protected FileSensor(SensorParams @params)
        {
            this.@params = @params;

            if ([email protected]("PATH"))
            {
                throw new ArgumentException("Passed improperly formed Tuple: no key for \"PATH\"");
            }

            string pathStr = (string)@params.Get("PATH");

            if (pathStr.IndexOf("!") != -1)
            {
                pathStr = pathStr.Substring("file:".Length);

                IStream <string> stream = GetZipEntryStream(pathStr);
                this.stream = BatchedCsvStream <string> .Batch(stream, BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE);
            }
            else
            {
                FileInfo f = new FileInfo(pathStr);
                if (!f.Exists)
                {
                    throw new ArgumentException("Passed improperly formed Tuple: invalid PATH: " + @params.Get("PATH"));
                }

                try
                {
                    IStream <string> fileStream = new Stream <string>(YieldingFileReader.ReadAllLines(f.FullName, Encoding.UTF8));
                    this.stream = BatchedCsvStream <string> .Batch(fileStream, BATCH_SIZE, DEFAULT_PARALLEL_MODE, HEADER_SIZE);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Пример #6
0
        /**
         * Factory method to allow creation through the {@link SensorFactory} in
         * the {@link Sensor#create(SensorFactory, SensorParams)} method of the
         * parent {@link Sensor} class. This indirection allows the decoration of
         * the returned {@code Sensor} type by wrapping it in an {@link HTMSensor}
         * (which is the current implementation but could be any wrapper).
         *
         * @param p     the {@link SensorParams} which describe connection or source
         *              data details.
         * @return      the Sensor.
         */
        public static Sensor <FileInfo> Create(SensorParams p)
        {
            Sensor <FileInfo> fs = new FileSensor(p);

            return(fs);
        }
Пример #7
0
        public static ObservableSensor <T> Create(SensorParams p)
        {
            ObservableSensor <string[]> sensor = new ObservableSensor <string[]>(p);

            return(sensor as ObservableSensor <T>);
        }