Esempio n. 1
0
        private string LoadConnectionString()
        {
            const string filename             = "db.auth";
            var          connectionStringPath = Path.Combine("content", "app", filename);

            if (!File.Exists(connectionStringPath))
            {
                throw new FileNotFoundException("Could not find the database credentials.", connectionStringPath);
            }

            if (!Passfile.TryParse(File.ReadAllText(connectionStringPath), out var result))
            {
                throw new InvalidDataException("The credential file was of an invalid format.");
            }

            return(result.ConnectionString);
        }
Esempio n. 2
0
        private static async Task <int> Main(string[] args)
        {
            var parsingResult = Parser.Default.ParseArguments <ProgramOptions>(args);

            if (parsingResult is Parsed <ProgramOptions> success)
            {
                Options = success.Value;
            }
            else
            {
                return(1);
            }

            if (!Directory.Exists(Options.InputFolder))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                await Console.Error.WriteLineAsync("Input directory not found.");

                return(1);
            }

            var repoFilePath = Path.Combine(Options.InputFolder, "plugins", "repository.xml");

            if (!File.Exists(repoFilePath))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                await Console.Error.WriteLineAsync("No repository information found in the input folder.");

                return(1);
            }

            if (!File.Exists(Options.AuthenticationFile))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                await Console.Error.WriteLineAsync("Authentication file not found.");

                return(1);
            }

            if (!Passfile.TryParse(File.ReadAllText(Options.AuthenticationFile), out var passfile))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                await Console.Error.WriteLineAsync("Could not parse authentication file.");

                return(1);
            }

            var deserializer = new XmlSerializer(typeof(IdeaPluginRepository));

            IdeaPluginRepository repository;

            await using (var repoFile = File.OpenRead(repoFilePath))
            {
                repository = (IdeaPluginRepository)deserializer.Deserialize(repoFile);
            }

            await using (var services = new ServiceCollection()
                                        .AddDbContextPool <PluginsDatabaseContext>
                                        (
                             options => PluginsDatabaseContext
                             .ConfigureDefaultOptions(options)
                             .UseNpgsql(passfile.ConnectionString)
                                        )
                                        .BuildServiceProvider())
            {
                await ImportRepositoryAsync(services, repository);
            }

            return(0);
        }