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


C# ShardedDocumentStore.Initialize方法代码示例

本文整理汇总了C#中Raven.Client.Shard.ShardedDocumentStore.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# ShardedDocumentStore.Initialize方法的具体用法?C# ShardedDocumentStore.Initialize怎么用?C# ShardedDocumentStore.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Client.Shard.ShardedDocumentStore的用法示例。


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

示例1: RoundRobinSharding

		public RoundRobinSharding()
		{
			servers = new Dictionary<string, RavenDbServer>
			{
				{"one",GetNewServer(8078)},
				{"two", GetNewServer(8077)},
				{"tri", GetNewServer(8076)}
			};

			var documentStores = new Dictionary<string, IDocumentStore>
			                            {
				                            {"one", new DocumentStore{Url = "http://localhost:8078"}},
				                            {"two", new DocumentStore{Url = "http://localhost:8077"}},
				                            {"tri", new DocumentStore{Url = "http://localhost:8076"}},
			                            };

			foreach (var documentStore in documentStores)
			{
				documentStore.Value.Conventions.FailoverBehavior = FailoverBehavior.FailImmediately;
			}


			var shardStrategy = new ShardStrategy(documentStores)
				.ShardingOn<Post>()
				.ShardingOn<PostComments>(x => x.PostId);

			store = new ShardedDocumentStore(shardStrategy);
			store.Initialize();
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:29,代码来源:RoundRobinSharding.cs

示例2: ShardingScenario

		protected ShardingScenario()
		{
			RavenDbServer users = null;
			RavenDbServer blogs = null;
			RavenDbServer posts1 = null;
			RavenDbServer posts2 = null;
			RavenDbServer posts3 = null;
			try
			{
				users = GetNewServer(8079, "shard1");
				blogs = GetNewServer(8078, "shard2");
				posts1 = GetNewServer(8077, "shard3");
				posts2 = GetNewServer(8076, "shard4");
				posts3 = GetNewServer(8075, "shard5");
			}
			catch (Exception)
			{
				if (users != null)
					users.Dispose();
				if (blogs != null)
					blogs.Dispose();
				if (posts1 != null)
					posts1.Dispose();
				if (posts2 != null)
					posts2.Dispose();
				if (posts3 != null)
					posts3.Dispose();
				throw;
			}

			Servers = new Dictionary<string, RavenDbServer>
			{
				{"Users", users},
				{"Blogs", blogs},
				{"Posts01", posts1},
				{"Posts02", posts2},
				{"Posts03", posts3}
			};

			var shards = new List<IDocumentStore>
			             	{
			             		new DocumentStore {Identifier = "Users", Url = "http://localhost:8079"},
			             		new DocumentStore {Identifier = "Blogs", Url = "http://localhost:8078"},
			             		new DocumentStore {Identifier = "Posts01", Url = "http://localhost:8077"},
			             		new DocumentStore {Identifier = "Posts02", Url = "http://localhost:8076"},
			             		new DocumentStore {Identifier = "Posts03", Url = "http://localhost:8075"}
			             	}.ToDictionary(x => x.Identifier, x => x);

			foreach (var shard in shards)
			{
				shard.Value.Conventions.FailoverBehavior = FailoverBehavior.FailImmediately;
			}

			ShardedDocumentStore = new ShardedDocumentStore(new ShardStrategy(shards)
															{
																ShardAccessStrategy = new SequentialShardAccessStrategy(),
																ShardResolutionStrategy = new BlogShardResolutionStrategy(3),
															});
			ShardedDocumentStore = (ShardedDocumentStore) ShardedDocumentStore.Initialize();
		}
开发者ID:DBCooper2012,项目名称:ravendb,代码行数:60,代码来源:ShardingScenario.cs

示例3: Main

        private static void Main()
        {
            //set up
            const int createUserCount = 30;
            Shards shards = ShardsConfiguration.SetupShards();
            IEnumerable<User> users = TestDataGenerator.GenerateUsers(createUserCount);
            var shardStore = new ShardedDocumentStore(new UserShardStrategy(), shards);

            //main logic
            using (IDocumentStore store = shardStore.Initialize())
            {
                //Based on user id, save users into the three shards
                var repo = new UserRepository(store);
                repo.SaveAll(users);

                //load all from database
                //this will query all three shards
                IEnumerable<User> persistedUsers = repo.FindAll();
                ConsoleOutput.PrintUsersInfo(persistedUsers);
                Console.WriteLine("===================================================");

                //pick a random user
                int id = rnd.Next(1, createUserCount);
                //query all shards for specific user
                //user location in a shard is resolved automatically
                User user = repo.FindUserById(id);
                ConsoleOutput.PrintTweetsPostedBy(user);
                Console.WriteLine("===================================================");
            }
            Console.ReadLine();
        }
开发者ID:tzarger,项目名称:RavenDbSharding,代码行数:31,代码来源:Program.cs

示例4: CanDisableQueryResultsTrackingForShardedDocumentQuery

		public void CanDisableQueryResultsTrackingForShardedDocumentQuery()
		{

			using (GetNewServer(8079))
			using (GetNewServer(8078))
			using (var store = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore>
			{
				{"1", CreateDocumentStore(8079)},
				{"2", CreateDocumentStore(8078)},
			})))
			{
				store.Initialize();

				using (var session = store.OpenSession())
				{
					session.Store(new Item());
					session.Store(new Item());

					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var items = session.Query<Item>().Customize(x => x.NoTracking().WaitForNonStaleResults()).ToList();

					Assert.Equal(2, items.Count);
					Assert.Equal(0, ((InMemoryDocumentSessionOperations) session).NumberOfEntitiesInUnitOfWork);
				}
			}
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:30,代码来源:RavenDB_790.cs

