Ejemplo 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);
        }
Ejemplo n.º 2
0
        public void Refresh()
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }
            Indexer.Refresh();
        }
Ejemplo 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)));
        }
Ejemplo 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)));
        }
Ejemplo 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)));
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo n.º 10
0
 public FactoryIndexer(
     IOptionsMonitor <ILog> options,
     FactoryIndexerHelper factoryIndexerSupport,
     TenantManager tenantManager,
     SearchSettingsHelper searchSettingsHelper,
     FactoryIndexer factoryIndexer,
     BaseIndexer <T> baseIndexer,
     Client client,
     IServiceProvider serviceProvider)
 {
     Logger = options.Get("ASC.Indexer");
     FactoryIndexerHelper = factoryIndexerSupport;
     TenantManager        = tenantManager;
     SearchSettingsHelper = searchSettingsHelper;
     FactoryIndexerCommon = factoryIndexer;
     Indexer         = baseIndexer;
     Client          = client;
     ServiceProvider = serviceProvider;
 }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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;
                }
            }
        }