Raven.Client.Shard.ShardedDocumentStore.Initialize C# (CSharp) Method

Initialize() public method

Initializes this instance.
public Initialize ( ) : IDocumentStore
return IDocumentStore
		public override IDocumentStore Initialize()
		{
			try
			{
				ShardStrategy.Shards.ForEach(shard => shard.Value.Initialize());
				if (Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing
				{
					var generator = new ShardedHiloKeyGenerator(this, 32);
					Conventions.DocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKey(commands, Conventions, entity);
				}

				if (Conventions.AsyncDocumentKeyGenerator == null)
				{
#if !SILVERLIGHT
					var generator = new AsyncShardedHiloKeyGenerator(this, 32);
					Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(commands, Conventions, entity);
#else
					Conventions.AsyncDocumentKeyGenerator = entity =>
					{
						var typeTagName = Conventions.GetTypeTagName(entity.GetType());
						if (typeTagName == null)
							return CompletedTask.With(Guid.NewGuid().ToString());
						return CompletedTask.With(typeTagName + "/" + Guid.NewGuid());
					};
#endif
				}
			}
			catch (Exception)
			{
				Dispose();
				throw;
			}

			return this;
		}

Usage Example

Esempio n. 1
0
		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();
		}
All Usage Examples Of Raven.Client.Shard.ShardedDocumentStore::Initialize