Exemplo n.º 1
0
        /// <summary>
        /// Verifies so that all headers in input files looks sane:
        /// <ul>
        /// <li>node/relationship headers can be parsed correctly</li>
        /// <li>relationship headers uses ID spaces previously defined in node headers</li>
        /// </ul>
        /// </summary>
        private void VerifyHeaders()
        {
            try
            {
                // parse all node headers and remember all ID spaces
                foreach (DataFactory dataFactory in _nodeDataFactory)
                {
                    using (CharSeeker dataStream = charSeeker(new MultiReadable(dataFactory.Create(_config).stream()), _config, true))
                    {
                        // Parsing and constructing this header will create this group,
                        // so no need to do something with the result of it right now
                        _nodeHeaderFactory.create(dataStream, _config, _idType, _groups);
                    }
                }

                // parse all relationship headers and verify all ID spaces
                foreach (DataFactory dataFactory in _relationshipDataFactory)
                {
                    using (CharSeeker dataStream = charSeeker(new MultiReadable(dataFactory.Create(_config).stream()), _config, true))
                    {
                        // Merely parsing and constructing the header here will as a side-effect verify that the
                        // id groups already exists (relationship header isn't allowed to create groups)
                        _relationshipHeaderFactory.create(dataStream, _config, _idType, _groups);
                    }
                }
            }
            catch (IOException e)
            {
                throw new UncheckedIOException(e);
            }
        }
Exemplo n.º 2
0
            public override Header Create(CharSeeker dataSeeker, Configuration config, IdType idType, Groups groups)
            {
                try
                {
                    Mark       mark       = new Mark();
                    Extractors extractors = new Extractors(config.arrayDelimiter(), config.emptyQuotedStringsAsNull(), config.trimStrings(), DefaultTimeZone);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.csv.reader.Extractor<?> idExtractor = idType.extractor(extractors);
                    Extractor <object> idExtractor = idType.extractor(extractors);
                    int delimiter = config.delimiter();
                    IList <Header.Entry> columns = new List <Header.Entry>();
                    for (int i = 0; !mark.EndOfLine && dataSeeker.Seek(mark, delimiter); i++)
                    {
                        string          entryString = dataSeeker.TryExtract(mark, extractors.String()) ? extractors.String().value() : null;
                        HeaderEntrySpec spec        = new HeaderEntrySpec(entryString);

                        if ((string.ReferenceEquals(spec.Name, null) && string.ReferenceEquals(spec.Type, null)) || (!string.ReferenceEquals(spec.Type, null) && spec.Type.Equals(Type.Ignore.name())))
                        {
                            columns.Add(new Header.Entry(null, Type.Ignore, [email protected]_Fields.Global, null, null));
                        }
                        else
                        {
                            Group group = CreateGroups ? groups.GetOrCreate(spec.GroupName) : groups.Get(spec.GroupName);
                            columns.Add(Entry(i, spec.Name, spec.Type, group, extractors, idExtractor));
                        }
                    }
                    Entry[] entries = columns.ToArray();
                    ValidateHeader(entries);
                    return(new Header(entries));
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            }
Exemplo n.º 3
0
 public CsvInputParser(CharSeeker seeker, int delimiter, IdType idType, Header header, Collector badCollector, Extractors extractors)
 {
     this._seeker          = seeker;
     this._delimiter       = delimiter;
     this._idType          = idType;
     this._header          = header;
     this._badCollector    = badCollector;
     this._stringExtractor = extractors.String();
 }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertNextLine(String[] line, CharSeeker seeker, Mark mark, Extractors extractors) throws java.io.IOException
        private void AssertNextLine(string[] line, CharSeeker seeker, Mark mark, Extractors extractors)
        {
            foreach (string value in line)
            {
                assertTrue(seeker.Seek(mark, _delimiter));
                assertEquals(value, seeker.Extract(mark, extractors.String()).value());
            }
            assertTrue(mark.EndOfLine);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadFromMultipleReaders() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReadFromMultipleReaders()
        {
            // GIVEN
            string[][] data = new string[][]
            {
                new string[] { "this is", "the first line" },
                new string[] { "where this", "is the second line" },
                new string[] { "and here comes", "the third line" }
            };
            RawIterator <CharReadable, IOException> readers = ReaderIteratorFromStrings(data, null);
            CharSeeker seeker = CharSeekers.CharSeeker(new MultiReadable(readers), CONFIG, true);

            // WHEN/THEN
            foreach (string[] line in data)
            {
                AssertNextLine(line, seeker, _mark, _extractors);
            }
            assertFalse(seeker.Seek(_mark, _delimiter));
            seeker.Dispose();
        }