public IDEntityCollection(IGTFSDataSource source, string tableName, GTFSEntityFactory <T> factory)
        {
            Dict     = new Dictionary <string, T>();
            Unparsed = new List <GTFSUnparsedEntity>();

            foreach (T item in source.GetObjects(tableName, factory, Unparsed))
            {
                Dict.Add(item.ID, item);
            }
        }
        public GTFSGenericCollection(IGTFSDataSource source, string tableName, GTFSEntityFactory <T> factory)
        {
            Backing  = new();
            Unparsed = new();

            foreach (T item in source.GetObjects(tableName, factory, Unparsed))
            {
                Backing.Add(item);
            }
        }
Exemple #3
0
        public IEnumerable <T> GetObjects <T>(string table, GTFSEntityFactory <T> factory, List <GTFSUnparsedEntity> unparsed = null) where T : GTFSEntity
        {
            // Get the file:
            ZipArchiveEntry file = Archive.GetEntry(table);

            // If that's not found, try appending .txt:
            if (file == null)
            {
                file = Archive.GetEntry($"{table}.txt");
            }

            // If still nout found, return an empty collection.
            if (file == null)
            {
                yield break;
            }

            using var stream = new StreamReader(file.Open());
            var rows = CSVParser.EnumerableToRows(FileUtils.StreamCharEnumerator(stream));

            List <string> header = new List <string>();
            bool          first  = true;

            foreach (List <string> row in rows)
            {
                if (first)
                {
                    header = row;
                    first  = false;
                    continue;
                }

                var props = header.Zip(row);

                T obj;

                try
                {
                    obj = factory(props);
                }
                catch (Exception ex)
                {
                    if (unparsed == null)
                    {
                        throw;
                    }
                    GTFSUnparsedEntity ent = new GTFSUnparsedEntity(new GTFSPropertyCollection(props), ex);
                    unparsed.Add(ent);
                    continue;
                }

                yield return(obj);
            }
        }
        public GTFSOrderedEntityCollection(IGTFSDataSource source, string tableName, GTFSEntityFactory <T> factory)
        {
            Backing = new Dictionary <string, AVLTreeDictionary <int, T> >();
            var backingGen = new DictionaryGenerator <string, AVLTreeDictionary <int, T> >(Backing,
                                                                                           new FuncGenerator <string, AVLTreeDictionary <int, T> >(x => new AVLTreeDictionary <int, T>()));

            Unparsed = new List <GTFSUnparsedEntity>();

            foreach (T item in source.GetObjects(tableName, factory, Unparsed))
            {
                backingGen[item.ID].Add(item.Index, item);
            }
        }