// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAnyOrigin",
                                  builder => builder.AllowAnyOrigin().AllowAnyHeader().WithMethods("GET"));
            });

            var transitDb = BuildTransitDb.BuildOrLoad();

            RouterDb routerDb = null;

            using (var routerDbStream = File.OpenRead(
                       Configuration.GetValue <string>("routerdb")))
            {
                routerDb = RouterDb.Deserialize(routerDbStream);
            }

            Startup.Router    = new Router(routerDb);
            Startup.TransitDb = transitDb;

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
示例#2
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .CreateLogger();


#if DEBUG
            var loggingBlacklist = new HashSet <string>();
#else
            var loggingBlacklist = new HashSet <string>();
#endif
            Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                if (loggingBlacklist.Contains(o))
                {
                    return;
                }

                if (!string.IsNullOrEmpty(o))
                {
                    message = $"[{o}] {message}";
                }

                if (level == Logging.TraceEventType.Verbose.ToString().ToLower())
                {
                    Log.Debug(message);
                }
                else if (level == Logging.TraceEventType.Information.ToString().ToLower())
                {
                    Log.Information(message);
                }
                else if (level == Logging.TraceEventType.Warning.ToString().ToLower())
                {
                    Log.Warning(message);
                }
                else if (level == Logging.TraceEventType.Critical.ToString().ToLower())
                {
                    Log.Fatal(message);
                }
                else if (level == Logging.TraceEventType.Error.ToString().ToLower())
                {
                    Log.Error(message);
                }
                else
                {
                    Log.Debug(message);
                }
            };

            // load data.
            var routerDb = BuildRouterDb.BuildOrLoad();

            // load transit db.
            var transitDb = BuildTransitDb.BuildOrLoad();

            var router = new Router(routerDb)
            {
                VerifyAllStoppable = true,
                CustomRouteBuilder = new Temp.Temp()
            };

            var antwerpen1        = new Coordinate(51.21880619138497f, 4.397792816162109f);
            var antwerpen2        = new Coordinate(51.21888683113129f, 4.432253837585449f);
            var brusselHermanTeir = new Coordinate(50.865696744357294f, 4.3497008085250854f);
            var brusselCentraal   = new Coordinate(50.83144119255431f, 4.339964389801025f);
            var lille             = new Coordinate(51.25979327802935f, 4.875869750976562f);
            var turnhout          = new Coordinate(51.3202332109125f, 4.9339234828948975f);
            var tourEnTaxis       = new Coordinate(50.86439661723841f, 4.348719120025635f);
            var marcheEnFamenne   = new Coordinate(50.23142236000259f, 5.333776473999023f);
            var ieper             = new Coordinate(50.85532180383167f, 2.860565185546875f);
//
//            var route = router.Calculate(router.Db.GetSupportedProfile("pedestrian.shortcut"),
//                antwerpen1, antwerpen2);
//            File.WriteAllText("route-antwerpen.json", route.ToGeoJson());
//
//            route = router.Calculate(router.Db.GetSupportedProfile("pedestrian.shortcut"),
//                brusselHermanTeir, brusselCentraal);
//            File.WriteAllText("route-brussel.json", route.ToGeoJson());
//

            var sourceLocation = antwerpen2;
            var targetLocation = brusselHermanTeir;

            var routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                            sourceLocation, targetLocation);
            File.WriteAllText("intermodal-route1.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        antwerpen2, lille);
            File.WriteAllText("intermodal-route2.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        turnhout, lille);
            File.WriteAllText("intermodal-route3.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        turnhout, marcheEnFamenne);
            File.WriteAllText("intermodal-route4.json", routeResult.Value.ToGeoJson());

            routeResult = router.TryCalculateIntermodal(transitDb, router.Db.GetSupportedProfile("pedestrian"),
                                                        turnhout, ieper);
            File.WriteAllText("intermodal-route5.json", routeResult.Value.ToGeoJson());
        }