Beispiel #1
0
        /// <summary>
        /// Adds and configures a default <see cref="RavenManager" />
        /// using options
        /// </summary>
        /// <param name="services">Service collection</param>
        /// <param name="options">The options used to configure the default Raven server.</param>
        public static RavenManagerBuilder AddRavenManagerWithDefaultServer(
            this IServiceCollection services,
            Action <RavenStoreOptions> options)
        {
            var serverOptions = new RavenStoreOptions();

            options?.Invoke(serverOptions);

            return(AddRavenManager <RavenManager, RavenManagerOptions>(services, moptions =>
            {
                moptions.DefaultServer = "Default";
                moptions.AddServer("Default", serverOptions);
            }));
        }
Beispiel #2
0
        /// <summary>
        /// Add a server to the raven manager.
        /// </summary>
        /// <param name="serverName">The name of the server.</param>
        /// <param name="serverOptions">The options for the server.</param>
        /// <returns>a bool which is true if the server was successfully added.</returns>
        public bool AddServer(
            string serverName, RavenStoreOptions serverOptions)
        {
            ThrowIfDisposed();

            if (serverName == null)
            {
                throw new ArgumentNullException(nameof(serverName));
            }

            if (serverOptions == null)
            {
                throw new ArgumentNullException(nameof(serverOptions));
            }

            return(_servers.TryAdd(serverName, serverOptions));
        }
        public static WorkflowOptions UseRavenDB(this WorkflowOptions options, RavenStoreOptions configOptions)
        {
            IDocumentStore store = new DocumentStore
            {
                Urls        = new[] { configOptions.ServerUrl },
                Database    = configOptions.DatabaseName,
                Certificate = new X509Certificate2(configOptions.CertificatePath, configOptions.CertificatePassword)
            }.Initialize();

            options.UsePersistence(sp =>
            {
                return(new RavendbPersistenceProvider(store));
            });

            options.Services.AddTransient <IWorkflowPurger>(sp =>
            {
                return(new WorkflowPurger(store));
            });

            return(options);
        }
        public static DocumentStore CreateDocumentStore(
            IHostingEnvironment host,
            RavenStoreOptions options,
            DocumentConventions defaultConventions = null)
        {
            var store = new DocumentStore
            {
                Urls = new[] { options.Url },
            };

            store.Database = options.DefaultDatabase != null ? options.DefaultDatabase : "";

            if (options.Conventions == null && defaultConventions != null)
            {
                store.Conventions = defaultConventions;
            }
            else if (options.Conventions != null)
            {
                store.Conventions = options.Conventions;
            }

            var hasCert = !string.IsNullOrWhiteSpace(options.CertificateFileName);

            if (hasCert)
            {
                var certFilePath    = Path.Combine(host.ContentRootPath, options.CertificateFileName);
                var hasCertPassword = !string.IsNullOrWhiteSpace(options.CertificatePassword);
                if (hasCertPassword)
                {
                    store.Certificate = new X509Certificate2(certFilePath, options.CertificatePassword);
                }
                else
                {
                    store.Certificate = new X509Certificate2(certFilePath);
                }
            }

            return(store);
        }