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


C# Shard.ShardedDocumentStore类代码示例

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


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

示例1: 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

示例2: 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

示例3: Main

		static void Main()
		{
			var shards = new Shards
			             	{
			             		new DocumentStore {Url = "http://localhost:8080", Identifier = "Posts"},
			             		new DocumentStore
			             			{
			             				Url = "http://localhost:8081",
			             				Identifier = "Users",
			             				Conventions = {DocumentKeyGenerator = user => "users/" + ((User) user).Name}
			             			}
			             	};

			var shardStrategy = new ShardStrategy
			{
				ShardAccessStrategy = new ParallelShardAccessStrategy(),
				ShardSelectionStrategy = new BlogShardSelectionStrategy(),
				ShardResolutionStrategy = new BlogShardResolutionStrategy()
			};

			using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
			{
				var posts = shards[0].DatabaseCommands.StartsWith("post", 0, 50);
				foreach (var post in posts) shards[0].DatabaseCommands.Delete(post.Key, post.Etag);

				var users = shards[1].DatabaseCommands.StartsWith("user", 0, 50);
				foreach (var user in users) shards[1].DatabaseCommands.Delete(user.Key, user.Etag);
			}
		}
开发者ID:reverentgeek,项目名称:RavenDB.Demos,代码行数:29,代码来源:Program.cs

