Ejemplo n.º 1
0
        /// <summary>
        /// Build a single index asynchronously
        /// </summary>
        /// <param name="indexInstance">An activated AbstractIndexCreationTask instance</param>
        /// <param name="progressCallBack">A callback we can use to report on the progress of a batch job; default is null</param>
        /// <returns>A task containing an IndexBuildResult report for this specific index</returns>
        public Task<IndexBuildResult> BuildIndexAsync(AbstractIndexCreationTask indexInstance, Action<IndexBuildResult> progressCallBack = null)
        {
            return Task.Factory.StartNew(() => indexInstance.Execute(_documentStore))
                .ContinueWith(result =>
                                  {
                                      var indexBuildResult = new IndexBuildResult()
                                                                 {IndexName = indexInstance.IndexName, ConnectionString = _documentStore.Identifier};

                                      if (result.IsCompleted && result.Exception == null)
                                      {
                                          indexBuildResult.Result = BuildResult.Created;
                                      }
                                      else if (result.IsCanceled)
                                      {
                                          indexBuildResult.Result = BuildResult.Cancelled;
                                      }
                                      else
                                      {
                                          indexBuildResult.Result = BuildResult.Failed;
                                          indexBuildResult.BuildException = result.Exception != null ? result.Exception.Flatten() : null;
                                      }

                                      if (progressCallBack != null)
                                      {
                                          progressCallBack.Invoke(indexBuildResult);
                                      }

                                      return indexBuildResult;
                                  });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Build a single index synchronously
        /// </summary>
        /// <param name="indexInstance">An activated AbstractIndexCreationTask instance</param>
        /// <returns>An IndexBuildResult report for this specific index</returns>
        public IndexBuildResult BuildIndex(AbstractIndexCreationTask indexInstance)
        {
            var buildIndexTask = BuildIndexAsync(indexInstance, null);

            buildIndexTask.Wait();

            return buildIndexTask.Result;
        }
Ejemplo n.º 3
0
        public void PutIndex(AbstractIndexCreationTask index)
        {
            var response = httpClient
                .PutAsync(databaseUrl + "/indexes/" + Uri.EscapeUriString(index.IndexName), new JsonContent(RavenJObject.FromObject(index.CreateIndexDefinition())))
                .ResultUnwrap();

            if (response.IsSuccessStatusCode == false)
                throw new InvalidOperationException(string.Format("PUT failed on '{0}'. Code: {1}.", index.IndexName, response.StatusCode));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Safely add the index to the RavenDB database, protect against possible failures caused by documented
 /// and undocumented possibilities of failure.
 /// Will throw iff index registration failed and index doesn't exist or it exists but with a non-current definition.
 /// </summary>
 /// <param name="store"></param>
 /// <param name="index"></param>
 internal static void SafelyCreateIndex(IDocumentStore store, AbstractIndexCreationTask index)
 {
     try
     {
         index.Execute(store);
     }
     catch (Exception) // Apparently ArgumentException can be thrown as well as a WebException; not taking any chances
     {
         var existingIndex = store.DatabaseCommands.GetIndex(index.IndexName);
         if (existingIndex == null || !index.CreateIndexDefinition().Equals(existingIndex))
             throw;
     }
 }
Ejemplo n.º 5
0
	    public void SideBySideExecuteIndex(AbstractIndexCreationTask indexCreationTask, Etag minimumEtagBeforeReplace = null, DateTime? replaceTimeUtc = null)
	    {
			Inner.SideBySideExecuteIndex(indexCreationTask, minimumEtagBeforeReplace, replaceTimeUtc);
	    }
Ejemplo n.º 6
0
	    /// <summary>
        ///     Executes the index creation.
        /// </summary>
        /// <param name="indexCreationTask"></param>
        public Task ExecuteIndexAsync(AbstractIndexCreationTask indexCreationTask)
        {
            return server.DocumentStore.ExecuteIndexAsync(indexCreationTask);
        }
Ejemplo n.º 7
0
 /// <summary>
 ///     Executes the index creation.
 /// </summary>
 public void ExecuteIndex(AbstractIndexCreationTask indexCreationTask)
 {
     server.DocumentStore.ExecuteIndex(indexCreationTask);
 }
Ejemplo n.º 8
0
		public override Task SideBySideExecuteIndexAsync(AbstractIndexCreationTask indexCreationTask, Etag minimumEtagBeforeReplace = null, DateTime? replaceTimeUtc = null)
		{
			var list = ShardStrategy.Shards.Values.Select(x => x.AsyncDatabaseCommands).ToList();
			return ShardStrategy.ShardAccessStrategy.ApplyAsync(list, new ShardRequestData(), (commands, i) =>
			{
				var tcs = new TaskCompletionSource<bool>();

				try
				{
					indexCreationTask.SideBySideExecuteAsync(commands, Conventions, minimumEtagBeforeReplace, replaceTimeUtc)
									 .ContinueWith(t => tcs.SetResult(true));
				}
				catch (Exception e)
				{
					tcs.SetException(e);
				}

				return tcs.Task;
			});
		}
Ejemplo n.º 9
0
 public void ExecuteIndex(AbstractIndexCreationTask indexCreationTask)
 {
     this.ThrowIfNotInitialized();
     this.innerStore.ExecuteIndex(indexCreationTask);
 }
 public Task ExecuteIndexAsync(AbstractIndexCreationTask indexCreationTask)
 {
     return Inner.ExecuteIndexAsync(indexCreationTask);
 }
Ejemplo n.º 11
0
		/// <summary>
		/// Executes the index creation against each of the shards.
		/// </summary>
		public override void ExecuteIndex(AbstractIndexCreationTask indexCreationTask)
		{
			var list = ShardStrategy.Shards.Values.Select(x => x.DatabaseCommands).ToList();
			ShardStrategy.ShardAccessStrategy.Apply(list,
															new ShardRequestData()
															, (commands, i) =>
															{
																indexCreationTask.Execute(commands, Conventions);
																return (object)null;
															});
		}
Ejemplo n.º 12
0
	    public virtual Task ExecuteIndexAsync(AbstractIndexCreationTask indexCreationTask)
	    {
	        return indexCreationTask.ExecuteAsync(AsyncDatabaseCommands, Conventions);
	    }
Ejemplo n.º 13
0
		/// <summary>
		/// Executes the index creation in side-by-side mode.
		/// </summary>
		public virtual Task SideBySideExecuteIndexAsync(AbstractIndexCreationTask indexCreationTask, Etag minimumEtagBeforeReplace = null, DateTime? replaceTimeUtc = null)
		{
			return indexCreationTask.SideBySideExecuteAsync(AsyncDatabaseCommands, Conventions, minimumEtagBeforeReplace, replaceTimeUtc);
		}
Ejemplo n.º 14
0
		/// <summary>
		/// Executes the index creation in side-by-side mode.
		/// </summary>
		public virtual void SideBySideExecuteIndex(AbstractIndexCreationTask indexCreationTask, Etag minimumEtagBeforeReplace = null, DateTime? replaceTimeUtc = null)
		{
			indexCreationTask.SideBySideExecute(DatabaseCommands, Conventions, minimumEtagBeforeReplace, replaceTimeUtc);
		}
Ejemplo n.º 15
0
	    public Task SideBySideExecuteIndexAsync(AbstractIndexCreationTask indexCreationTask, Etag minimumEtagBeforeReplace = null, DateTime? replaceTimeUtc = null)
	    {
		    return Inner.SideBySideExecuteIndexAsync(indexCreationTask, minimumEtagBeforeReplace, replaceTimeUtc);
	    }
Ejemplo n.º 16
0
        /// <summary>
        /// Executes the index creation against each of the shards Async.
        /// </summary>
        public override Task ExecuteIndexAsync(AbstractIndexCreationTask indexCreationTask)
        {
            var list = ShardStrategy.Shards.Values.Select(x => x.AsyncDatabaseCommands).ToList();
            return ShardStrategy.ShardAccessStrategy.ApplyAsync(list,new ShardRequestData(), (commands, i) =>
            {
                var tcs = new TaskCompletionSource<bool>();

                try
                {
                    indexCreationTask.ExecuteAsync(commands, Conventions)
                                     .ContinueWith(t => tcs.SetResult(true));
                }
                catch (Exception e)
                {
                    tcs.SetException(e);
                }

                return tcs.Task;
            });
        }
 public void ExecuteIndex(AbstractIndexCreationTask indexCreationTask)
 {
     Inner.ExecuteIndex(indexCreationTask);
 }
Ejemplo n.º 18
0
		public override void SideBySideExecuteIndex(AbstractIndexCreationTask indexCreationTask, Etag minimumEtagBeforeReplace = null, DateTime? replaceTimeUtc = null)
		{
			var list = ShardStrategy.Shards.Values.Select(x => x.DatabaseCommands).ToList();
			ShardStrategy.ShardAccessStrategy.Apply(list,
															new ShardRequestData()
															, (commands, i) =>
															{
																indexCreationTask.SideBySideExecute(commands, Conventions, minimumEtagBeforeReplace, replaceTimeUtc);
																return (object)null;
															});
		}
Ejemplo n.º 19
0
		/// <summary>
		/// Executes the index creation.
		/// </summary>
		public virtual void ExecuteIndex(AbstractIndexCreationTask indexCreationTask)
		{
			indexCreationTask.Execute(DatabaseCommands, Conventions);
		}
Ejemplo n.º 20
0
 public void ExecuteIndex(AbstractIndexCreationTask indexCreationTask)
 {
     throw new NotImplementedException();
 }