示例#1
0
		public void HandleResponses(GetResponse[] responses, ShardStrategy shardStrategy)
		{
			var list = new List<MultiLoadResult>(
				from response in responses
				let result = response.Result
				select new MultiLoadResult
				{
					Includes = result.Value<RavenJArray>("Includes").Cast<RavenJObject>().ToList(),
					Results = result.Value<RavenJArray>("Results").Cast<RavenJObject>().ToList()
				});

			var capacity = list.Max(x => x.Results.Count);

			var finalResult = new MultiLoadResult
			                  	{
									Includes = new List<RavenJObject>(),
			                  		Results = new List<RavenJObject>(Enumerable.Range(0,capacity).Select(x=> (RavenJObject)null))
			                  	};


			foreach (var multiLoadResult in list)
			{
				finalResult.Includes.AddRange(multiLoadResult.Includes);

				for (int i = 0; i < multiLoadResult.Results.Count; i++)
				{
					if (finalResult.Results[i] == null)
						finalResult.Results[i] = multiLoadResult.Results[i];
				}
			}
			RequiresRetry = loadOperation.SetResult(finalResult);
			if (RequiresRetry == false)
				Result = loadOperation.Complete<T>();

		}
示例#2
0
 private void HandleResponse(MultiLoadResult multiLoadResult)
 {
     RequiresRetry = multiLoadOperation.SetResult(multiLoadResult);
     if (RequiresRetry == false)
     {
         Result = multiLoadOperation.Complete <T>();
     }
 }
示例#3
0
        public T[] LoadInternal <T>(string[] ids)
        {
            if (ids.Length == 0)
            {
                return(new T[0]);
            }

            // only load documents that aren't already cached
            var idsOfNotExistingObjects = ids.Where(id => IsLoaded(id) == false && IsDeleted(id) == false)
                                          .Distinct(StringComparer.OrdinalIgnoreCase)
                                          .ToArray();

            if (idsOfNotExistingObjects.Length > 0)
            {
                IncrementRequestCount();
                var             multiLoadOperation = new MultiLoadOperation(this, DatabaseCommands.DisableAllCaching, idsOfNotExistingObjects, null);
                MultiLoadResult multiLoadResult;
                do
                {
                    multiLoadOperation.LogOperation();
                    using (multiLoadOperation.EnterMultiLoadContext())
                    {
                        multiLoadResult = DatabaseCommands.Get(idsOfNotExistingObjects, null);
                    }
                } while (multiLoadOperation.SetResult(multiLoadResult));

                multiLoadOperation.Complete <T>();
            }

            return(ids.Select(Load <T>).ToArray());
        }
示例#4
0
        public T[] LoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes)
        {
            if (ids.Length == 0)
            {
                return(new T[0]);
            }

            if (CheckIfIdAlreadyIncluded(ids, includes))
            {
                return(ids.Select(Load <T>).ToArray());
            }
            var includePaths = includes != null?includes.Select(x => x.Key).ToArray() : null;


            IncrementRequestCount();
            var             multiLoadOperation = new MultiLoadOperation(this, DatabaseCommands.DisableAllCaching, ids, includes);
            MultiLoadResult multiLoadResult;

            do
            {
                multiLoadOperation.LogOperation();
                using (multiLoadOperation.EnterMultiLoadContext())
                {
                    multiLoadResult = DatabaseCommands.Get(ids, includePaths);
                }
            } while (multiLoadOperation.SetResult(multiLoadResult));

            return(multiLoadOperation.Complete <T>());
        }
示例#5
0
        /// <summary>
        /// Begins the async multi load operation
        /// </summary>
        public async Task <T[]> LoadAsyncInternal <T>(string[] ids, CancellationToken token = default(CancellationToken))
        {
            if (ids.Length == 0)
            {
                return(new T[0]);
            }

            // only load documents that aren't already cached
            var idsOfNotExistingObjects = ids.Where(id => IsLoaded(id) == false && IsDeleted(id) == false)
                                          .Distinct(StringComparer.OrdinalIgnoreCase)
                                          .ToArray();

            if (idsOfNotExistingObjects.Length > 0)
            {
                IncrementRequestCount();
                var             multiLoadOperation = new MultiLoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, idsOfNotExistingObjects, null);
                MultiLoadResult multiLoadResult;
                do
                {
                    multiLoadOperation.LogOperation();
                    using (multiLoadOperation.EnterMultiLoadContext())
                    {
                        multiLoadResult = await AsyncDatabaseCommands.GetAsync(idsOfNotExistingObjects, null);
                    }
                } while (multiLoadOperation.SetResult(multiLoadResult));

                multiLoadOperation.Complete <T>();
            }

            var loadTasks  = ids.Select(async id => await LoadAsync <T>(id, token)).ToArray();
            var loadedData = await Task.WhenAll(loadTasks).WithCancellation(token);

            return(loadedData);
        }