示例4: CanIgnoreParallel

		public void CanIgnoreParallel()
		{
			using (GetNewServer())
			{
				var shardingStrategy = new ShardStrategy(new Dictionary<string, IDocumentStore>
				{
					{"one", new DocumentStore {Url = "http://localhost:8079"}},
					{"two", new DocumentStore {Url = "http://localhost:8078"}},
				})
				{
					ShardAccessStrategy = new ParallelShardAccessStrategy()
				};
				shardingStrategy.ShardAccessStrategy.OnError += (commands, request, exception) => request.Query != null;

				using (var docStore = new ShardedDocumentStore(shardingStrategy).Initialize())
				{
					using (var session = docStore.OpenSession())
					{
						session.Query<AccurateCount.User>()
							.ToList();
					}
				}

			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:25,代码来源:ShardingFailure.cs

示例5: 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

示例6: Sharding

        public Sharding()
        {
            #region intro
            var shards = new Dictionary<string, IDocumentStore>
                         	{
                         		{"Asia", new DocumentStore {Url = "http://localhost:8080"}},
                         		{"Middle East", new DocumentStore {Url = "http://localhost:8081"}},
                         		{"America", new DocumentStore {Url = "http://localhost:8082"}},
                         	};

            var shardStrategy = new ShardStrategy
                                    {
                                        ShardAccessStrategy = new ParallelShardAccessStrategy(),
                                        ShardResolutionStrategy = new ShardResolutionByRegion(),
                                    };

            using (var documentStore = new ShardedDocumentStore(shardStrategy, shards).Initialize())
            using (var session = documentStore.OpenSession())
            {
                //store 3 items in the 3 shards
                session.Store(new Company {Name = "Company 1", Region = "Asia"});
                session.Store(new Company {Name = "Company 2", Region = "Middle East"});
                session.Store(new Company {Name = "Company 3", Region = "America"});
                session.SaveChanges();

                //get all, should automagically retrieve from each shard
                var allCompanies = session.Query<Company>()
                    .Customize(x => x.WaitForNonStaleResultsAsOfNow()).ToArray();

                foreach (var company in allCompanies)
                    Console.WriteLine(company.Name);
            }
            #endregion
        }
开发者ID:kprog,项目名称:docs,代码行数:34,代码来源:Sharding.cs

示例7: Main

        static void Main(string[] args)
        {
            var shards = new Dictionary<string, IDocumentStore>
                {
                    { "one", new DocumentStore { Url = "http://localhost:8079", } },
                    { "two", new DocumentStore { Url = "http://localhost:8078", } },
                };

            var shardStrategy = new ShardStrategy(shards)
                .ShardingOn<User>()
                .ShardingOn<Story>(x => x.UserId);

            using (var store = new ShardedDocumentStore(shardStrategy).Initialize())
            {
                //using (var session = store.OpenSession())
                //{
                //	var user = new User { Name = "Ayende" };
                //	session.Store(user);
                //	session.Store(new Story { UserId = user.Id });
                //	session.SaveChanges();
                //}

                using (var session = store.OpenSession())
                {
                    var load = session.Query<Story>()
                        .Where(x => x.UserId == "two/users/1")
                        .ToList();

                    Console.WriteLine(load[0].UserId);
                }
            }
        }
开发者ID:ayende,项目名称:courses-trondheim-sep-2012,代码行数:32,代码来源:Program.cs

示例8: 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

示例9: Main

        private static void Main()
        {
            var shards = new Dictionary<string, IDocumentStore>
            {
                {"_", new DocumentStore {Url = "http://localhost:8080", DefaultDatabase = "Shop"}}, //existing data
                {"ME", new DocumentStore {Url = "http://localhost:8080", DefaultDatabase = "Shop_ME"}},
                {"US", new DocumentStore {Url = "http://localhost:8080", DefaultDatabase = "Shop_US"}},
            };

            var shardStrategy = new ShardStrategy(shards)
                .ShardingOn<Customer>(c => c.Region)
                .ShardingOn<Invoice>(i => i.Customer);

            var x = new ShardedDocumentStore(shardStrategy).Initialize();
            using (var s = x.OpenSession())
            {
                var customer = new Customer
                {
                    Region = "US"
                };
                s.Store(customer);
                s.Store(new Invoice
                {
                    Customer = customer.Id
                });
                s.SaveChanges();
            }
        }
开发者ID:jrusbatch,项目名称:ravendb,代码行数:28,代码来源:Program.cs

示例10: 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

示例11: 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

示例12: Index

		public Index()
		{
			#region store
			var shards = new Dictionary<string, IDocumentStore>
			             	{
			             		{"Asia", new DocumentStore {Url = "http://localhost:8080"}},
			             		{"Middle East", new DocumentStore {Url = "http://localhost:8081"}},
			             		{"America", new DocumentStore {Url = "http://localhost:8082"}},
			             	};

			var shardStrategy = new ShardStrategy(shards)
				.ShardingOn<Company>(company => company.Region)
				.ShardingOn<Invoice>(x => x.CompanyId);

			var documentStore = new ShardedDocumentStore(shardStrategy).Initialize();

			#endregion

			#region SaveEntities
			using (var session = documentStore.OpenSession())
			{
				var asian = new Company { Name = "Company 1", Region = "Asia" };
				session.Store(asian);
				var middleEastern = new Company { Name = "Company 2", Region = "Middle-East" };
				session.Store(middleEastern);
				var american = new Company { Name = "Company 3", Region = "America" };
				session.Store(american);

				session.Store(new Invoice { CompanyId = american.Id, Amount = 3, IssuedAt = DateTime.Today.AddDays(-1) });
				session.Store(new Invoice { CompanyId = asian.Id, Amount = 5, IssuedAt = DateTime.Today.AddDays(-1) });
				session.Store(new Invoice { CompanyId = middleEastern.Id, Amount = 12, IssuedAt = DateTime.Today });
				session.SaveChanges();
			}

			#endregion

			#region Query
			using (var session = documentStore.OpenSession())
			{
				//get all, should automagically retrieve from each shard
				var allCompanies = session.Query<Company>()
					.Customize(x => x.WaitForNonStaleResultsAsOfNow())
					.Where(company => company.Region == "Asia")
					.ToArray();

				foreach (var company in allCompanies)
					Console.WriteLine(company.Name);
			}

			#endregion

			documentStore.Dispose();
		}
开发者ID:modulexcite,项目名称:docs-8,代码行数:53,代码来源:Index.cs

示例13: ShardedBulkInsertOperation

 public ShardedBulkInsertOperation(string database, ShardedDocumentStore shardedDocumentStore, BulkInsertOptions options)
 {
     this.database = database;
     this.shardedDocumentStore = shardedDocumentStore;
     this.options = options;
     shards = shardedDocumentStore.ShardStrategy.Shards;
     Bulks = new Dictionary<string, BulkInsertOperation>();
     generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(shardedDocumentStore.Conventions,
         entity => AsyncHelpers.RunSync(() => shardedDocumentStore.Conventions.GenerateDocumentKeyAsync(database, DatabaseCommands, entity)));
     shardResolutionStrategy = shardedDocumentStore.ShardStrategy.ShardResolutionStrategy;
     shardStrategy = this.shardedDocumentStore.ShardStrategy;
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:12,代码来源:ShardedBulkInsertOperation.cs

示例14: 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

示例15: 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


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