コード例 #1
0
        public void Can_query_by_id_prefix()
        {
            db.Put("abc", null, new RavenJObject {
                { "a", "b" }
            }, new RavenJObject(), null);
            db.Put("Raven/Databases/Hello", null, new RavenJObject {
                { "a", "b" }
            }, new RavenJObject(), null);
            db.Put("Raven/Databases/Northwind", null, new RavenJObject {
                { "a", "b" }
            }, new RavenJObject(), null);
            db.Put("Raven/Databases/Sys", null, new RavenJObject {
                { "a", "b" }
            }, new RavenJObject(), null);
            db.Put("Raven/Databases/Db", null, new RavenJObject {
                { "a", "b" }
            }, new RavenJObject(), null);
            db.Put("Raven/Database", null, new RavenJObject {
                { "a", "b" }
            }, new RavenJObject(), null);

            var dbs = db.GetDocumentsWithIdStartingWith("Raven/Databases/", 0, 10);

            Assert.Equal(4, dbs.Length);
        }
コード例 #2
0
        public void Execute(DocumentDatabase database)
        {
            if (string.IsNullOrEmpty(database.Name) == false)
            {
                return;                // we don't care about tenant databases
            }
            if (string.Equals(database.Configuration.AuthenticationMode, "OAuth", StringComparison.InvariantCultureIgnoreCase) == false)
            {
                return;                 // we don't care if we aren't using oauth
            }
            var array = database.GetDocumentsWithIdStartingWith("Raven/Users/", 0, 1);

            if (array.Length > 0)
            {
                return;                 // there is already at least one user in there
            }
            var pwd = Guid.NewGuid().ToString();

            if (database.Configuration.RunInMemory == false)
            {
                var authConfigPath = Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), "authentication.config");

                File.WriteAllText(authConfigPath,
                                  @"Since no users were found in the database, and the database authentication mode was set to OAuth, the following user was automatically created.

Username: Admin
Password: "******"

You can use those credentials to login to RavenDB.");

                logger.Info(@"Since no users were found, and the database authentication mode was set to OAuth, a default user was generated name 'Admin'.
Credentials for this user can be found in the following file: {0}", authConfigPath);
            }


            var ravenJTokenWriter = new RavenJTokenWriter();

            JsonExtensions.CreateDefaultJsonSerializer().Serialize(ravenJTokenWriter, new AuthenticationUser
            {
                AllowedDatabases = new[] { "*" },
                Name             = "Admin",
                Admin            = true
            }.SetPassword(pwd));


            var userDoc = (RavenJObject)ravenJTokenWriter.Token;

            userDoc.Remove("Id");
            database.Put("Raven/Users/Admin", null,
                         userDoc,
                         new RavenJObject
            {
                { Constants.RavenEntityName, "AuthenticationUsers" },
                {
                    Constants.RavenClrType,
                    typeof(AuthenticationUser).FullName + ", " + typeof(AuthenticationUser).Assembly.GetName().Name
                }
            }, null);
        }
コード例 #3
0
        /// <summary>
        /// Gets documents for the specified key prefix
        /// </summary>
        public JsonDocument[] StartsWith(string keyPrefix, string matches, int start, int pageSize, bool metadataOnly = false)
        {
            pageSize = Math.Min(pageSize, database.Configuration.MaxPageSize);

            // metadata only is NOT supported for embedded, nothing to save on the data transfers, so not supporting
            // this

            var documentsWithIdStartingWith = database.GetDocumentsWithIdStartingWith(keyPrefix, matches, start, pageSize);

            return(SerializationHelper.RavenJObjectsToJsonDocuments(documentsWithIdStartingWith.OfType <RavenJObject>()).ToArray());
        }
コード例 #4
0
        private void NotifySiblings()
        {
            var notifications = new BlockingCollection <RavenConnectionStringOptions>();

            Task.Factory.StartNew(() => NotifySibling(notifications));

            int skip = 0;
            var replicationDestinations = GetReplicationDestinations();

            foreach (var replicationDestination in replicationDestinations)
            {
                notifications.TryAdd(replicationDestination.ConnectionStringOptions, 15 * 1000);
            }

            while (true)
            {
                var docs = docDb.GetDocumentsWithIdStartingWith(Constants.RavenReplicationSourcesBasePath, null, skip, 128);
                if (docs.Length == 0)
                {
                    notifications.TryAdd(null, 15 * 1000);                     // marker to stop notify this
                    return;
                }

                skip += docs.Length;

                foreach (RavenJObject doc in docs)
                {
                    var sourceReplicationInformation = doc.JsonDeserialization <SourceReplicationInformation>();
                    if (string.IsNullOrEmpty(sourceReplicationInformation.Source))
                    {
                        continue;
                    }

                    var match = replicationDestinations.FirstOrDefault(x =>
                                                                       string.Equals(x.ConnectionStringOptions.Url,
                                                                                     sourceReplicationInformation.Source,
                                                                                     StringComparison.InvariantCultureIgnoreCase));

                    if (match != null)
                    {
                        notifications.TryAdd(match.ConnectionStringOptions, 15 * 1000);
                    }
                    else
                    {
                        notifications.TryAdd(new RavenConnectionStringOptions
                        {
                            Url = sourceReplicationInformation.Source
                        }, 15 * 1000);
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets documents for the specified key prefix
        /// </summary>
        public JsonDocument[] StartsWith(string keyPrefix, int start, int pageSize)
        {
            var documentsWithIdStartingWith = database.GetDocumentsWithIdStartingWith(keyPrefix, start, pageSize);

            return(SerializationHelper.RavenJObjectsToJsonDocuments(documentsWithIdStartingWith.OfType <RavenJObject>()).ToArray());
        }