コード例 #1
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <Task <T[]> > LazyLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval, CancellationToken token = default(CancellationToken))
        {
            var loadOperation = new LoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, ids, includes);
            var lazyOp        = new LazyLoadOperation <T>(loadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval, token));
        }
コード例 #2
0
        public Lazy <Task <Dictionary <string, T> > > LazyAsyncLoadInternal <T>(string[] ids, string[] includes, Action <Dictionary <string, T> > onEval, CancellationToken token = default(CancellationToken))
        {
            var loadOperation = new LoadOperation(this).ByIds(ids).WithIncludes(includes);
            var lazyOp        = new LazyLoadOperation <T>(this, loadOperation).ByIds(ids).WithIncludes(includes);

            return(AddLazyOperation(lazyOp, onEval, token));
        }
コード例 #3
0
        Lazy <TResult> ILazySessionOperations.Load <TTransformer, TResult>(string id)
        {
            var transformer       = new TTransformer().TransformerName;
            var lazyLoadOperation = new LazyLoadOperation <TResult>(id, new LoadOperation(this, DatabaseCommands.DisableAllCaching, id), HandleInternalMetadata, transformer);

            return(AddLazyOperation <TResult>(lazyLoadOperation, null));
        }
コード例 #4
0
        /// <summary>
        /// Loads the specified id and a function to call when it is evaluated
        /// </summary>
        Lazy <T> ILazySessionOperations.Load <T>(string id, Action <T> onEval)
        {
            if (IsLoaded(id))
            {
                return(new Lazy <T>(() => Load <T>(id)));
            }
            var lazyLoadOperation = new LazyLoadOperation <T>(id, new LoadOperation(this, DatabaseCommands.DisableAllCaching, id), HandleInternalMetadata);

            return(AddLazyOperation(lazyLoadOperation, onEval));
        }
コード例 #5
0
        /// <summary>
        /// Loads the specified id and a function to call when it is evaluated
        /// </summary>
        Lazy <T> ILazySessionOperations.Load <T>(string id, Action <T> onEval)
        {
            if (IsLoaded(id))
            {
                return(new Lazy <T>(() => Load <T>(id)));
            }
            var lazyLoadOperation = new LazyLoadOperation <T>(this, new LoadOperation(this).ById(id)).ById(id);

            return(AddLazyOperation(lazyLoadOperation, onEval));
        }
コード例 #6
0
        /// <summary>
        /// Loads the specified id and a function to call when it is evaluated
        /// </summary>
        public Lazy <T> Load <T>(string id, Action <T> onEval)
        {
            if (IsLoaded(id))
            {
                return(new Lazy <T>(() => Load <T>(id)));
            }
            var lazyLoadOperation = new LazyLoadOperation <T>(id, new LoadOperation(this, DatabaseCommands.DisableAllCaching, id));

            return(AddLazyOperation(lazyLoadOperation, onEval));
        }
コード例 #7
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <T[]> LazyLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval)
        {
            if (CheckIfIdAlreadyIncluded(ids, includes))
            {
                return(new Lazy <T[]>(() => ids.Select(Load <T>).ToArray()));
            }
            var loadOperation = new LoadOperation(this, DatabaseCommands.DisableAllCaching, ids, includes);
            var lazyOp        = new LazyLoadOperation <T>(loadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval));
        }
コード例 #8
0
        /// <summary>
        /// Loads the specified id and a function to call when it is evaluated
        /// </summary>
        public Lazy <Task <T> > LoadAsync <T>(string id, Action <T> onEval, CancellationToken token = default(CancellationToken))
        {
            if (IsLoaded(id))
            {
                return(new Lazy <Task <T> >(() => LoadAsync <T>(id, token)));
            }

            var lazyLoadOperation = new LazyLoadOperation <T>(id, new LoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, id), handleInternalMetadata: HandleInternalMetadata);

            return(AddLazyOperation(lazyLoadOperation, onEval, token));
        }
コード例 #9
0
        /// <summary>
        /// Loads the specified id and a function to call when it is evaluated
        /// </summary>
        public Lazy <Task <T> > LoadAsync <T>(string id, Action <T> onEval, CancellationToken token = new CancellationToken())
        {
            if (IsLoaded(id))
            {
                return(new Lazy <Task <T> >(() => LoadAsync <T>(id, token)));
            }

            var lazyLoadOperation = new LazyLoadOperation <T>(this, new LoadOperation(this).ById(id)).ById(id);

            return(AddLazyOperation(lazyLoadOperation, onEval, token));
        }
