Beispiel #1
0
        private IEnumerable <object> DefaultApplyReduceFunction(
            Type indexType,
            Type resultType,
            IEnumerable <object> results,
            Func <Func <IEnumerable <object>, IEnumerable> > generateTransformResults)
        {
            var copy = compiledReduceCache;
            Func <IEnumerable <object>, IEnumerable> compile;

            if (copy.TryGetValue(indexType, out compile) == false)
            {
                compile             = generateTransformResults();
                compiledReduceCache = new Dictionary <Type, Func <IEnumerable <object>, IEnumerable> >(copy)
                {
                    { indexType, compile }
                };
            }
            return(compile(results).Cast <object>()
                   .Select(result =>
            {
                // we got an anonymous object and we need to get the reduce results
                var ravenJTokenWriter = new RavenJTokenWriter();
                var jsonSerializer = CreateSerializer();
                jsonSerializer.Serialize(ravenJTokenWriter, result);
                return jsonSerializer.Deserialize(new RavenJTokenReader(ravenJTokenWriter.Token), resultType);
            }));
        }
        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);
        }
Beispiel #3
0
        private RavenJObject GetMappedData(object doc)
        {
            if (doc is IDynamicJsonObject)
            {
                return(((IDynamicJsonObject)doc).Inner);
            }

            var ravenJTokenWriter = new RavenJTokenWriter();

            jsonSerializer.Serialize(ravenJTokenWriter, doc);
            return((RavenJObject)ravenJTokenWriter.Token);
        }