Example #1
0
        public static void Main(string[] args)
        {
            if (args.Contains("build-config"))
            {
                Console.WriteLine("I build the configuration.");
                BuildConfigurationFromArguments.BuildConfiguration(args);
                return;
            }

            if (args.Contains("start-server"))
            {
                Console.WriteLine("I start a server.");
                var webHostBuilder = CreateWebHostBuilder(args);
                webHostBuilder.Build().Run();
                return;
            }
        }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            var serviceProvider = services.BuildServiceProvider();
            var config          = serviceProvider.GetService <IConfiguration>();

            Composition.Component webAppConfig = null;

            {
                byte[] webAppConfigFileZipArchive = null;

                var webAppConfigurationFilePath = config.GetValue <string>(Configuration.WebAppConfigurationFilePathSettingKey);

                if (0 < webAppConfigurationFilePath?.Length)
                {
                    _logger.LogInformation(
                        "Loading configuration from single file '" + webAppConfigurationFilePath + "'.");

                    webAppConfigFileZipArchive = System.IO.File.ReadAllBytes(webAppConfigurationFilePath);
                }
                else
                {
                    _logger.LogInformation(
                        "Loading configuration from current directory.");

                    var(configZipArchive, _) = BuildConfigurationFromArguments.BuildConfigurationZipArchive(null);

                    webAppConfigFileZipArchive = configZipArchive;
                }

                webAppConfig = Composition.FromTree(Composition.TreeFromSetOfBlobsWithCommonOSPath(
                                                        ZipArchive.EntriesFromZipArchive(webAppConfigFileZipArchive), System.Text.Encoding.UTF8));
            }

            _logger.LogInformation("Loaded configuration " +
                                   CommonConversion.StringBase16FromByteArray(Composition.GetHash(webAppConfig)));

            var webAppConfigObject = WebAppConfiguration.FromFiles(
                Composition.ParseAsTree(webAppConfig).ok.EnumerateBlobsTransitive()
                .Select(blobWithPath =>
                        (path: (IImmutableList <string>)blobWithPath.path.Select(pathComponent => System.Text.Encoding.UTF8.GetString(pathComponent.ToArray())).ToImmutableList(),
                         content: blobWithPath.blobContent))
                .ToList());

            services.AddSingleton <WebAppConfiguration>(webAppConfigObject);

            var getDateTimeOffset = serviceProvider.GetService <Func <DateTimeOffset> >();

            if (getDateTimeOffset == null)
            {
                getDateTimeOffset = () => DateTimeOffset.UtcNow;
                services.AddSingleton <Func <DateTimeOffset> >(getDateTimeOffset);
            }

            var processStoreDirectory = config.GetValue <string>(Configuration.ProcessStoreDirectoryPathSettingKey);
            var processStore          = new Kalmit.ProcessStore.ProcessStoreInFileDirectory(
                processStoreDirectory,
                () =>
            {
                var time          = getDateTimeOffset();
                var directoryName = time.ToString("yyyy-MM-dd");
                return(System.IO.Path.Combine(directoryName, directoryName + "T" + time.ToString("HH") + ".composition.jsonl"));
            });

            services.AddSingleton <ProcessStore.IProcessStoreReader>(processStore);
            services.AddSingleton <ProcessStore.IProcessStoreWriter>(processStore);
            services.AddSingleton <IPersistentProcess>(BuildPersistentProcess);

            var letsEncryptOptions = webAppConfigObject?.JsonStructure?.letsEncryptOptions;

            if (letsEncryptOptions == null)
            {
                _logger.LogInformation("I did not find 'letsEncryptOptions' in the configuration. I continue without Let's Encrypt.");
            }
            else
            {
                _logger.LogInformation("I found 'letsEncryptOptions' in the configuration.");
                services.AddFluffySpoonLetsEncryptRenewalService(letsEncryptOptions);
                services.AddFluffySpoonLetsEncryptFileCertificatePersistence();
                services.AddFluffySpoonLetsEncryptMemoryChallengePersistence();
            }

            Asp.ConfigureServices(services);
        }