Exemple #1
0
        /// <summary>
        /// Load the blog settings configuration from the repository.
        /// </summary>
        public override void Load()
        {
            var gitDbContext = GitDbContext.Create(_source.Options);

            IDictionary <string, byte[]> files;

            try
            {
                files = gitDbContext.GetFiles(new string[] { PathHelper.Build(_source.Options.RootPath, GitDbConstants.BlogSettingsFile) });
            }
            catch
            {
                return;
            }

            var json     = Encoding.UTF8.GetString(files.Values.Single());
            var settings = JsonSerializer.Deserialize <BlogSettings>(json, new JsonSerializerOptions {
                AllowTrailingCommas = true
            });

            if (settings == null)
            {
                return;
            }

            Data = new Dictionary <string, string>();
            Data.Add($"{nameof(PineBlogOptions)}:{nameof(PineBlogOptions.Title)}", settings.Title);
            Data.Add($"{nameof(PineBlogOptions)}:{nameof(PineBlogOptions.Description)}", settings.Description);
            Data.Add($"{nameof(PineBlogOptions)}:{nameof(PineBlogOptions.CoverCaption)}", settings.CoverCaption);
            Data.Add($"{nameof(PineBlogOptions)}:{nameof(PineBlogOptions.CoverLink)}", settings.CoverLink);
            Data.Add($"{nameof(PineBlogOptions)}:{nameof(PineBlogOptions.CoverUrl)}", settings.CoverUrl);
        }
        /// <summary>
        /// Adds PineBlog GitDb services to the specified services collection.
        /// </summary>
        /// <param name="services">The services available in the application.</param>
        /// <param name="configuration">The application configuration properties.</param>
        /// <returns>The original services object.</returns>
        public static IServiceCollection AddPineBlogGitDb(this IServiceCollection services, IConfiguration configuration)
        {
            if (((IConfigurationRoot)configuration).Providers.SingleOrDefault(p => p.GetType() == typeof(BlogSettingsConfigurationProvider)) == null)
            {
                throw new ConfigurationException("The PineBlog IConfigurationProvider(s) are not configured, please add \"AddPineBlogGitDbConfiguration\" to the \"ConfigureAppConfiguration\" on the \"IWebHostBuilder\".")
                      {
                          HelpLink = "https://github.com/ofpinewood/pineblog/blob/main/docs/getting-started.md#blog-settings-configurationprovider"
                      };
            }

            services.Configure <PineBlogGitDbOptions>(configuration.GetSection(nameof(PineBlogGitDbOptions)));

            services.AddTransient <GitDbContext>(provider =>
            {
                var options = provider.GetRequiredService <IOptions <PineBlogGitDbOptions> >();
                return(GitDbContext.Create(options.Value));
            });
            services.AddTransient <IBlogUnitOfWork, BlogUnitOfWork>();

            services.AddFeatureManagement(configuration);

            services.AddHostedService <GitDbSyncService>();

            return(services);
        }
Exemple #3
0
        public GitDbFixture()
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .Build();

            var options = configuration.GetSection(nameof(PineBlogGitDbOptions)).Get <PineBlogGitDbOptions>();

            _gitDbContext = GitDbContext.Create(options);
            _gitDbContext.CheckoutBranch(options.Branch);
        }