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); }
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(); }
static void Main(string[] args) { var logsStore = new Raven.Client.Documents.DocumentStore { Urls = Realm.GetDbServerUrls(), Database = "rpg_logs" }.Initialize(); Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .Enrich.FromLogContext() .WriteTo.Console( outputTemplate: "{Timestamp:HH:mm:ss} [{SourceContext}] [{Level:u3}] - {Message}{NewLine}{Exception}", theme: Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme.Literate) .WriteTo.RavenDB(logsStore, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning) .CreateLogger(); // Deploy/Update indexes var indexCount = Assembly.GetExecutingAssembly() .GetTypes() .Count(t => t.IsClass && t.IsNested == false && t.Namespace == "RealmRpgBot.Index"); Log.Logger.Information("Deploying {n} indexes", indexCount); Raven.Client.Documents.Indexes.IndexCreation.CreateIndexes(Assembly.GetExecutingAssembly(), Db.DocStore); // Setup scheduler JobScheduler.Scheduler.Initialize(); // Setup correct RNG implementation DiceNotation.SingletonRandom.Instance = new DiceNotation.Random.GaussianRandom(); new Bot.RpgBot() .StartBotAsync() .ConfigureAwait(false) .GetAwaiter() .GetResult(); }