Exemplo n.º 1
0
        public bool TrySelectIds(Expression <Func <Selector <T>, Selector <T> > > expression, out List <int> result, out long total)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t) || !Indexer.CheckExist(t))
            {
                result = new List <int>();
                total  = 0;
                return(false);
            }

            try
            {
                result = Indexer.Select(expression, true, out total).Select(r => r.Id).ToList();
            }
            catch (Exception e)
            {
                Logger.Error("Select", e);
                total  = 0;
                result = new List <int>();
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public void Refresh()
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }
            Indexer.Refresh();
        }
Exemplo n.º 3
0
        public Task <bool> DeleteAsync(T data, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return(Task.FromResult(false));
            }
            return(Queue(() => Indexer.Delete(data, immediately)));
        }
Exemplo n.º 4
0
        public Task <bool> UpdateAsync(T data, bool immediately = true, params Expression <Func <T, object> >[] fields)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return(Task.FromResult(false));
            }
            return(Queue(() => Indexer.Update(data, immediately, fields)));
        }
Exemplo n.º 5
0
        public Task <bool> DeleteAsync(Expression <Func <Selector <T>, Selector <T> > > expression, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return(Task.FromResult(false));
            }
            var tenant = TenantManager.GetCurrentTenant().TenantId;

            return(Queue(() => Indexer.Delete(expression, tenant, immediately)));
        }
Exemplo n.º 6
0
        public void Delete(T data, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }

            try
            {
                Indexer.Delete(data, immediately);
            }
            catch (Exception e)
            {
                Logger.Error("Delete", e);
            }
        }
Exemplo n.º 7
0
        public void Update(T data, UpdateAction action, Expression <Func <T, IList> > field, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }

            try
            {
                Indexer.Update(data, action, field, immediately);
            }
            catch (Exception e)
            {
                Logger.Error("Update", e);
            }
        }
Exemplo n.º 8
0
        public void Update(T data, bool immediately = true, params Expression <Func <T, object> >[] fields)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }

            try
            {
                Indexer.Update(data, immediately, fields);
            }
            catch (Exception e)
            {
                Logger.Error("Update", e);
            }
        }
Exemplo n.º 9
0
        public void Update(T data, Expression <Func <Selector <T>, Selector <T> > > expression, UpdateAction action, Expression <Func <T, IList> > fields, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }

            try
            {
                var tenant = TenantManager.GetCurrentTenant().TenantId;
                Indexer.Update(data, expression, tenant, action, fields, immediately);
            }
            catch (Exception e)
            {
                Logger.Error("Update", e);
            }
        }
Exemplo n.º 10
0
        public void Delete(Expression <Func <Selector <T>, Selector <T> > > expression, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }

            var tenant = TenantManager.GetCurrentTenant().TenantId;

            try
            {
                Indexer.Delete(expression, tenant, immediately);
            }
            catch (Exception e)
            {
                Logger.Error("Index", e);
            }
        }
Exemplo n.º 11
0
        public bool Index(T data, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return(false);
            }

            try
            {
                Indexer.Index(data, immediately);
                return(true);
            }
            catch (Exception e)
            {
                Logger.Error("Index", e);
            }
            return(false);
        }
Exemplo n.º 12
0
        public bool TrySelect(Expression <Func <Selector <T>, Selector <T> > > expression, out IReadOnlyCollection <T> result)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t) || !Indexer.CheckExist(t))
            {
                result = new List <T>();
                return(false);
            }

            try
            {
                result = Indexer.Select(expression);
            }
            catch (Exception e)
            {
                Logger.Error("Select", e);
                result = new List <T>();
                return(false);
            }
            return(true);
        }
Exemplo n.º 13
0
        public void Index(List <T> data, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t) || !data.Any())
            {
                return;
            }

            try
            {
                Indexer.Index(data, immediately);
            }
            catch (AggregateException e)
            {
                if (e.InnerExceptions.Count == 0)
                {
                    throw;
                }

                var inner = e.InnerExceptions.OfType <ElasticsearchClientException>().FirstOrDefault();
                Logger.Error(inner);

                if (inner != null)
                {
                    Logger.Error("inner", inner.Response.OriginalException);

                    if (inner.Response.HttpStatusCode == 413)
                    {
                        data.ForEach(r => Index(r, immediately));
                    }
                }
                else
                {
                    throw;
                }
            }
        }