public static void EnsureConfigured(Settings settings) { const int waitForStartupSeconds = 5; var waitForStartup = TimeSpan.FromSeconds(waitForStartupSeconds); var stopwatch = new Stopwatch(); stopwatch.Start(); while (!IsRunning()) { System.Threading.Thread.Sleep(1000); if (stopwatch.Elapsed >= waitForStartup) throw new ApplicationException($"Waited too long (over {waitForStartupSeconds} seconds) for ArangoDb to start up. " + "If you are on a Mac, make sure to install the ArangoDB app from the App Store and startup a local instance " + $"at port {settings.ServerUri.Port}. " + "See the readme for more information https://github.com/danludwig/eventsourced.net"); } while (true) { try { using (var systemDb = new ArangoDatabase(settings.ServerUrl, "_system")) { List<string> dbs = systemDb.ListDatabases(); if (!dbs.Contains(settings.DbName)) { systemDb.CreateDatabase(settings.DbName); } using (var appDb = new ArangoDatabase(settings.ServerUrl, settings.DbName)) { List<CreateCollectionResult> collections = appDb.ListCollections(); string[] collectionsNeeded = { typeof(ReadModel.Users.Internal.Documents.UserDocument).Name, typeof(ReadModel.Users.Internal.Documents.UserLoginIndex).Name, }; foreach (string collectionNeeded in collectionsNeeded) { if (!collections.Any(x => collectionNeeded.Equals(x.Name))) { appDb.CreateCollection(collectionNeeded); } } } break; } } catch (System.Net.Http.HttpRequestException ex) when (ex.InnerException?.GetType() == typeof(WebException) && ex.InnerException?.Message == "Unable to connect to the remote server") { if (stopwatch.Elapsed > waitForStartup) { var throwEx = new ApplicationException($"Could not connect to ArangoDB database at {settings.ServerUrl}. " + "Start ArangoDB if it is not running, otherwise check the port. " + "If you are on a Mac, the Arango app likes to create instances at port 8000 instead of 8529. " + "See the readme for more information https://github.com/danludwig/eventsourced.net", ex); throw throwEx; } //} catch (Exception ex) { // throw; } } stopwatch.Stop(); }
public Package(Settings settings = null) { Settings = settings ?? new Settings(); }