コード例 #10
0
        public Lazy <Task <T[]> > LazyAsyncLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval, CancellationToken token = default(CancellationToken))
        {
            if (CheckIfIdAlreadyIncluded(ids, includes))
            {
                return(new Lazy <Task <T[]> >(async() => await Task.WhenAll(ids.Select(id => LoadAsync <T>(id, token)).ToArray()).WithCancellation(token).ConfigureAwait(false)));
            }
            var loadOperation = new LoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, ids, includes);
            var lazyOp        = new LazyLoadOperation <T>(loadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval));
        }
コード例 #11
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <Dictionary <string, T> > LazyLoadInternal <T>(string[] ids, string[] includes, Action <Dictionary <string, T> > onEval)
        {
            if (CheckIfIdAlreadyIncluded(ids, includes))
            {
                return(new Lazy <Dictionary <string, T> >(() => ids.ToDictionary(x => x, Load <T>)));
            }
            var loadOperation = new LoadOperation(this)
                                .ByIds(ids)
                                .WithIncludes(includes);

            var lazyOp = new LazyLoadOperation <T>(this, loadOperation).ByIds(ids).WithIncludes(includes);

            return(AddLazyOperation(lazyOp, onEval));
        }
コード例 #12
0
        /// <summary>
        /// Loads the specified id and a function to call when it is evaluated
        /// </summary>
        public Lazy <TResult> Load <TResult>(string id, Action <TResult> onEval)
        {
            var cmds = GetCommandsToOperateOn(new ShardRequestData
            {
                Key = id, EntityType = typeof(TResult)
            });

            var lazyLoadOperation = new LazyLoadOperation <TResult>(id, new LoadOperation(this, () =>
            {
                var list = cmds.Select(databaseCommands => databaseCommands.DisableAllCaching()).ToList();
                return(new DisposableAction(() => list.ForEach(x => x.Dispose())));
            }, id));

            return(AddLazyOperation(lazyLoadOperation, onEval, cmds));
        }
コード例 #13
0
        Lazy <TResult> ILazySessionOperations.Load <TTransformer, TResult>(string id)
        {
            var cmds = GetCommandsToOperateOn(new ShardRequestData
            {
                Keys       = { id },
                EntityType = typeof(TTransformer)
            });

            var lazyLoadOperation = new LazyLoadOperation <TResult>(id, new LoadOperation(this, () =>
            {
                var list = cmds.Select(databaseCommands => databaseCommands.DisableAllCaching()).ToList();
                return(new DisposableAction(() => list.ForEach(x => x.Dispose())));
            }, id), HandleInternalMetadata);

            return(AddLazyOperation <TResult>(lazyLoadOperation, null, cmds));
        }
コード例 #14
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <T[]> LazyLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval)
        {
            var idsAndShards = ids.Select(id => new
            {
                id,
                shards = GetCommandsToOperateOn(new ShardRequestData
                {
                    Keys       = { id },
                    EntityType = typeof(T),
                })
            })
                               .GroupBy(x => x.shards, new DbCmdsListComparer());
            var cmds = idsAndShards.SelectMany(idAndShard => idAndShard.Key).Distinct().ToList();

            var multiLoadOperation = new LoadOperation(this, () =>
            {
                var list = cmds.Select(cmd => cmd.DisableAllCaching()).ToList();
                return(new DisposableAction(() => list.ForEach(disposable => disposable.Dispose())));
            }, ids, includes);
            var lazyOp = new LazyLoadOperation <T>(multiLoadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval, cmds));
        }
コード例 #15
0
ファイル: DocumentSession.cs プロジェクト: tal952/ravendb
        public Lazy <TResult> Load <TResult>(string id, Action <TResult> onEval)
        {
            var lazyLoadOperation = new LazyLoadOperation <TResult>(id, new LoadOperation(this, DatabaseCommands.DisableAllCaching, id));

            return(AddLazyOperation(lazyLoadOperation, onEval));
        }