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


C# Document.DocumentStore类代码示例

本文整理汇总了C#中Raven.Client.Document.DocumentStore的典型用法代码示例。如果您正苦于以下问题:C# DocumentStore类的具体用法?C# DocumentStore怎么用?C# DocumentStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DocumentStore类属于Raven.Client.Document命名空间,在下文中一共展示了DocumentStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Can_load_entity

		public void Can_load_entity()
		{
			var specialId = "SHA1-UdVhzPmv0o+wUez+Jirt0OFBcUY=";

			using (base.GetNewServer())
			{
				IDocumentStore documentStore = new DocumentStore
				{
					Url = "http://localhost:8080"
				}.Initialize();

				using(var store = documentStore)
				{
					store.Initialize();

					using (var session = store.OpenSession())
					{
						var entity = new Entity() { Id = specialId };
						session.Store(entity);
						session.SaveChanges();
					}

					using (var session = store.OpenSession())
					{
						var entity1 = session.Load<object>(specialId);
						Assert.NotNull(entity1);
					}
				}
			}
		}
开发者ID:nhsevidence,项目名称:ravendb,代码行数:30,代码来源:WithBase64Characters.cs

示例2: ProperlyHandleDataDirectoryWhichEndsWithSlash

        public void ProperlyHandleDataDirectoryWhichEndsWithSlash()
        {
            server1 = CreateServer(8079, "D1");

            store1 = new DocumentStore
            {
                DefaultDatabase = "Northwind",
                Url = "http://localhost:8079"
            };

            store1.Initialize(ensureDatabaseExists: false);

            store1.DatabaseCommands.GlobalAdmin.CreateDatabase(
                new DatabaseDocument
                {
                    Id = "Northwind",
                    Settings = { { "Raven/DataDir", @"~\D1\N" } }
                });

            store1.DatabaseCommands.ForDatabase("Northwind").Get("force/load/of/db");

            Assert.True(
                Directory.Exists(Path.Combine(server1.SystemDatabase.Configuration.DataDirectory,
                                              "N")));


        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:27,代码来源:RavenDB_1595.cs

示例3: Sample

        public void Sample()
        {
            using (var store = NewDocumentStore())
            {
                #region authentication_3

                store.DatabaseCommands.Put("Raven/ApiKeys/sample",
                                           null,
                                           RavenJObject.FromObject(new ApiKeyDefinition
                                               {
                                                   Name = "sample",
                                                   Secret = "ThisIsMySecret",
                                                   Enabled = true,
                                                   Databases = new List<DatabaseAccess>
                                                       {
                                                           new DatabaseAccess {TenantId = "*"},
                                                           new DatabaseAccess {TenantId = Constants.SystemDatabase},
                                                       }
                                               }), new RavenJObject());

                #endregion
            }

            #region authentication_4
            var documentStore = new DocumentStore
                {
                    ApiKey = "sample/ThisIsMySecret",
                    Url = "http://localhost:8080/"
                };

            #endregion
        }
开发者ID:sainiuc,项目名称:docs,代码行数:32,代码来源:Index.cs

示例4: CanUseStats

		public void CanUseStats()
		{
			using (GetNewServer())
			using (var docStore = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
			{
				using (var session = docStore.OpenSession())
				{
					session.Store(new User { Name = "Ayende" });
					session.Store(new User { Name = "Oren" });
					session.SaveChanges();
				}


				using (var session = docStore.OpenSession())
				{
					RavenQueryStatistics stats;
					session.Query<User>()
						.Customize(x=>x.WaitForNonStaleResults())
						.Statistics(out stats)
						.Lazily();

					session.Advanced.Eagerly.ExecuteAllPendingLazyOperations();

					Assert.Equal(2, stats.TotalResults);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:27,代码来源:Bugs.cs

示例5: InitializeDocumentStore

        void InitializeDocumentStore()
        {
            _documentStore = _configuration.CreateDocumentStore();

            var keyGenerator = new SequentialKeyGenerator(_documentStore);
            _documentStore.Conventions.DocumentKeyGenerator = (a,b,c) => string.Format("{0}/{1}", CollectionName, keyGenerator.NextFor<IEvent>());
            //_documentStore.Conventions.IdentityTypeConvertors.Add(new ConceptTypeConverter<long>());
            //_documentStore.Conventions.IdentityTypeConvertors.Add(new ConceptTypeConverter<int>());
            //_documentStore.Conventions.IdentityTypeConvertors.Add(new ConceptTypeConverter<string>());
            //_documentStore.Conventions.IdentityTypeConvertors.Add(new ConceptTypeConverter<Guid>());
            //_documentStore.Conventions.IdentityTypeConvertors.Add(new ConceptTypeConverter<short>());

            _documentStore.Conventions.CustomizeJsonSerializer = s =>
            {
                s.Converters.Add(new MethodInfoConverter());
                s.Converters.Add(new EventSourceVersionConverter());
                s.Converters.Add(new ConceptConverter());
            };
            
           var originalFindTypeTagNam =  _documentStore.Conventions.FindTypeTagName;
           _documentStore.Conventions.FindTypeTagName = t =>
           {
               if (t.HasInterface<IEvent>() || t == typeof(IEvent)) return CollectionName;
               return originalFindTypeTagNam(t);
           };

            _documentStore.RegisterListener(new EventMetaDataListener(_eventMigrationHierarchyManager));
        }
开发者ID:JoB70,项目名称:Bifrost,代码行数:28,代码来源:EventStore.cs

示例6: Application_Start

        protected void Application_Start() {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);


            Store = new DocumentStore() { ConnectionStringName = "Onboarding" };
            Store.Initialize();
            var builder = new ContainerBuilder();

            Store.Conventions.RegisterIdConvention<User>((dbname, commands, user) => "users/" + user.UserName);

            builder.Register(c => {
                var store = new DocumentStore {
                    ConnectionStringName = "Onboarding",
                    DefaultDatabase = "Onboarding"
                }.Initialize();

                return store;

            }).As<IDocumentStore>().SingleInstance();

            builder.Register(c => c.Resolve<IDocumentStore>().OpenAsyncSession()).As<IAsyncDocumentSession>().InstancePerLifetimeScope();

        }
开发者ID:meridiumlabs,项目名称:Meridium.Onboarding,代码行数:27,代码来源:Global.asax.cs

示例7: CanSaveAndLoadSameTimeLocal

		public void CanSaveAndLoadSameTimeLocal()
		{
			using(GetNewServer())
			using (var store = new DocumentStore{Url = "http://localhost:8079"}.Initialize())
			{
				using (var session = store.OpenSession())
				{
					var serviceExecutionLog = new ServiceExecutionLog
					{
						LastDateChecked = new DateTime(2010, 2, 17, 19, 06, 06, DateTimeKind.Local)
					};

					session.Store(serviceExecutionLog);

					session.SaveChanges();

				}

				using (var session = store.OpenSession())
				{
					var log = session.Load<ServiceExecutionLog>("ServiceExecutionLogs/1");
					Assert.Equal(new DateTime(2010, 2, 17, 19, 06, 06), log.LastDateChecked);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:25,代码来源:DateTimeInLocalTimeRemote.cs

示例8: AddEntity

		public void AddEntity()
		{
            //Please use a normal running database and not the ones contained in the Base Class
			using (var store = new DocumentStore())
			{
				store.Conventions.FindIdentityPropertyNameFromEntityName = typeName => "ID";
				store.Conventions.FindIdentityProperty = prop => prop.Name == "ID";

				IDocumentSession session = store.OpenSession();

				var article = new Article
				{
					Title = "Article 1",
					SubTitle = "Article 1 subtitle",
					PublishDate = DateTime.UtcNow.Add(TimeSpan.FromDays(1))
				};
				session.Store(article);
				session.SaveChanges();

				Assert.True(article.ID > 0);

				var insertedArticle = session.Query<Article>().Where(
					a => a.ID.In(new int[] {article.ID}) && a.PublishDate > DateTime.UtcNow).FirstOrDefault();

				Assert.NotNull(insertedArticle);
			}
		}
开发者ID:kpantos,项目名称:ravendb,代码行数:27,代码来源:DynamicId.cs

示例9: CanQueryDefaultDatabaseQuickly

        public void CanQueryDefaultDatabaseQuickly()
        {
            using (GetNewServer(8080))
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8080"
            }.Initialize())
            {
                store.DatabaseCommands.EnsureDatabaseExists("Northwind");

                using (var s = store.OpenSession("Northwind"))
                {
                    var entity = new User
                    {
                        Name = "Hello",
                    };
                    s.Store(entity);
                    s.SaveChanges();
                }

                var sp = Stopwatch.StartNew();
                using (var s = store.OpenSession())
                {
                    Assert.Empty(s.Query<User>().Where(x => x.Name == "Hello"));
                }
                Assert.True(TimeSpan.FromSeconds(5) > sp.Elapsed);
            }
        }
开发者ID:vinone,项目名称:ravendb,代码行数:28,代码来源:MultiTenancy.cs

示例10: CanCreateDatabaseUsingExtensionMethod

        public void CanCreateDatabaseUsingExtensionMethod()
        {
            using (GetNewServer(8080))
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8080"
            }.Initialize())
            {
                store.DatabaseCommands.EnsureDatabaseExists("Northwind");

                string userId;

                using (var s = store.OpenSession("Northwind"))
                {
                    var entity = new User
                    {
                        Name = "First Mutlti Tenant Bank",
                    };
                    s.Store(entity);
                    userId = entity.Id;
                    s.SaveChanges();
                }

                using (var s = store.OpenSession())
                {
                    Assert.Null(s.Load<User>(userId));
                }

                using (var s = store.OpenSession("Northwind"))
                {
                    Assert.NotNull(s.Load<User>(userId));
                }
            }
        }
开发者ID:vinone,项目名称:ravendb,代码行数:34,代码来源:MultiTenancy.cs

示例11: InitialiseRaven

        private static void InitialiseRaven()
        {
            Store = new DocumentStore {ConnectionStringName = "RavenDB"};
            Store.Initialize();

            IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), Store);
        }
开发者ID:ascjones,项目名称:speedyturtle,代码行数:7,代码来源:Global.asax.cs

示例12: RavenDbRegistry

        public RavenDbRegistry(string connectionStringName)
        {
            For<IDocumentStore>()
                .Singleton()
                .Use(x =>
                         {
                             var store = new DocumentStore
                                             {
                                                 ConnectionStringName = connectionStringName,
                                             };
                             store.Initialize();

                             // Index initialisation.
                             IndexCreation.CreateIndexes(typeof(RecentTags).Assembly, store);

                             return store;
                         }
                )
                .Named("RavenDB Document Store.");

            For<IDocumentSession>()
                .AlwaysUnique()
                .Use(x =>
                         {
                             var store = x.GetInstance<IDocumentStore>();
                             return store.OpenSession();
                         })
                .Named("RavenDB Session (aka. Unit of Work).");
        }
开发者ID:alexeylih,项目名称:RavenOverflow,代码行数:29,代码来源:RavenDbRegistry.cs

示例13: Main

		static void Main()
		{
			using (var store = new DocumentStore { ConnectionStringName = "RavenDB" }.Initialize())
			{
				int start = 0;
				while (true)
				{
					using (var session = store.OpenSession())
					{
						var posts = session.Query<Post>()
							.OrderBy(x => x.CreatedAt)
							.Include(x => x.CommentsId)
							.Skip(start)
							.Take(128)
							.ToList();

						if (posts.Count == 0)
							break;

						foreach (var post in posts)
						{
							session.Load<PostComments>(post.CommentsId).Post = new PostComments.PostReference
							{
								Id = post.Id,
								PublishAt = post.PublishAt
							};
						}

						session.SaveChanges();
						start += posts.Count;
						Console.WriteLine("Migrated {0}", start);
					}
				}
			}
		}
开发者ID:wheeliemow,项目名称:RaccoonBlog,代码行数:35,代码来源:Program.cs

示例14: using

        public void Should_save_put_to_tenant_database_if_tenant_database_is_reloaded_in_the_middle_of_the_put_transaction()
        {
			using (var server = GetNewServer(runInMemory: false))
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8079"
            }.Initialize())
            {
                store.DatabaseCommands.CreateDatabase(new DatabaseDocument { Id = TenantName, Settings = { { "Raven/DataDir", @"~\Databases\Mine" } }, });

                var tx1 = new TransactionInformation { Id = Guid.NewGuid().ToString() };
                var tx2 = new TransactionInformation { Id = Guid.NewGuid().ToString() };

                var tenantDatabaseDocument = store.DatabaseCommands.Get("Raven/Databases/" + TenantName);
                server.Database.Put("Raven/Databases/mydb", null, tenantDatabaseDocument.DataAsJson, tenantDatabaseDocument.Metadata, tx1);

                var tenantDb = GetDocumentDatabaseForTenant(server, TenantName);
                tenantDb.Put("Foo/1", null, new RavenJObject { { "Test", "123" } }, new RavenJObject(), tx2);

				server.Database.PrepareTransaction(tx1.Id);
                server.Database.Commit(tx1.Id);

                tenantDb = GetDocumentDatabaseForTenant(server, TenantName);
				tenantDb.PrepareTransaction(tx2.Id);
                tenantDb.Commit(tx2.Id);

                var fooDoc = tenantDb.Get("Foo/1", new TransactionInformation { Id = Guid.NewGuid().ToString() });
                Assert.NotNull(fooDoc);
            }
        }
