本文整理汇总了C#中Raven.Database.DocumentDatabase.GetDocumentsWithIdStartingWith方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentDatabase.GetDocumentsWithIdStartingWith方法的具体用法?C# DocumentDatabase.GetDocumentsWithIdStartingWith怎么用?C# DocumentDatabase.GetDocumentsWithIdStartingWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Database.DocumentDatabase
的用法示例。
在下文中一共展示了DocumentDatabase.GetDocumentsWithIdStartingWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
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: " + pwd + @"
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);
}