示例#6
0
        /// <summary>
        /// Begins the async multi load operation
        /// </summary>
        public async Task <T[]> LoadAsyncInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, CancellationToken token = default(CancellationToken))
        {
            if (CheckIfIdAlreadyIncluded(ids, includes))
            {
                var loadTasks  = ids.Select(id => LoadAsync <T>(id, token)).ToArray();
                var loadedData = await Task.WhenAll(loadTasks).WithCancellation(token);

                return(loadedData);
            }

            IncrementRequestCount();
            var multiLoadOperation = new MultiLoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, ids, includes);

            multiLoadOperation.LogOperation();
            var includePaths = includes != null?includes.Select(x => x.Key).ToArray() : null;

            MultiLoadResult result;

            do
            {
                multiLoadOperation.LogOperation();
                using (multiLoadOperation.EnterMultiLoadContext())
                {
                    result = await AsyncDatabaseCommands.GetAsync(ids, includePaths, token : token).ConfigureAwait(false);
                }
            } while (multiLoadOperation.SetResult(result));
            return(multiLoadOperation.Complete <T>());
        }
示例#7
0
        public static T[] MoreLikeThis <T>(this ISyncAdvancedSessionOperation advancedSession, string index, MoreLikeThisQuery parameters)
        {
            if (string.IsNullOrEmpty(index))
            {
                throw new ArgumentException("Index name cannot be null or empty", "index");
            }

            parameters.IndexName = index;

            // /morelikethis/(index-name)/(ravendb-document-id)?fields=(fields)
            var cmd = advancedSession.DocumentStore.DatabaseCommands;

            var inMemoryDocumentSessionOperations = ((InMemoryDocumentSessionOperations)advancedSession);

            inMemoryDocumentSessionOperations.IncrementRequestCount();

            var             multiLoadOperation = new MultiLoadOperation(inMemoryDocumentSessionOperations, cmd.DisableAllCaching, null, null);
            MultiLoadResult multiLoadResult;

            do
            {
                multiLoadOperation.LogOperation();
                using (multiLoadOperation.EnterMultiLoadContext())
                {
                    multiLoadResult = cmd.MoreLikeThis(parameters);
                }
            } while (multiLoadOperation.SetResult(multiLoadResult));

            return(multiLoadOperation.Complete <T>());
        }
示例#8
0
        public static T[] MoreLikeThis <T>(this ISyncAdvancedSessionOperation advancedSession, string index, MoreLikeThisQueryParameters parameters)
        {
            var cmd = advancedSession.DocumentStore.DatabaseCommands as ServerClient;

            if (cmd == null)
            {
                throw new NotImplementedException("Embedded client isn't supported by the MoreLikeThis bundle");
            }


            var inMemoryDocumentSessionOperations = ((InMemoryDocumentSessionOperations)advancedSession);

            // /morelikethis/(index-name)/(ravendb-document-id)?fields=(fields)
            EnsureIsNotNullOrEmpty(index, "index");

            inMemoryDocumentSessionOperations.IncrementRequestCount();
            var             multiLoadOperation = new MultiLoadOperation(inMemoryDocumentSessionOperations, cmd.DisableAllCaching, null, null);
            MultiLoadResult multiLoadResult;

            do
            {
                multiLoadOperation.LogOperation();
                using (multiLoadOperation.EnterMultiLoadContext())
                {
                    var result = cmd.ExecuteGetRequest(parameters.GetRequestUri(index));

                    multiLoadResult = ((RavenJObject)result).Deserialize <MultiLoadResult>(inMemoryDocumentSessionOperations.Conventions);
                }
            } while (multiLoadOperation.SetResult(multiLoadResult));

            return(multiLoadOperation.Complete <T>());
        }