开发者ID:925coder,项目名称:ravendb,代码行数:30,代码来源:DatabaseReloadingTests.cs

示例15: CanGetNotificationAboutDocumentDelete

        public void CanGetNotificationAboutDocumentDelete()
        {
            using (GetNewServer())
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8079"
            }.Initialize())
            {
                var list = new BlockingCollection<DocumentChangeNotification>();
                var taskObservable = store.Changes();
                taskObservable.Task.Wait();
                var observableWithTask = taskObservable.ForDocument("items/1");
                observableWithTask.Task.Wait();
                observableWithTask
                    .Where(x => x.Type == DocumentChangeTypes.Delete)
                    .Subscribe(list.Add);

                using (var session = store.OpenSession())
                {
                    session.Store(new Item(), "items/1");
                    session.SaveChanges();
                }

                store.DatabaseCommands.Delete("items/1", null);

                DocumentChangeNotification DocumentChangeNotification;
                Assert.True(list.TryTake(out DocumentChangeNotification, TimeSpan.FromSeconds(2)));

                Assert.Equal("items/1", DocumentChangeNotification.Id);
                Assert.Equal(DocumentChangeNotification.Type, DocumentChangeTypes.Delete);

                ((RemoteDatabaseChanges) taskObservable).DisposeAsync().Wait();
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:34,代码来源:ClientServer.cs


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