예제 #1
0
        public void AddRange(IUniqueEntityCollection <FareRule> entities)
        {
            using (var command = _connection.CreateCommand())
            {
                using (var transaction = _connection.BeginTransaction())
                {
                    foreach (var entity in entities)
                    {
                        string sql = "INSERT INTO fare_rule VALUES (:feed_id, :fare_id, :route_id, :origin_id, :destination_id, :contains_id);";
                        command.CommandText = sql;
                        command.Parameters.Add(new SQLiteParameter(@"feed_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"fare_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"route_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"origin_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"destination_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"contains_id", DbType.String));

                        command.Parameters[0].Value = _id;
                        command.Parameters[1].Value = entity.FareId;
                        command.Parameters[2].Value = entity.RouteId;
                        command.Parameters[3].Value = entity.OriginId;
                        command.Parameters[4].Value = entity.DestinationId;
                        command.Parameters[5].Value = entity.ContainsId;

                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
        }
예제 #2
0
 public void AddRange(IUniqueEntityCollection <Stop> entities)
 {
     using (var writer = _connection.BeginBinaryImport("COPY stop (feed_id, id, stop_code, stop_name, stop_desc, stop_lat, stop_lon, zone_id, stop_url, location_type, parent_station, stop_timezone, wheelchair_boarding, level_id, platform_code) FROM STDIN (FORMAT BINARY)"))
     {
         foreach (var stop in entities)
         {
             writer.StartRow();
             writer.Write(_id, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(stop.Id, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.Code, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.Name, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.Description, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.Latitude, NpgsqlTypes.NpgsqlDbType.Real);
             writer.Write(stop.Longitude, NpgsqlTypes.NpgsqlDbType.Real);
             writer.Write(stop.Zone, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.Url, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.LocationType, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(stop.ParentStation, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.Timezone, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.WheelchairBoarding, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.LevelId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(stop.PlatformCode, NpgsqlTypes.NpgsqlDbType.Text);
         }
     }
 }
예제 #3
0
        public void AddRange(IUniqueEntityCollection <Level> entities)
        {
            using (var command = _connection.CreateCommand())
            {
                using (var transaction = _connection.BeginTransaction())
                {
                    foreach (var entity in entities)
                    {
                        string sql = "INSERT INTO level VALUES (:feed_id, :level_id, :level_index, :level_name);";
                        command.CommandText = sql;
                        command.Parameters.Add(new SQLiteParameter(@"feed_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"level_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"level_index", DbType.Double));
                        command.Parameters.Add(new SQLiteParameter(@"level_name", DbType.String));

                        command.Parameters[0].Value = _id;
                        command.Parameters[1].Value = entity.Id;
                        command.Parameters[2].Value = entity.Index;
                        command.Parameters[3].Value = entity.Name;

                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
        }
예제 #4
0
파일: Extensions.cs 프로젝트: mmsatari/GTFS
        /// <summary>
        /// Adds or replaces an entity in the given collection.
        /// </summary>
        public static void AddOrReplace <T>(this IUniqueEntityCollection <T> collection, T entity, Func <T, string> getId)
            where T : Entities.GTFSEntity
        {
            var ent = collection.Get(getId(entity));

            if (ent != null)
            {
                collection.Remove(getId(entity));
            }
            collection.Add(entity);
        }
예제 #5
0
 public void AddRange(IUniqueEntityCollection <Level> entities)
 {
     using (var writer = _connection.BeginBinaryImport("COPY level (feed_id, level_id, level_index, level_name) FROM STDIN (FORMAT BINARY)"))
     {
         foreach (var level in entities)
         {
             writer.StartRow();
             writer.Write(_id, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(level.Id, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(level.Index, NpgsqlTypes.NpgsqlDbType.Real);
             writer.Write(level.Name, NpgsqlTypes.NpgsqlDbType.Text);
         }
     }
 }
예제 #6
0
        public void AddRange(IUniqueEntityCollection <Stop> entities)
        {
            using (var command = _connection.CreateCommand())
            {
                using (var transaction = _connection.BeginTransaction())
                {
                    foreach (var entity in entities)
                    {
                        string sql = "INSERT INTO stop VALUES (:feed_id, :id, :stop_code, :stop_name, :stop_desc, :stop_lat, :stop_lon, :zone_id, :stop_url, :location_type, :parent_station, :stop_timezone, :wheelchair_boarding, :level_id, :platform_code);";
                        command.CommandText = sql;
                        command.Parameters.Add(new SQLiteParameter(@"feed_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"stop_code", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"stop_name", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"stop_desc", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"stop_lat", DbType.Double));
                        command.Parameters.Add(new SQLiteParameter(@"stop_lon", DbType.Double));
                        command.Parameters.Add(new SQLiteParameter(@"zone_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"stop_url", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"location_type", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"parent_station", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"stop_timezone", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"wheelchair_boarding", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"level_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"platform_code", DbType.String));

                        command.Parameters[0].Value  = _id;
                        command.Parameters[1].Value  = entity.Id;
                        command.Parameters[2].Value  = entity.Code;
                        command.Parameters[3].Value  = entity.Name;
                        command.Parameters[4].Value  = entity.Description;
                        command.Parameters[5].Value  = entity.Latitude;
                        command.Parameters[6].Value  = entity.Longitude;
                        command.Parameters[7].Value  = entity.Zone;
                        command.Parameters[8].Value  = entity.Url;
                        command.Parameters[9].Value  = entity.LocationType.HasValue ? (int?)entity.LocationType.Value : null;
                        command.Parameters[10].Value = entity.ParentStation;
                        command.Parameters[11].Value = entity.Timezone;
                        command.Parameters[12].Value = entity.WheelchairBoarding;
                        command.Parameters[13].Value = entity.LevelId;
                        command.Parameters[14].Value = entity.PlatformCode;

                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
        }
예제 #7
0
 public void AddRange(IUniqueEntityCollection <FareRule> entities)
 {
     using (var writer = _connection.BeginBinaryImport("COPY fare_rule (feed_id, fare_id, route_id, origin_id, destination_id, contains_id) FROM STDIN (FORMAT BINARY)"))
     {
         foreach (var fareRule in entities)
         {
             writer.StartRow();
             writer.Write(_id, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(fareRule.FareId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(fareRule.RouteId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(fareRule.OriginId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(fareRule.DestinationId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(fareRule.ContainsId, NpgsqlTypes.NpgsqlDbType.Text);
         }
     }
 }
예제 #8
0
 public void AddRange(IUniqueEntityCollection <Agency> entities)
 {
     using (var writer = _connection.BeginBinaryImport("COPY agency (feed_id, id, agency_name, agency_url, agency_timezone, agency_lang, agency_phone, agency_fare_url) FROM STDIN (FORMAT BINARY)"))
     {
         foreach (var agency in entities)
         {
             writer.StartRow();
             writer.Write(_id, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(agency.Id, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(agency.Name, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(agency.URL, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(agency.Timezone, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(agency.LanguageCode, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(agency.Phone, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(agency.FareURL, NpgsqlTypes.NpgsqlDbType.Text);
         }
     }
 }
예제 #9
0
        public void AddRange(IUniqueEntityCollection <Route> entities)
        {
            using (var command = _connection.CreateCommand())
            {
                using (var transaction = _connection.BeginTransaction())
                {
                    foreach (var entity in entities)
                    {
                        string sql = "INSERT INTO route VALUES (:feed_id, :id, :agency_id, :route_short_name, :route_long_name, :route_desc, :route_type, :route_url, :route_color, :route_text_color, :vehicle_capacity, :continuous_pickup, :continuous_drop_off);";
                        command.CommandText = sql;
                        command.Parameters.Add(new SQLiteParameter(@"feed_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"route_short_name", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"route_long_name", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"route_desc", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"route_type", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"route_url", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"route_color", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"route_text_color", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"vehicle_capacity", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"continuous_pickup", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"continuous_drop_off", DbType.Int64));

                        command.Parameters[0].Value  = _id;
                        command.Parameters[1].Value  = entity.Id;
                        command.Parameters[2].Value  = entity.AgencyId;
                        command.Parameters[3].Value  = entity.ShortName;
                        command.Parameters[4].Value  = entity.LongName;
                        command.Parameters[5].Value  = entity.Description;
                        command.Parameters[6].Value  = (int)entity.Type;
                        command.Parameters[7].Value  = entity.Url;
                        command.Parameters[8].Value  = entity.Color;
                        command.Parameters[9].Value  = entity.TextColor;
                        command.Parameters[10].Value = entity.VehicleCapacity;
                        command.Parameters[11].Value = entity.ContinuousPickup.HasValue ? (int?)entity.ContinuousPickup.Value : null;
                        command.Parameters[12].Value = entity.ContinuousDropOff.HasValue ? (int?)entity.ContinuousDropOff.Value : null;

                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
        }
예제 #10
0
        public void AddRange(IUniqueEntityCollection <Pathway> entities)
        {
            using (var command = _connection.CreateCommand())
            {
                using (var transaction = _connection.BeginTransaction())
                {
                    foreach (var entity in entities)
                    {
                        string sql = "INSERT INTO pathway VALUES (:feed_id, :pathway_id, :from_stop_id, :to_stop_id, :pathway_mode, :is_bidirectional, :length, :traversal_time, :stair_count, :max_slope, :min_width, :signposted_as, :reversed_signposted_as	);";
                        command.CommandText = sql;
                        command.Parameters.Add(new SQLiteParameter(@"feed_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"pathway_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"from_stop_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"to_stop_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"pathway_mode", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"is_bidirectional", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"length", DbType.Double));
                        command.Parameters.Add(new SQLiteParameter(@"traversal_time", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"stair_count", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"max_slope", DbType.Double));
                        command.Parameters.Add(new SQLiteParameter(@"min_width", DbType.Double));
                        command.Parameters.Add(new SQLiteParameter(@"signposted_as", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"reversed_signposted_as", DbType.String));

                        command.Parameters[0].Value  = _id;
                        command.Parameters[1].Value  = entity.Id;
                        command.Parameters[2].Value  = entity.FromStopId;
                        command.Parameters[3].Value  = entity.ToStopId;
                        command.Parameters[4].Value  = entity.PathwayMode;
                        command.Parameters[5].Value  = entity.IsBidirectional;
                        command.Parameters[6].Value  = entity.Length;
                        command.Parameters[7].Value  = entity.TraversalTime;
                        command.Parameters[8].Value  = entity.StairCount;
                        command.Parameters[9].Value  = entity.MaxSlope;
                        command.Parameters[10].Value = entity.MinWidth;
                        command.Parameters[11].Value = entity.SignpostedAs;
                        command.Parameters[12].Value = entity.ReversedSignpostedAs;

                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
        }
예제 #11
0
 public void AddRange(IUniqueEntityCollection <Trip> entities)
 {
     using (var writer = _connection.BeginBinaryImport("COPY trip (feed_id, id, route_id, service_id, trip_headsign, trip_short_name, direction_id, block_id, shape_id, wheelchair_accessible) FROM STDIN (FORMAT BINARY)"))
     {
         foreach (var trip in entities)
         {
             writer.StartRow();
             writer.Write(_id, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(trip.Id, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(trip.RouteId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(trip.ServiceId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(trip.Headsign, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(trip.ShortName, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(trip.Direction, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(trip.BlockId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(trip.ShapeId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(trip.AccessibilityType, NpgsqlTypes.NpgsqlDbType.Integer);
         }
     }
 }
예제 #12
0
 public void AddRange(IUniqueEntityCollection <Route> entities)
 {
     using (var writer = _connection.BeginBinaryImport("COPY route (feed_id, id, agency_id, route_short_name, route_long_name, route_desc, route_type, route_url, route_color, route_text_color, vehicle_capacity) FROM STDIN (FORMAT BINARY)"))
     {
         foreach (var route in entities)
         {
             writer.StartRow();
             writer.Write(_id, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(route.Id, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(route.AgencyId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(route.ShortName, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(route.LongName, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(route.Description, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(route.Type, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(route.Url, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(route.Color, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(route.TextColor, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(route.VehicleCapacity, NpgsqlTypes.NpgsqlDbType.Integer);
         }
     }
 }
예제 #13
0
        public void AddRange(IUniqueEntityCollection <Trip> entities)
        {
            using (var command = _connection.CreateCommand())
            {
                using (var transaction = _connection.BeginTransaction())
                {
                    foreach (var trip in entities)
                    {
                        string sql = "INSERT INTO trip VALUES (:feed_id, :id, :route_id, :service_id, :trip_headsign, :trip_short_name, :direction_id, :block_id, :shape_id, :wheelchair_accessible);";
                        command.CommandText = sql;
                        command.Parameters.Add(new SQLiteParameter(@"feed_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"route_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"service_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"trip_headsign", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"trip_short_name", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"direction_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"block_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"shape_id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"wheelchair_accessible", DbType.Int64));

                        command.Parameters[0].Value = _id;
                        command.Parameters[1].Value = trip.Id;
                        command.Parameters[2].Value = trip.RouteId;
                        command.Parameters[3].Value = trip.ServiceId;
                        command.Parameters[4].Value = trip.Headsign;
                        command.Parameters[5].Value = trip.ShortName;
                        command.Parameters[6].Value = trip.Direction.HasValue ? (int?)trip.Direction.Value : null;
                        command.Parameters[7].Value = trip.BlockId;
                        command.Parameters[8].Value = trip.ShapeId;
                        command.Parameters[9].Value = trip.AccessibilityType.HasValue ? (int?)trip.AccessibilityType.Value : null;

                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
        }
예제 #14
0
 public void AddRange(IUniqueEntityCollection <Pathway> entities)
 {
     using (var writer = _connection.BeginBinaryImport("COPY pathway (feed_id, pathway_id, from_stop_id, to_stop_id, pathway_mode, is_bidirectional, length, traversal_time, stair_count, max_slope, min_width, signposted_as, reversed_signposted_as) FROM STDIN (FORMAT BINARY)"))
     {
         foreach (var pathway in entities)
         {
             writer.StartRow();
             writer.Write(_id, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(pathway.Id, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(pathway.FromStopId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(pathway.ToStopId, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(pathway.PathwayMode, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(pathway.IsBidirectional, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(pathway.Length, NpgsqlTypes.NpgsqlDbType.Real);
             writer.Write(pathway.TraversalTime, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(pathway.StairCount, NpgsqlTypes.NpgsqlDbType.Integer);
             writer.Write(pathway.MaxSlope, NpgsqlTypes.NpgsqlDbType.Real);
             writer.Write(pathway.MinWidth, NpgsqlTypes.NpgsqlDbType.Real);
             writer.Write(pathway.SignpostedAs, NpgsqlTypes.NpgsqlDbType.Text);
             writer.Write(pathway.ReversedSignpostedAs, NpgsqlTypes.NpgsqlDbType.Text);
         }
     }
 }
예제 #15
0
        public void AddRange(IUniqueEntityCollection <Agency> entities)
        {
            using (var command = _connection.CreateCommand())
            {
                using (var transaction = _connection.BeginTransaction())
                {
                    foreach (var entity in entities)
                    {
                        string sql = "INSERT INTO agency VALUES (:feed_id, :id, :agency_name, :agency_url, :agency_timezone, :agency_lang, :agency_phone, :agency_fare_url, :agency_email);";
                        command.CommandText = sql;
                        command.Parameters.Add(new SQLiteParameter(@"feed_id", DbType.Int64));
                        command.Parameters.Add(new SQLiteParameter(@"id", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_name", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_url", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_timezone", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_lang", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_phone", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_fare_url", DbType.String));
                        command.Parameters.Add(new SQLiteParameter(@"agency_email", DbType.String));

                        command.Parameters[0].Value = _id;
                        command.Parameters[1].Value = entity.Id;
                        command.Parameters[2].Value = entity.Name;
                        command.Parameters[3].Value = entity.URL;
                        command.Parameters[4].Value = entity.Timezone;
                        command.Parameters[5].Value = entity.LanguageCode;
                        command.Parameters[6].Value = entity.Phone;
                        command.Parameters[7].Value = entity.FareURL;
                        command.Parameters[8].Value = entity.Email;

                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
        }
예제 #16
0
 /// <summary>
 /// This is just a placeholder
 /// </summary>
 /// <returns></returns>
 public void AddRange(IUniqueEntityCollection <T> entities)
 {
     _entities.AddRange(entities);
 }