示例#9
0
        public static async Task <T[]> MoreLikeThisAsync <T>(this IAsyncAdvancedSessionOperations advancedSession, string index, string transformer, MoreLikeThisQuery parameters)
        {
            if (string.IsNullOrEmpty(index))
            {
                throw new ArgumentException("Index name cannot be null or empty", "index");
            }

            parameters.IndexName          = index;
            parameters.ResultsTransformer = transformer;

            // /morelikethis/(index-name)/(ravendb-document-id)?fields=(fields)
            var cmd = ((AsyncDocumentSession)advancedSession).AsyncDatabaseCommands;

            var inMemoryDocumentSessionOperations = ((InMemoryDocumentSessionOperations)advancedSession);

            inMemoryDocumentSessionOperations.IncrementRequestCount();

            var             multiLoadOperation = new MultiLoadOperation(inMemoryDocumentSessionOperations, cmd.DisableAllCaching, null, null);
            MultiLoadResult multiLoadResult;

            do
            {
                multiLoadOperation.LogOperation();
                using (multiLoadOperation.EnterMultiLoadContext())
                {
                    multiLoadResult = await cmd.MoreLikeThisAsync(parameters).ConfigureAwait(false);
                }
            } while (multiLoadOperation.SetResult(multiLoadResult));

            return(multiLoadOperation.Complete <T>());
        }
示例#10
0
        public void HandleResponse(GetResponse response)
        {
            var result = RavenJObject.Parse(response.Result);

            var multiLoadResult = new MultiLoadResult
            {
                Includes = result.Value <RavenJArray>("Includes").Cast <RavenJObject>().ToList(),
                Results  = result.Value <RavenJArray>("Results").Cast <RavenJObject>().ToList()
            };

            RequiresRetry = loadOperation.SetResult(multiLoadResult);
            if (RequiresRetry == false)
            {
                Result = loadOperation.Complete <T>();
            }
        }
示例#11
0
 private Task <T[]> LoadAsyncInternal <T>(string[] ids, string[] includes, MultiLoadOperation multiLoadOperation)
 {
     multiLoadOperation.LogOperation();
     using (multiLoadOperation.EnterMultiLoadContext())
     {
         return(AsyncDatabaseCommands.GetAsync(ids, includes)
                .ContinueWith(t =>
         {
             if (multiLoadOperation.SetResult(t.Result) == false)
             {
                 return Task.Factory.StartNew(() => multiLoadOperation.Complete <T>());
             }
             return LoadAsyncInternal <T>(ids, includes, multiLoadOperation);
         })
                .Unwrap());
     }
 }
示例#12
0
        /// <summary>
        /// Begins the async multi load operation
        /// </summary>
        public async Task <T[]> LoadAsyncInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes)
        {
            IncrementRequestCount();
            var multiLoadOperation = new MultiLoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, ids, includes);

            multiLoadOperation.LogOperation();
            var includePaths = includes != null?includes.Select(x => x.Key).ToArray() : null;

            MultiLoadResult result;

            do
            {
                multiLoadOperation.LogOperation();
                using (multiLoadOperation.EnterMultiLoadContext())
                {
                    result = await AsyncDatabaseCommands.GetAsync(ids, includePaths);
                }
            } while (multiLoadOperation.SetResult(result));
            return(multiLoadOperation.Complete <T>());
        }
示例#13
0
        internal T[] LoadInternal <T>(string[] ids, string[] includes)
        {
            if (ids.Length == 0)
            {
                return(new T[0]);
            }

            IncrementRequestCount();
            var             multiLoadOperation = new MultiLoadOperation(this, DatabaseCommands.DisableAllCaching, ids);
            MultiLoadResult multiLoadResult;

            do
            {
                multiLoadOperation.LogOperation();
                using (multiLoadOperation.EnterMultiLoadContext())
                {
                    multiLoadResult = DatabaseCommands.Get(ids, includes);
                }
            } while (multiLoadOperation.SetResult(multiLoadResult));

            return(multiLoadOperation.Complete <T>());
        }