Example #1
0
        /// <summary>
        /// Parses this command into a processor given the arguments for this switch. Consumes the previous processors and returns how many it consumes.
        /// </summary>
        public override int Parse(List <Processor> previous, out Processor processor)
        {
            if (this.Arguments.Length != 1)
            {
                throw new ArgumentException("Exactly one argument is expected.");
            }
            if (previous.Count < 1)
            {
                throw new ArgumentException("Expected at least one processors before this one.");
            }

            var file = new FileInfo(this.Arguments[0]);

            if (!(previous[previous.Count - 1] is Processors.TransitDb.IProcessorTransitDbSource))
            {
                throw new Exception("Expected a transit db source.");
            }

            var source = (previous[previous.Count - 1] as Processors.TransitDb.IProcessorTransitDbSource);
            Func <Itinero.Transit.Data.TransitDb> getTransitDb = () =>
            {
                var transitDb = source.GetTransitDb();
                using (var stream = File.Open(file.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    transitDb.Serialize(stream);
                }
                return(transitDb);
            };

            processor = new Processors.TransitDb.ProcessorTransitDbSource(getTransitDb);

            return(1);
        }
Example #2
0
        /// <summary>
        /// Parses this command into a processor given the arguments for this switch. Consumes the previous processors and returns how many it consumes.
        /// </summary>
        public override int Parse(List <Processor> previous, out Processor processor)
        {
            var profileName = string.Empty; // no default profile.
            var distance    = 100;          // default distance 100m.

            for (var i = 0; i < this.Arguments.Length; i++)
            {
                string key, value;
                if (SwitchParsers.SplitKeyValue(this.Arguments[i], out key, out value))
                {
                    switch (key.ToLower())
                    {
                    case "profile":
                        profileName = value;
                        break;

                    case "distance":
                        if (!int.TryParse(value, out distance))
                        {
                            throw new SwitchParserException("--add-transfers",
                                                            "Invalid parameter value for command --add-transfers: distance not a number.");
                        }
                        break;

                    default:
                        throw new SwitchParserException("--add-transfers",
                                                        string.Format("Invalid parameter for command --add-transfers: {0} not recognized.", key));
                    }
                }
            }

            Profile profile;

            if (!Profile.TryGet(profileName, out profile))
            {
                throw new SwitchParserException("--add-transfers",
                                                string.Format("Invalid parameter value for command --add-transfers: profile {0} not found.", profileName));
            }

            if (!(previous[previous.Count - 1] is Processors.TransitDb.IProcessorTransitDbSource))
            {
                throw new Exception("Expected a transit db stream source.");
            }

            var source = (previous[previous.Count - 1] as Processors.TransitDb.IProcessorTransitDbSource).GetTransitDb;
            Func <Itinero.Transit.Data.TransitDb> getTransitDb = () =>
            {
                var db = source();

                db.AddTransfersDb(profile, distance);

                return(db);
            };

            processor = new Processors.TransitDb.ProcessorTransitDbSource(getTransitDb);

            return(1);
        }
Example #3
0
        /// <summary>
        /// Parses this command into a processor given the arguments for this switch. Consumes the previous processors and returns how many it consumes.
        /// </summary>
        public override int Parse(List <Processor> previous, out Processor processor)
        {
            if (!(previous[previous.Count - 1] is Processors.GTFS.IProcessorGTFSSource))
            {
                throw new Exception("Expected a GTFS source.");
            }

            var source = (previous[previous.Count - 1] as Processors.GTFS.IProcessorGTFSSource);
            Func <Itinero.Transit.Data.TransitDb> getTransitDb = () =>
            {
                var transitDb = new Itinero.Transit.Data.TransitDb();

                transitDb.LoadFrom(source.GetGTFS());

                transitDb.SortConnections(Itinero.Transit.Data.DefaultSorting.DepartureTime, null);

                return(transitDb);
            };

            processor = new Processors.TransitDb.ProcessorTransitDbSource(getTransitDb);

            return(1);
        }