public bool IsNoSqlServiceRunning(string url, string username, string password, ILogger logger = null)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(false);
            }

            try
            {
                var store = new Raven.Client.Documents.DocumentStore {
                    Urls = new[] { url }
                };
                store.Initialize();
                store.Maintenance.Server.Send(new GetBuildNumberOperation());
                logger?.Information("NO-SQL STORE WORKING.");
            }
            catch (Exception e)
            {
                logger?.Error("DOCUMENT STORE DOWN. SERVICE DISABLED AUTOMATICALLY.");
                logger?.Error(e, $"ERROR: {1}", e);
                return(false);
            }

            return(true);
        }
        public void CleanUp()
        {
            var ravenDocumentStore = new Raven.Client.Documents.DocumentStore {
                Urls = new [] { "http://localhost:8080" }
            };

            ravenDocumentStore.Initialize();
            ravenDocumentStore.Maintenance.Server.Send(new DeleteDatabasesOperation("Tests", true));
        }
        private static IDocumentSession GetRavenDocumentSession()
        {
            var ravenDocumentStore = new Raven.Client.Documents.DocumentStore {
                Urls = new [] { "http://localhost:8080" }
            };

            ravenDocumentStore.Initialize();
            ravenDocumentStore.Maintenance.Server.Send(new CreateDatabaseOperation(new DatabaseRecord("Tests")));
            var session = ravenDocumentStore.OpenSession("Tests");

            return(session);
        }
Пример #4
0
        public void TestGenerateKey()
        {
            var configuration = MockBuilder.BuildConfiguration();
            var store         = new Raven.Client.Documents.DocumentStore {
                Urls = new[] { configuration.DocumentStore.Url }
            };

            store.Initialize();
            var documentStore = new DocumentStore(new DocumentSessionFactory(store, new NullLogger(), false), store);
            var generateKey   = new GenerateKey(documentStore);

            Assert.IsTrue(generateKey.GetNextNumericalKey("Tests") != 0);
        }
        private void RegisterDocumentStore(ILogger logger)
        {
            var verifier = new ProviderVerifier();

            if (_configuration.DocumentStore == null || string.IsNullOrEmpty(_configuration.DocumentStore?.Url) || !verifier.IsNoSqlServiceRunning(_configuration.DocumentStore?.Url,
                                                                                                                                                   _configuration.DocumentStore?.Username,
                                                                                                                                                   _configuration.DocumentStore?.Password,
                                                                                                                                                   logger))
            {
                _autofacContainerBuilder.RegisterType <NullDocumentStore>()
                .As <IDocumentStore>()
                .SingleInstance();
                return;
            }

            var store = new Raven.Client.Documents.DocumentStore {
                Urls = new[] { _configuration.DocumentStore?.Url }
            };

            store.Initialize();

            _autofacContainerBuilder.RegisterInstance <Raven.Client.Documents.DocumentStore>(store)
            .As <Raven.Client.Documents.IDocumentStore>()
            .SingleInstance();

            _autofacContainerBuilder.Register(ctx =>
            {
                var transactionContext = AmbientTransactionContext.Current;
                var unitOfWork         = (UnitOfWork)transactionContext?.Items["UnitOfWork"];

                if (unitOfWork != null)
                {
                    return(unitOfWork.DocumentSessionFactory);
                }

                return(new DocumentSessionFactory(ctx.Resolve <Raven.Client.Documents.IDocumentStore>(), ctx.Resolve <ILogger>(), false));
            })
            .AsSelf()
            .InstancePerLifetimeScope();

            _autofacContainerBuilder.RegisterType <DocumentStore>()
            .As <IDocumentStore>()
            .InstancePerDependency();
        }