当前位置: 首页>>代码示例>>C#>>正文


C# DocumentDatabase.GetDocumentsWithIdStartingWith方法代码示例

本文整理汇总了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);


		}
开发者ID:neiz,项目名称:ravendb,代码行数:55,代码来源:EnsureAtLeastOneUserExists.cs


注:本文中的Raven.Database.DocumentDatabase.GetDocumentsWithIdStartingWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。