示例5: CanIgnoreMultiShard

        public void CanIgnoreMultiShard()
        {
            using (var server1 = GetNewServer(8079))
            using (var server2 = GetNewServer(8078))
            using (var server3 = GetNewServer(8077))
            using (var server4 = server3)
            {
                Dictionary<string, IDocumentStore> shards = new Dictionary<string, IDocumentStore>
                {
                    {"Eastern", server1.DocumentStore},
                    {"Western", server2.DocumentStore},
                    {"Northern", server3.DocumentStore},
                    {"Southern", server4.DocumentStore},
                };

                ShardStrategy shardStrategy = new ShardStrategy(shards)
                    .ShardingOn<Region2>(r => r.Name)//, name => (name == "Northern" || name == "Southern") ? "NorthSouth" : name)
                    .ShardingOn<TerritoryOf>(x => x.RegionId);

                IDocumentStore store = new ShardedDocumentStore(shardStrategy);
                NotSupportedException notSuppotedEx = null;
                try
                {
                    store.Initialize();
                }
                catch (Exception ex)
                {

                    notSuppotedEx = ex as NotSupportedException;
                }

                Assert.NotNull(notSuppotedEx);
                Assert.Contains("Multiple keys in shard dictionary for", notSuppotedEx.Message);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:35,代码来源:ShardingFailure.cs

示例6: bulk_insert_sharded

        public void bulk_insert_sharded(string databaseName1, string databaseName2)
        {
            var server1 = GetNewServer(8079);
            var server2 = GetNewServer(8078);
            var shards = new Dictionary<string, IDocumentStore>
			{
				{"Shard1", new DocumentStore {Url = server1.Configuration.ServerUrl, DefaultDatabase = databaseName1}},
				{"Shard2", new DocumentStore {Url = server2.Configuration.ServerUrl, DefaultDatabase = databaseName2}}
			};
            var shardStrategy = new ShardStrategy(shards);
            shardStrategy.ShardingOn<Profile>(x => x.Location);

            using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
            {
                shardedDocumentStore.Initialize();

                var entity1 = new Profile {Id = "bulk1", Name = "Hila", Location = "Shard1"};
                var entity2 = new Profile {Name = "Jay", Location = "Shard2"};
                var entity3 = new Profile {Name = "Jay", Location = "Shard1"};
                using (var bulkInsert = shardedDocumentStore.ShardedBulkInsert())
                {
                    bulkInsert.Store(entity1);
                    bulkInsert.Store(entity2);
                    bulkInsert.Store(entity3);
                }
            }

            using (var store1 = new DocumentStore { Url = server1.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = databaseName1 }.Initialize())
            {
                using (var session = store1.OpenSession())
                {
                    var docs = session.Load<Profile>("Shard1/bulk1");
                    Assert.Equal("Shard1", docs.Location);
                    var docs2 = session.Load<Profile>("Shard1/profiles/2");
                    Assert.Equal("Shard1", docs2.Location);

                    var totalDocs = session.Query<Profile>()
                        .Customize(x => x.WaitForNonStaleResults())
                        .ToList();
                    Assert.Equal(2, totalDocs.Count);
                }
            }
            using (var store2 = new DocumentStore { Url = server2.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = databaseName2 }.Initialize())
            {
                using (var session = store2.OpenSession())
                {
                    var docs = session.Load<Profile>("Shard2/profiles/1");
                    Assert.Equal("Shard2", docs.Location);

                    var totalDocs = session.Query<Profile>()
                        .Customize(x => x.WaitForNonStaleResults())
                        .ToList();
                    Assert.Equal(1, totalDocs.Count);
                }
            }
        }
开发者ID:JackWangCUMT,项目名称:ravendb,代码行数:56,代码来源:RavenDB-3420.cs

示例7: CanQueryUsingInt

		public void CanQueryUsingInt()
		{
			shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy();
			using (var documentStore = new ShardedDocumentStore(shardStrategy))
			{
				documentStore.Initialize();

				using (var session = documentStore.OpenSession())
				{
					session.Load<Company>(1);
				}
			}
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:13,代码来源:WhenUsingShardedServers.cs

示例8: Can_insert_into_two_sharded_servers

        public void Can_insert_into_two_sharded_servers()
        {
            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards))
            {
                documentStore.Initialize();

                using (var session = documentStore.OpenSession())
                {
                	session.Store(company1);
					session.Store(company2);
					session.SaveChanges();
                }
            }
        }
开发者ID:nzdunic,项目名称:ravendb,代码行数:14,代码来源:When_Using_Sharded_Servers.cs

示例9: ToFacetsDoesntWorkWithShardedDocumentSession

        public void ToFacetsDoesntWorkWithShardedDocumentSession()
        {
            var server1 = GetNewServer(8079);
            var server2 = GetNewServer(8078);
            var shards = new Dictionary<string, IDocumentStore>
            {
                {"Shard1", new DocumentStore{Url = server1.Configuration.ServerUrl}},
                {"Shard2", new DocumentStore{Url = server2.Configuration.ServerUrl}},
            };



            var shardStrategy = new ShardStrategy(shards);
            shardStrategy.ShardResolutionStrategy = new HybridShardingResolutionStrategy(shards.Keys, shardStrategy, new Type[0], "Shard1");
            shardStrategy.ShardingOn<Profile>(x => x.Location);

            using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
            {
                shardedDocumentStore.Initialize();
                new ProfileIndex().Execute(shardedDocumentStore);
                /*var facetSetup = new FacetSetup
                        {
                            Id = "facets/ProfileFacet",
                            Facets = new List<Facet>
                            {
                                new Facet {Name = "Name", Mode = FacetMode.Default}
                            }
                        };*/
                var facets = new List<Facet>
                {
                    new Facet {Name = "Name", Mode = FacetMode.Default}
                };
                var profile = new Profile {Name = "Test", Location = "Shard1"};

                using (var documentSession = shardedDocumentStore.OpenSession())
                {
                    documentSession.Store(profile, profile.Id);
                    //documentSession.Store(facetSetup);
                    documentSession.SaveChanges();
                }
                using (var documentSession = shardedDocumentStore.OpenSession())
                {
                    var query = documentSession.Query<Profile>("ProfileIndex").Where(x => x.Name == "Test");
                    var res = query.ToFacets(facets);
                    Assert.Equal(1, res.Results.Count);
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:48,代码来源:RavenDB_3096.cs

示例10: ShardedSessionInclude

        public ShardedSessionInclude()
        {
            servers = new[]
            {
                GetNewServer(8079,requestedStorage: "esent"),
                GetNewServer(8080, requestedStorage: "esent")
            };

            documentStore = CreateDocumentStore(8080);
            shardedDocumentStore = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore>
            {
                {"1", CreateDocumentStore(8079)}
            }));
            shardedDocumentStore.Initialize();
            documentStore.Initialize();
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:16,代码来源:ShardedSessionInclude.cs

示例11: RavenDB_579

		public RavenDB_579()
		{
			servers = new[]
			{
				GetNewServer(8079),
				GetNewServer(8078),
				GetNewServer(8077),
			};

			documentStore = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore>
			{
				{shardNames[0], CreateDocumentStore(8079)},
				{shardNames[1], CreateDocumentStore(8078)},
				{shardNames[2], CreateDocumentStore(8077)}
			}));
			documentStore.Initialize();
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:17,代码来源:RavenDB_579.cs

示例12: SimpleSharding

		public SimpleSharding()
		{
			servers = new[]
			{
				GetNewServer(8079),
				GetNewServer(8078),
				GetNewServer(8077),
			};

			documentStore = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore>
			{
				{"1", CreateDocumentStore(8079)},
				{"2", CreateDocumentStore(8078)},
				{"3", CreateDocumentStore(8077)}
			}));
			documentStore.Initialize();
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:17,代码来源:SimpleSharding.cs

示例13: get_metadata_for_sharded

		public void get_metadata_for_sharded()
		{
			var server1 = GetNewServer(8079);
			var server2 = GetNewServer(8078);
			var shards = new List<IDocumentStore>
			{
				new DocumentStore {Identifier = "Shard1", Url = server1.Configuration.ServerUrl},
				new DocumentStore {Identifier = "Shard2", Url = server2.Configuration.ServerUrl}
			}
				.ToDictionary(x => x.Identifier, x => x);

			var shardStrategy = new ShardStrategy(shards);
			shardStrategy.ShardingOn<Profile>(x => x.Location);

			using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
			{
				shardedDocumentStore.Initialize();

				var profile = new Profile {Name = "Test", Location = "Shard1"};
				var profile2 = new Profile {Name = "Test2", Location = "Shard2"};

				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					documentSession.Store(profile, profile.Id);
					documentSession.Store(profile2, profile2.Id);
					documentSession.SaveChanges();
				}
				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					var correctId = profile.Id;
					var correctId2 = profile2.Id;

					documentSession.Store(profile, profile.Id);
					var metaData = documentSession.Advanced.GetMetadataFor(profile);
					var metaData2 = documentSession.Advanced.GetMetadataFor(profile2);

					Assert.NotNull(metaData);
					Assert.NotNull(metaData2);
					Assert.Equal(correctId, profile.Id);
				}
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:42,代码来源:RavenDB-3465.cs

示例14: get_metadata_for_async_sharded

		public async Task get_metadata_for_async_sharded()
		{
			var server1 = GetNewServer(8079);
			var server2 = GetNewServer(8078);
			var shards = new Dictionary<string, IDocumentStore>
			{
				{"Shard1", new DocumentStore{Url = server1.Configuration.ServerUrl}},
				{"Shard2", new DocumentStore{Url = server2.Configuration.ServerUrl}},
			};

			var shardStrategy = new ShardStrategy(shards);
			shardStrategy.ShardingOn<Profile>(x => x.Location);

			using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy))
			{
				shardedDocumentStore.Initialize();

				var profile = new Profile {Name = "Test", Location = "Shard1"};
				var profile2 = new Profile {Name = "Test2", Location = "Shard2"};

				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					documentSession.Store(profile, profile.Id);
					documentSession.Store(profile2, profile2.Id);
					documentSession.SaveChanges();
				}

				using (var documentSession = shardedDocumentStore.OpenSession())
				{
					var metaData = documentSession.Advanced.GetMetadataFor(profile);
				}
				using (var documentSession = shardedDocumentStore.OpenAsyncSession())
				{
					//var data = await documentSession.LoadAsync<Profile>(profile.Id);
					var metaData = await documentSession.Advanced.GetMetadataForAsync(profile);
					var metaData2 = await documentSession.Advanced.GetMetadataForAsync(profile2);

					Assert.NotNull(metaData);
					Assert.NotNull(metaData2);
				}
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:42,代码来源:RavenDB-3465.cs

示例15: Can_insert_into_two_sharded_servers

        public void Can_insert_into_two_sharded_servers()
        {
            var serverPortsStoredUpon = new List<string>();

            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards))
            {
                documentStore.Stored += (storeServer, storeEntity) => serverPortsStoredUpon.Add(storeServer);
                documentStore.Initialize();

                using (var session = documentStore.OpenSession())
                {
                	session.Store(company1);
					session.Store(company2);
					session.SaveChanges();
                }
            }

			Assert.Contains("Shard1", serverPortsStoredUpon[0]);
			Assert.Contains("Shard2", serverPortsStoredUpon[1]);
        }
开发者ID:VirtueMe,项目名称:ravendb,代码行数:20,代码来源:When_Using_Sharded_Servers.cs


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