public IPuller CreatePuller(IIndexModel model) { if (model == null) { return(null); } using (var connectionRepository = ResolverFactory.Resolve <ConnectionRepository>()) using (var entityRepository = ResolverFactory.Resolve <EntityRepository>()) { var sourceConnection = connectionRepository.GetById(model.SourceConnectionId.ToString()); IPuller result = null; if (model.EntityType == EntityType.Attribute) { var attrModel = model as AttributeModel; var entityModel = entityRepository.GetById(attrModel.EntityId.ToString()); result = pullers.Where(p => typeof(IAttributePuller).IsAssignableFrom(p.GetType())) .Select(p => p as IAttributePuller) .FirstOrDefault(p => p.IsImplemented(model.SourceProcessorId, entityModel.SourceProcessorId, sourceConnection.ProviderId)); } else { result = pullers.Where(p => typeof(IEntityPuller).IsAssignableFrom(p.GetType())) .Select(p => p as IEntityPuller) .FirstOrDefault(p => p.IsImplemented(model.SourceProcessorId, sourceConnection.ProviderId)); } var options = entityRepository.LoadOptions(model.Id.ToString(), model.EntityType) .Select(o => new OptionItem { Name = o.Key, Value = o.Value }); result.SetIndex(model); result.SetOptions(options); return(result); } }
public override async Task Invoke(IStepExecutionContext context = null) { try { Logger.Information($@"Updating index changes of {IndexModel.Name}/{IndexModel.Id}..."); var sourceConnection = connectionRepository.GetById(IndexModel.SourceConnectionId.ToString()); //var destConnection = connectionRepository.GetById(IndexModel.DestinationConnectionId.ToString()); IPuller puller = null; IIndexer indexer = null; if (IndexModel.EntityType == EntityType.Entity) { puller = pullers.Where(p => typeof(IEntityPuller).IsAssignableFrom(p.GetType())) .Select(p => (IEntityPuller)p) .FirstOrDefault(p => p.IsImplemented( IndexModel?.SourceProcessorId, sourceConnection?.ProviderId)); indexer = indexers.Where(p => typeof(IEntityIndexer).IsAssignableFrom(p.GetType())) .Select(p => (IEntityIndexer)p) .FirstOrDefault(p => p.IsImplemented( IndexModel?.SourceProcessorId, sourceConnection?.ProviderId)); } else { var entity = entityRepository.GetById((IndexModel as AttributeModel).EntityId.ToString()); puller = pullers.Where(p => typeof(IAttributePuller).IsAssignableFrom(p.GetType())) .Select(p => (IAttributePuller)p) .FirstOrDefault(p => p.IsImplemented( IndexModel.SourceProcessorId, entity?.SourceProcessorId, sourceConnection?.ProviderId)); indexer = indexers.Where(p => typeof(IAttributeIndexer).IsAssignableFrom(p.GetType())) .Select(p => (IAttributeIndexer)p) .FirstOrDefault(p => p.IsImplemented( IndexModel.SourceProcessorId, entity?.SourceProcessorId, sourceConnection?.ProviderId)); } var options = entityRepository.LoadOptions(IndexModel.Id.ToString(), IndexModel.EntityType) .Select(o => new OptionItem { Name = o.Key, Value = o.Value }); puller.SetIndex(IndexModel); puller.SetOptions(options); indexer.SetIndex(IndexModel); indexer.SetOptions(options); indexerManager.SetIndex(IndexModel); indexerManager.SetPuller(puller); indexerManager.SetIndexer(indexer); indexerManager.OnReport(s => { Logger.Information(s); }); await indexerManager.PullNext(); Logger.Information($@"Updated index changes of {IndexModel.Name}/{IndexModel.Id}"); } catch (Exception ex) { ErrorLogger.Error(ex, ex.Message); throw; } }