Exemplo n.º 1
0
        /// <summary>
        /// Таблицы.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableId">Идентификатор таблицы</param>
        /// <param name="o">Сущность</param>
        /// <returns></returns>
        public async Task <IEnumerable <T> > UpdateAsync(IEnumerable <T> o, CancellationToken token = default(CancellationToken))
        {
            if (o == null || o.Count() == 0)
            {
                return(Enumerable.Empty <T>());
            }
            ConcurrentBag <T>  result = new ConcurrentBag <T>();
            ParallelPumper <T> pumper = new ParallelPumper <T>(o, ServicePointManager.DefaultConnectionLimit);

            pumper.Handler = async(e) =>
            {
                token.ThrowIfCancellationRequested();
                result.Add(await UpdateAsync(e, token));
            };
            pumper.Progress = async(p) => { };
            await pumper.Pump();

            return(result.ToList());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Таблицы.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableId">Идентификатор таблицы</param>
        /// <param name="o">Сущность</param>
        /// <returns></returns>
        public async Task <IEnumerable <T> > InsertAsync(IEnumerable <T> o, CancellationToken token = default(CancellationToken))
        {
            if (o == null || o.Count() == 0)
            {
                return(Enumerable.Empty <T>());
            }
            ConcurrentBag <T> result = new ConcurrentBag <T>();
            ParallelPumper <KeyValuePair <int, IEnumerable <T> > > pumper = new ParallelPumper <KeyValuePair <int, IEnumerable <T> > >(await o.GetPages(100), ServicePointManager.DefaultConnectionLimit);

            pumper.Handler = async(page) =>
            {
                token.ThrowIfCancellationRequested();
                var res = await _sclm.POSTAsync <IEnumerable <T> >(GetUri(Id + "/insertmany"), page.Value, token);;
                foreach (var t in res)
                {
                    result.Add(t);
                }
            };
            pumper.Progress = async(p) => { };
            await pumper.Pump();

            return(result.ToList());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Удаляет записи в таблице по списку идентификаторов.
        /// </summary>
        /// <param name="ids">Список идентификаторов записей в таблице</param>
        /// <returns></returns>
        public async Task <IEnumerable <T> > DeleteAsync(IEnumerable <string> ids, CancellationToken token = default(CancellationToken))
        {
            if (ids == null || ids.Count() == 0)
            {
                return(Enumerable.Empty <T>());
            }
            ConcurrentBag <T> result = new ConcurrentBag <T>();
            ParallelPumper <KeyValuePair <int, IEnumerable <string> > > pumper = new ParallelPumper <KeyValuePair <int, IEnumerable <string> > >(await ids.GetPages(50), ServicePointManager.DefaultConnectionLimit);

            pumper.Handler = async(page) =>
            {
                token.ThrowIfCancellationRequested();
                var res = await _sclm.DELETEAsync <IEnumerable <T> >(GetUri(Id + "/deletemany" + page.Value.ToIdsQueryArray()), token);

                foreach (var t in res)
                {
                    result.Add(t);
                }
            };
            pumper.Progress = async(p) => { };
            await pumper.Pump();

            return(result.ToList());
        }