Example #1
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        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)
                {
                    var generator = new AsyncShardedHiloKeyGenerator(this, 32);
                    Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(commands, Conventions, entity);
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return(this);
        }
Example #2
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public override IDocumentStore Initialize()
        {
            try
            {
                ShardStrategy.Shards.ForEach(shard => shard.Value.Initialize());

                var shardsPointingToSameDb = ShardStrategy.Shards
                                             .GroupBy(x =>
                {
                    try
                    {
                        return(x.Value.DatabaseCommands.GetStatistics().DatabaseId);
                    }
                    catch (Exception)
                    {
                        return(Guid.NewGuid());   // we'll just ignore any connection erros here
                    }
                }).FirstOrDefault(x => x.Count() > 1);


                if (shardsPointingToSameDb != null)
                {
                    throw new NotSupportedException(string.Format("Multiple keys in shard dictionary for {0} are not supported.",
                                                                  string.Join(", ", shardsPointingToSameDb.Select(x => x.Key))));
                }

                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)
                {
                    var generator = new AsyncShardedHiloKeyGenerator(this, 32);
                    Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(commands, Conventions, entity);
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return(this);
        }
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        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);
        }
		/// <summary>
		/// Initializes this instance.
		/// </summary>
		/// <returns></returns>
		public override IDocumentStore Initialize()
		{
			try
			{
				ShardStrategy.Shards.ForEach(shard => shard.Value.Initialize());

                var shardsPointingToSameDb = ShardStrategy.Shards
                    .GroupBy(x =>
                    {
                        try
                        {
                            return x.Value.DatabaseCommands.GetStatistics().DatabaseId;
                        }
                        catch (Exception)
                        {
                            return Guid.NewGuid();// we'll just ignore any connection erros here
                        }
                    }).FirstOrDefault(x => x.Count() > 1);


			    if (shardsPointingToSameDb != null)
			        throw new NotSupportedException(string.Format("Multiple keys in shard dictionary for {0} are not supported.",
			            string.Join(", ", shardsPointingToSameDb.Select(x => x.Key))));

                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)
				{
					var generator = new AsyncShardedHiloKeyGenerator(this, 32);
					Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(commands, Conventions, entity);
				}
			}
			catch (Exception)
			{
				Dispose();
				throw;
			}

			return this;
		}
Example #5
0
		/// <summary>
		/// Initializes this instance.
		/// </summary>
		/// <returns></returns>
		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;
		}
		/// <summary>
		/// Initializes this instance.
		/// </summary>
		/// <returns></returns>
		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)
				{
					var generator = new AsyncShardedHiloKeyGenerator(this, 32);
					Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(commands, Conventions, entity);
				}
			}
			catch (Exception)
			{
				Dispose();
				throw;
			}

			return this;
		}