Exemplo n.º 1
0
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            // Disable the AutoRegister since we're not using it
            // base.ConfigureApplicationContainer(container);

            var store = new DocumentStore
            {
                ConnectionStringName = "RavenDB",
            };

            store.Initialize();

            store.Conventions.RegisterIdConvention <ServerRecord>((s, commands, serverRecord) => "serverRecords/" + ReplicationTask.EscapeDestinationName(serverRecord.Url));
            store.Conventions.RegisterIdConvention <DatabaseRecord>((s, commands, databaseRecord) => databaseRecord.ServerId + "/" + databaseRecord.Name);

            store.Conventions.RegisterAsyncIdConvention <ServerRecord>((s, commands, serverRecord) => new CompletedTask <string>("serverRecords/" + ReplicationTask.EscapeDestinationName(serverRecord.Url)));
            store.Conventions.RegisterAsyncIdConvention <DatabaseRecord>((s, commands, databaseRecord) => new CompletedTask <string>(databaseRecord.ServerId + "/" + databaseRecord.Name));

            container.Register <IDocumentStore>(store);
        }
Exemplo n.º 2
0
        private static async Task HandleDatabaseInServerAsync(ServerRecord server, string databaseName, IAsyncDatabaseCommands dbCmds, IAsyncDocumentSession session)
        {
            var databaseRecord = await session.LoadAsync <DatabaseRecord>(server.Id + "/" + databaseName);

            if (databaseRecord == null)
            {
                return;
            }

            var replicationDocument = await dbCmds.GetAsync(Constants.RavenReplicationDestinations);

            if (replicationDocument == null)
            {
                return;
            }

            databaseRecord.IsReplicationEnabled = true;
            var document = replicationDocument.DataAsJson.JsonDeserialization <ReplicationDocument>();

            databaseRecord.ReplicationDestinations = document.Destinations;

            var replicationStatistics = await dbCmds.Info.GetReplicationInfoAsync();

            if (replicationStatistics != null)
            {
                databaseRecord.ReplicationStatistics = replicationStatistics;
            }

            // Monitor the replicated destinations
            foreach (var replicationDestination in databaseRecord.ReplicationDestinations)
            {
                if (replicationDestination.Disabled)
                {
                    continue;
                }

                var url            = replicationDestination.Url;
                var databasesIndex = url.IndexOf("/databases/", StringComparison.OrdinalIgnoreCase);
                if (databasesIndex > 0)
                {
                    url = url.Substring(0, databasesIndex);
                }
                var replicationDestinationServer = await session.LoadAsync <ServerRecord>("serverRecords/" + ReplicationTask.EscapeDestinationName(url));

                if (replicationDestinationServer == null)
                {
                    replicationDestinationServer = new ServerRecord
                    {
                        Url = url,
                    };
                    await session.StoreAsync(replicationDestinationServer);
                }
                else
                {
                    if (DateTimeOffset.UtcNow - server.LastTriedToConnectAt <= TimeSpan.FromHours(1))
                    {
                        continue;
                    }
                }

                await FetchServerDatabasesAsync(replicationDestinationServer, session);
            }
        }