예제 #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
        /**
         * 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);
        }
예제 #3
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);
                }
            }
        }