private void DoWork() { while (!shutdown) { IndexQueueItem item = null; try { if (_indexQueue.Queue.TryDequeue(out item)) { try { //_logger.LogDebug("Dequeued item - " + item.EntityID); //IIndexStore indexStore = _services.GetService<IIndexStore>(); IIndexStore indexStore = IoC.Container.Resolve <IIndexStore>(); IDbContext primaryDC = (IoC.Container.Resolve(item.ContextType) as IDbContext); IIndexBuilder indexer = new IndexBuilder(indexStore, primaryDC, _indexQueue, _registry); //TODO: fix indexer.IndexEntity(item.EntityType, item.EntityID, item.Recursive, item.ContextType); indexStore.SaveChanges(); indexStore.Dispose(); primaryDC.Dispose(); } catch (OptimisticConcurrencyException ex) { _indexQueue.Queue.Enqueue(item); //_logger.LogError("Error indexing (" + item.EntityType + ", " + item.EntityID.ToString() + "): " + ex.Message, ex); } catch (Exception ex) { //todo: add error reporting //_logger.LogError("Error indexing (" + item.EntityType + ", " + item.EntityID.ToString() + "): " + ex.Message, ex); } } else { System.Threading.Thread.Sleep(500); //no work } } catch (Exception ex) { //todo: add error reporting //_logger.LogError("Error indexing (" + item.EntityType + ", " + item.EntityID.ToString() + "): " + ex.Message, ex); } } }
public void RegisterEntityTypes(Assembly assembly) { if (_processedAssemblies.Contains(assembly.FullName)) { return; } _processedAssemblies.Add(assembly.FullName); Type[] types = assembly.GetTypes(); //foreach (var t in types.Where(x => x.IsClass && !x.IsAbstract).Where(x => x.GetInterfaces().Any(y => y.GetGenericTypeDefinition() == typeof(EntityIndexer<>)))) foreach (var t in types.Where(x => x.IsClass && !x.IsAbstract).Where(x => x.GetInterfaces().Any(y => y == typeof(IEntityIndexer)))) { var entityType = GetEntityTypeFromIndexer(t); if (entityType != null) { _indexers.Add(entityType, t); } } var indexableTypes = types .Where(t => t.IsSubclassOf(typeof(BaseEntity)) && (!t.IsAbstract)) .ToList(); foreach (var type in indexableTypes) { _entityTypes.Add(type.FullName, type); int count = _indexStore.EntityTypes.Count(x => x.Name == type.FullName); if (count == 0) { _indexStore.EntityTypes.Add(new EntityType() { Name = type.FullName }); } } _indexStore.SaveChanges(); }