Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigureLogging();

            services.AddMvc(options => { options.EnableEndpointRouting = false; })
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAnyOrigin",
                                  builder => builder.AllowAnyOrigin().AllowAnyHeader().WithMethods("GET"));
            });

            services.AddSwaggerDocument();

            Task.Factory.StartNew(
                () =>
            {
                try
                {
                    StartLoadingTransitDbs();
                }
                catch (Exception e)
                {
                    Log.Error($"PANIC: could not properly boot the server!\n{e.Message}\n{e.StackTrace}");
                }
            }
                );
        }
Beispiel #2
0
        public async static Task Main(string[] args)
        {
            SerilogLog.Logger = new LoggerConfiguration()
                                .MinimumLevel.ControlledBy(LevelSwitch)
                                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                                .MinimumLevel.Override("System", LogEventLevel.Warning)
                                .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
                                .Enrich.FromLogContext()
                                .WriteTo.Console()
                                .WriteTo.File(
                "logs/log.txt",
                outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
                rollingInterval: RollingInterval.Day,
                retainedFileCountLimit: 7,
                rollOnFileSizeLimit: true,
                shared: true)
                                .CreateLogger();

            try
            {
                var host = CreateHostBuilder(args).Build();

                using (var scope = host.Services.CreateScope())
                {
                    var services = scope.ServiceProvider;

                    try
                    {
                        var context = services.GetRequiredService <ApplicationDbContext>();
                        context.Database.Migrate();

                        var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();

                        await ApplicationDbContextSeed.SeedDefaultUserAsync(userManager);

                        await ApplicationDbContextSeed.SeedSampleDataAsync(context);
                    }
                    catch (Exception exp)
                    {
                        SerilogLog.Error(exp, "An error occurred while migrating or seeding the database.");
                    }
                }

                await host.RunAsync();
            }
            catch (System.Exception exp)
            {
                SerilogLog.Fatal(exp, "Host terminated unexpectedly");
            }
            finally
            {
                SerilogLog.Information("Ending the web host!");
                SerilogLog.CloseAndFlush();
            }
        }
Beispiel #3
0
        private void StartSentry()
        {
            SelfLog.Enable(m => Log.Error(m));

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Debug()
                         .WriteTo.Sentry(o =>
            {
                o.Dsn = new Dsn("https://[email protected]/6");
                o.MinimumEventLevel      = LogEventLevel.Error;
                o.MinimumBreadcrumbLevel = LogEventLevel.Error;
                o.AttachStacktrace       = true;
                o.SendDefaultPii         = true;
                o.Environment            = "Android: " + App.DeviceToken;
            })
                         .CreateLogger();
        }
        public void Run <TMainViewModel>()
        {
            IConfiguration configuration = _configurationBuilder.Build();

            LoggerConfiguration loggerConfiguration = new LoggerConfiguration()
                                                      .ReadFrom.Configuration(configuration);

            RegisterViewAssembly <BlasticApplication>();

            Configure(x => x.RegisterInstance(configuration));
            Configure(x => x.RegisterType <TMainViewModel>());

            _containerBuilder.Populate(_serviceCollection);
            IContainer container = _containerBuilder.Build();

            LogSink logSink = container.ResolveOptional <LogSink>();

            if (logSink != null)
            {
                loggerConfiguration.WriteTo.Sink(logSink);
            }

            Log.Logger = loggerConfiguration.CreateLogger();

            Bootstrapper bootstrapper = new Bootstrapper(
                container,
                typeof(TMainViewModel),
                _viewAssemblies);

            SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());

            try
            {
                bootstrapper.Initialize();
                _application.Run();
            }
            catch (Exception exception)
            {
                Log.Error(exception, exception.Message);
                throw;
            }
        }
Beispiel #5
0
        public static void ConfigureLogging()
        {
            var date    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var logFile = Path.Combine("logs", $"log-itinero-{date}.txt");

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Verbose)
                         .Enrich.FromLogContext()
                         .WriteTo.File(new JsonFormatter(), logFile)
                         .WriteTo.Console()
                         .CreateLogger();
            Log.Information($"Logging has started. Logfile can be found at {logFile}");
            Logger.LogAction = (o, level, message, parameters) =>
            {
                if (string.Equals(level, TraceEventType.Error.ToString(), StringComparison.CurrentCultureIgnoreCase))
                {
                    Log.Error($"{message}");
                }
                else if (string.Equals(level, TraceEventType.Warning.ToString(),
                                       StringComparison.CurrentCultureIgnoreCase))
                {
                    Log.Warning($"{message}");
                }
                else if (string.Equals(level, TraceEventType.Information.ToString(),
                                       StringComparison.CurrentCultureIgnoreCase))
                {
                    Log.Information($"{message}");
                }
                else if (string.Equals(level, TraceEventType.Verbose.ToString(),
                                       StringComparison.CurrentCultureIgnoreCase))
                {
                    Log.Verbose($"{message}");
                }
                else
                {
                    Log.Information($"{level} (unknown log level): {message}");
                }
            };
        }
Beispiel #6
0
        private void StartLoadingTransitDbs()
        {
            OtherModeBuilder otherModeBuilder;

            string routableTileCache = null;

            if (Configuration["RoutableTilesCache"] != null)
            {
                routableTileCache = Configuration.GetValue <string>("RoutableTilesCache");
            }

            try
            {
                otherModeBuilder = new OtherModeBuilder(routableTileCache,
                                                        Configuration.GetSection("OsmProfiles"));
            }
            catch (Exception e)
            {
                Log.Error("Could not create all the other profiles: " + e);
                otherModeBuilder = new OtherModeBuilder();
            }


            var fileLogger = new FileLogger("logs");
            var operators  = Configuration.LoadOperators();

            var state = new State(
                operators,
                otherModeBuilder,
                otherModeBuilder.RouterDb,
                fileLogger
                )
            {
                FreeMessage = "Loading transitdbs"
            };

            Log.Information("Loaded configuration");
            State.GlobalState = state;

            Log.Information("Loaded tdbs are " +
                            string.Join(", ", state.Operators.GetFullView().Operators
                                        .Select(kvp => kvp.Name)));

            state.NameIndex = new NameIndexBuilder(new List <string> {
                "name:nl", "name", "name:fr"
            })
                              .Build(state.Operators.GetFullView().GetStopsReader());


            Log.Information("Performing initial runs");
            state.FreeMessage = "Running initial data syncs";

            var allOperators = state.Operators.GetFullView();

            foreach (var provider in allOperators.Operators)
            {
                try
                {
                    Log.Information($"Starting initial run of {provider.Name}");
                    provider.Synchronizer.InitialRun();
                }
                catch (Exception e)
                {
                    Log.Error($"Caught exception while running initial data sync: {e.Message}\n{e}");
                }
            }

            foreach (var provider in allOperators.Operators)
            {
                try
                {
                    Log.Information($"Starting synchronizer for {provider.Name}");
                    provider.Synchronizer.Start();
                }
                catch (Exception e)
                {
                    Log.Error($"Caught exception while running initial data sync: {e.Message}\n{e}");
                }
            }

            state.FreeMessage = "Fully operational";
        }
Beispiel #7
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());
        }