public void TestMethod1()
 {
     Batteries_V2.Init();
 }
Beispiel #2
0
        static async Task Main(string csvName = "tnt/dump_release_tntvillage_2019-08-30.csv", string tntReadme = "tnt/README.txt", string dbName = "tnt.sqlite")
        {
            Batteries_V2.Init();

            if (!File.Exists(csvName))
            {
                Console.WriteLine("Invalid path for CSV file");
                return;
            }

            if (!File.Exists(tntReadme))
            {
                Console.WriteLine("Invalid path for TNT README");
                return;
            }

            var res = sqlite3_open_v2(dbName, out var db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, null);

            if (res != SQLITE_OK)
            {
                var err = db.errmsg();
                Console.WriteLine($"Error opening DB: ({res}) {err}");
                return;
            }

            CreateTables(db);

            var readme = await File.ReadAllTextAsync(tntReadme);

            var categoryMatches = CategoryRegex.Matches(readme);
            var categories      = categoryMatches
                                  .Select(m => (id: int.Parse(m.Groups[1].ToString()), name: m.Groups[2].ToString()));

            var csvItems = ParseCsv(csvName).ToList();

            using (var stmt = db.prepare("INSERT INTO categories (id, name) VALUES (?, ?)"))
            {
                foreach (var(id, name) in categories)
                {
                    stmt.reset();

                    stmt.bind_int(1, id);
                    stmt.bind_text(2, name);

                    stmt.step_done();
                }
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var dbItemCount = db.query_scalar <long>("SELECT count(*) FROM items");

            if (dbItemCount != csvItems.Count)
            {
                Console.WriteLine("Seeding DB");
                SeedDb(db, csvItems);
                Console.WriteLine("Seeding completed");
            }
            else
            {
                Console.WriteLine("Seeding not needed");
            }

            stopWatch.Stop();
            Console.WriteLine($"Stopwatch: {stopWatch.ElapsedMilliseconds} ms");
            db.exec("INSERT OR REPLACE INTO metadata (key, value) VALUES ('db_build_time_ms', ?)", stopWatch.ElapsedMilliseconds);
            db.exec("INSERT OR REPLACE INTO metadata (key, value) VALUES ('clean', 1)");
            db.close_v2();
        }
Beispiel #3
0
        private static async Task StartApp(StartupOptions options)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            ServerApplicationPaths appPaths = CreateApplicationPaths(options);

            // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager
            Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath);

            IConfiguration appConfig = await CreateConfiguration(appPaths).ConfigureAwait(false);

            CreateLogger(appConfig, appPaths);

            _logger = _loggerFactory.CreateLogger("Main");

            AppDomain.CurrentDomain.UnhandledException += (sender, e)
                                                          => _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");

            // Intercept Ctrl+C and Ctrl+Break
            Console.CancelKeyPress += (sender, e) =>
            {
                if (_tokenSource.IsCancellationRequested)
                {
                    return; // Already shutting down
                }

                e.Cancel = true;
                _logger.LogInformation("Ctrl+C, shutting down");
                Environment.ExitCode = 128 + 2;
                Shutdown();
            };

            // Register a SIGTERM handler
            AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
            {
                if (_tokenSource.IsCancellationRequested)
                {
                    return; // Already shutting down
                }

                _logger.LogInformation("Received a SIGTERM signal, shutting down");
                Environment.ExitCode = 128 + 15;
                Shutdown();
            };

            _logger.LogInformation(
                "Jellyfin version: {Version}",
                Assembly.GetEntryAssembly().GetName().Version.ToString(3));

            ApplicationHost.LogEnvironmentInfo(_logger, appPaths);

            // Increase the max http request limit
            // The default connection limit is 10 for ASP.NET hosted applications and 2 for all others.
            ServicePointManager.DefaultConnectionLimit = Math.Max(96, ServicePointManager.DefaultConnectionLimit);

            // Disable the "Expect: 100-Continue" header by default
            // http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
            ServicePointManager.Expect100Continue = false;

// CA5359: Do Not Disable Certificate Validation
#pragma warning disable CA5359

            // Allow all https requests
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); });
#pragma warning restore CA5359

            Batteries_V2.Init();
            if (raw.sqlite3_enable_shared_cache(1) != raw.SQLITE_OK)
            {
                _logger.LogWarning("Failed to enable shared cache for SQLite");
            }

            var appHost = new CoreAppHost(
                appPaths,
                _loggerFactory,
                options,
                new ManagedFileSystem(_loggerFactory.CreateLogger <ManagedFileSystem>(), appPaths),
                new NullImageEncoder(),
                new NetworkManager(_loggerFactory.CreateLogger <NetworkManager>()),
                appConfig);
            try
            {
                await appHost.InitAsync(new ServiceCollection()).ConfigureAwait(false);

                appHost.ImageProcessor.ImageEncoder = GetImageEncoder(appPaths, appHost.LocalizationManager);

                await appHost.RunStartupTasksAsync().ConfigureAwait(false);

                stopWatch.Stop();

                _logger.LogInformation("Startup complete {Time:g}", stopWatch.Elapsed);

                // Block main thread until shutdown
                await Task.Delay(-1, _tokenSource.Token).ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                // Don't throw on cancellation
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, "Error while starting server.");
            }
            finally
            {
                appHost?.Dispose();
            }

            if (_restartOnShutdown)
            {
                StartNewInstance(options);
            }
        }
Beispiel #4
0
 static Example()
 {
     Batteries_V2.Init();
 }
Beispiel #5
0
 static StatementTests()
 {
     Batteries_V2.Init();
 }
 static SQLiteDatabaseConnectionTests()
 {
     Batteries_V2.Init();
 }
 static SQLiteValueTests()
 {
     Batteries_V2.Init();
 }
Beispiel #8
0
 static DatabaseBackupTests()
 {
     Batteries_V2.Init();
 }
Beispiel #9
0
 static PrettyTests()
 {
     Batteries_V2.Init();
 }
Beispiel #10
0
 static WordManagerContext()
 {
     Batteries_V2.Init();
 }
Beispiel #11
0
 static BindParametersTests()
 {
     Batteries_V2.Init();
 }
 static SQLiteDatabase()
 {
     Batteries_V2.Init();
 }
Beispiel #13
0
 static BlobStreamTests()
 {
     Batteries_V2.Init();
 }
Beispiel #14
0
 static AkaCacheServiceCollectionExtensions()
 {
     Batteries_V2.Init();
 }