public void NoDeletes() { var entity = GetTestEntity(); entity.MinVersion = 1; // to make entity.IsFirstRun() == false for testing purposes var input = GetTestReader(entity); var output = GetTestReader(entity); var deleter = new TestDeleter(entity, output.Data); var deleteHandler = new DefaultDeleteHandler(entity, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(2, deleter.Data.Count); }
public void NoDeletes() { var entity = GetTestEntity(); var input = GetTestReader(entity); var output = GetTestReader(entity); var deleter = new TestDeleter(entity, output.Data); var context = new PipelineContext(new TraceLogger(), new Process(), entity); var deleteHandler = new DefaultDeleteHandler(context, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(2, deleter.Data.Count); }
public void NoDeletes() { var entity = GetTestEntity(); entity.MinVersion = 1; // to make entity.IsFirstRun() == false for testing purposes var input = GetTestReader(entity); var output = GetTestReader(entity); var deleter = new TestDeleter(entity, output.Data); var deleteHandler = new DefaultDeleteHandler(entity, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(2, deleter.Data.Count); }
public void DeleteAll() { var entity = GetTestEntity(); entity.MinVersion = 1; // to make entity.IsFirstRun() == false for testing purposes var input = GetTestReader(entity); var output = GetTestReader(entity); // remove one from input input.Data.Clear(); var deleter = new TestDeleter(entity, output.Data); var deleteHandler = new DefaultDeleteHandler(entity, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(0, deleter.Data.Count, "output should everthing too"); }
public void OneDelete() { var entity = GetTestEntity(); entity.MinVersion = 1; // to make entity.IsFirstRun() == false for testing purposes var input = GetTestReader(entity); var output = GetTestReader(entity); // remove one from input var last = input.Data.Last(); input.Data.Remove(last); var deleter = new TestDeleter(entity, output.Data); var deleteHandler = new DefaultDeleteHandler(entity, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(1, deleter.Data.Count, "output should loose one too"); }
public void DeleteAll() { var entity = GetTestEntity(); entity.MinVersion = 1; // to make entity.IsFirstRun() == false for testing purposes var input = GetTestReader(entity); var output = GetTestReader(entity); // remove one from input input.Data.Clear(); var deleter = new TestDeleter(entity, output.Data); var deleteHandler = new DefaultDeleteHandler(entity, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(0, deleter.Data.Count, "output should everthing too"); }
public void OneDelete() { var entity = GetTestEntity(); entity.MinVersion = 1; // to make entity.IsFirstRun() == false for testing purposes var input = GetTestReader(entity); var output = GetTestReader(entity); // remove one from input var last = input.Data.Last(); input.Data.Remove(last); var deleter = new TestDeleter(entity, output.Data); var deleteHandler = new DefaultDeleteHandler(entity, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(1, deleter.Data.Count, "output should loose one too"); }
public void OneDelete() { var entity = GetTestEntity(); entity.MinVersion = 1; // to make entity.IsFirstRun() == false for testing purposes var input = GetTestReader(entity); var output = GetTestReader(entity); // remove one from input var last = input.Data.Last(); input.Data.Remove(last); var deleter = new TestDeleter(entity, output.Data); var context = new PipelineContext(new TraceLogger(), new Process().WithValidation(), entity); var deleteHandler = new DefaultDeleteHandler(context, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(1, deleter.Data.Count, "output should loose one too"); }
public void DeleteAll() { var entity = GetTestEntity(); entity.ModifyIndexes(); Assert.AreEqual(0, entity.Errors().Length); var input = GetTestReader(entity); var output = GetTestReader(entity); // remove one from input input.Data.Clear(); var deleter = new TestDeleter(entity, output.Data); var context = new PipelineContext(new TraceLogger(), new Process(), entity); var deleteHandler = new DefaultDeleteHandler(context, input, output, deleter); deleteHandler.Delete(); Assert.AreEqual(0, deleter.Data.Count, "output should everthing too"); }
protected override void Load(ContainerBuilder builder) { if (_process == null) { return; } // Connections foreach (var c in _process.Connections.Where(cn => cn.Provider == "lucene")) { switch (c.Provider) { case "lucene": // Analyzers builder.Register <Analyzer>(ctx => new KeywordAnalyzer()).Named <Analyzer>(DefaultAnalyzer); foreach (var analyzer in _process.SearchTypes.Where(st => st.Analyzer != string.Empty && st.Analyzer != DefaultAnalyzer).Select(st => st.Analyzer).Distinct()) { switch (analyzer) { case "simple": builder.Register <Analyzer>(ctx => new SimpleAnalyzer()).Named <Analyzer>(analyzer); break; case "whitespace": builder.Register <Analyzer>(ctx => new WhitespaceAnalyzer()).Named <Analyzer>(analyzer); break; case "standard": builder.Register <Analyzer>(ctx => new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)).Named <Analyzer>(analyzer); break; default: builder.Register <Analyzer>(ctx => new KeywordAnalyzer()).Named <Analyzer>(analyzer); break; } } // entity index writers foreach (var e in _process.Entities) { // Directory builder.Register(ctx => new DirectoryFactory(Path.Combine(c.Folder, e.Alias))).Named <DirectoryFactory>(e.Key); // Per Field Analyzer builder.Register <Analyzer>(ctx => { var analyzers = new PerFieldAnalyzerWrapper(ctx.ResolveNamed <Analyzer>(DefaultAnalyzer)); var context = ctx.ResolveNamed <OutputContext>(e.Key); foreach (var field in new FieldSearchTypes(context.Process, context.OutputFields)) { if (field.SearchType.Name != "none") { analyzers.AddAnalyzer(field.Alias, ctx.ResolveNamed <Analyzer>(field.SearchType.Analyzer == string.Empty ? DefaultAnalyzer : field.SearchType.Analyzer)); } } return(analyzers); }).Named <Analyzer>(e.Key + ReadFrom.Output); builder.Register <Analyzer>(ctx => { var analyzers = new PerFieldAnalyzerWrapper(ctx.ResolveNamed <Analyzer>(DefaultAnalyzer)); var context = ctx.ResolveNamed <InputContext>(e.Key); foreach (var field in new FieldSearchTypes(context.Process, context.InputFields)) { if (field.SearchType.Name != "none") { analyzers.AddAnalyzer(field.Field.Name, ctx.ResolveNamed <Analyzer>(field.SearchType.Analyzer == string.Empty ? DefaultAnalyzer : field.SearchType.Analyzer)); } } return(analyzers); }).Named <Analyzer>(e.Key + ReadFrom.Input); // Index Writer Factory builder.Register(ctx => new IndexWriterFactory(ctx.ResolveNamed <DirectoryFactory>(e.Key), ctx.ResolveNamed <Analyzer>(e.Key + ReadFrom.Output))).Named <IndexWriterFactory>(e.Key); // Index Reader Factory builder.Register(ctx => new IndexReaderFactory(ctx.ResolveNamed <DirectoryFactory>(e.Key), ctx.ResolveNamed <IndexWriterFactory>(e.Key))).Named <IndexReaderFactory>(e.Key); // Index Searcher Factory builder.Register(ctx => new SearcherFactory(ctx.ResolveNamed <IndexReaderFactory>(e.Key))).Named <SearcherFactory>(e.Key); } break; } } // entity input foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Connection).Provider == "lucene")) { // INPUT VERSION DETECTOR builder.Register <IInputVersionDetector>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); switch (input.Connection.Provider) { case "lucene": return(new LuceneInputVersionDetector(input, ctx.ResolveNamed <SearcherFactory>(entity.Key))); default: return(new NullVersionDetector()); } }).Named <IInputVersionDetector>(entity.Key); // INPUT READER builder.Register <IRead>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); switch (input.Connection.Provider) { case "lucene": return(new LuceneReader(input, input.InputFields, ctx.ResolveNamed <SearcherFactory>(entity.Key), ctx.ResolveNamed <Analyzer>(entity.Key + ReadFrom.Input), ctx.ResolveNamed <IndexReaderFactory>(entity.Key), rowFactory, ReadFrom.Input)); default: return(new NullReader(input, false)); } }).Named <IRead>(entity.Key); } // entity output if (_process.Output().Provider == "lucene") { // PROCESS OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>(); // PROCESS INITIALIZER builder.Register <IInitializer>(ctx => { var output = ctx.Resolve <OutputContext>(); return(new LuceneInitializer(output)); }).As <IInitializer>(); foreach (var entity in _process.Entities) { // UPDATER builder.Register <IUpdate>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); output.Warn($"{output.Connection.Provider} does not denormalize."); return(new NullMasterUpdater()); }).Named <IUpdate>(entity.Key); // OUTPUT builder.Register <IOutputController>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "lucene": return(new LuceneOutputController( output, new NullInitializer(), ctx.ResolveNamed <IInputVersionDetector>(entity.Key), new LuceneOutputVersionDetector(output, ctx.ResolveNamed <SearcherFactory>(entity.Key)), ctx.ResolveNamed <SearcherFactory>(entity.Key), ctx.ResolveNamed <IndexReaderFactory>(entity.Key) )); default: return(new NullOutputController()); } }).Named <IOutputController>(entity.Key); // WRITER builder.Register <IWrite>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "lucene": return(new LuceneWriter(output, ctx.ResolveNamed <IndexWriterFactory>(entity.Key), ctx.ResolveNamed <SearcherFactory>(entity.Key))); default: return(new NullWriter(output)); } }).Named <IWrite>(entity.Key); // DELETE HANDLER if (entity.Delete) { builder.Register <IEntityDeleteHandler>(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); var inputContext = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", inputContext.RowCapacity)); IRead input = new NullReader(context); var primaryKey = entity.GetPrimaryKey(); switch (inputContext.Connection.Provider) { case "lucene": input = new LuceneReader( inputContext, primaryKey, ctx.ResolveNamed <SearcherFactory>(entity.Key), ctx.ResolveNamed <Analyzer>(entity.Key + ReadFrom.Input), ctx.ResolveNamed <IndexReaderFactory>(entity.Key), rowFactory, ReadFrom.Input); break; } IRead output = new NullReader(context); IDelete deleter = new NullDeleter(context); var outputConnection = _process.Output(); var outputContext = ctx.ResolveNamed <OutputContext>(entity.Key); switch (outputConnection.Provider) { case "lucene": output = new LuceneReader( outputContext, primaryKey, ctx.ResolveNamed <SearcherFactory>(entity.Key), ctx.ResolveNamed <Analyzer>(entity.Key + ReadFrom.Output), ctx.ResolveNamed <IndexReaderFactory>(entity.Key), rowFactory, ReadFrom.Output ); //TODO: need LuceneUpdater (update TflDeleted to true) break; } var handler = new DefaultDeleteHandler(context, input, output, deleter); // since the primary keys from the input may have been transformed into the output, you have to transform before comparing // feels a lot like entity pipeline on just the primary keys... may look at consolidating handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray())); handler.Register(TransformFactory.GetTransforms(ctx, _process, entity, primaryKey)); handler.Register(new StringTruncateTransfom(context, primaryKey)); return(new ParallelDeleteHandler(handler)); }).Named <IEntityDeleteHandler>(entity.Key); } } } }
protected override void Load(ContainerBuilder builder) { if (_process == null) { return; } //CONNECTIONS foreach (var connection in _process.Connections.Where(c => c.Provider.In("elasticsearch"))) { connection.Url = connection.BuildElasticUrl(); builder.Register <IConnectionPool>(ctx => new SingleNodeConnectionPool(new Uri(connection.Url))).Named <IConnectionPool>(connection.Key); // Elasticsearch.Net builder.Register(ctx => { var settings = new ConnectionConfiguration(ctx.ResolveNamed <IConnectionPool>(connection.Key)); if (_process.Mode != "init" && connection.RequestTimeout >= 0) { settings.RequestTimeout(new TimeSpan(0, 0, 0, connection.RequestTimeout * 1000)); } if (connection.Timeout > 0) { settings.PingTimeout(new TimeSpan(0, 0, connection.Timeout)); } return(new ElasticLowLevelClient(settings)); }).Named <IElasticLowLevelClient>(connection.Key); // Process-Level Schema Reader builder.Register <ISchemaReader>(ctx => new ElasticSchemaReader(ctx.ResolveNamed <IConnectionContext>(connection.Key), ctx.ResolveNamed <IElasticLowLevelClient>(connection.Key))).Named <ISchemaReader>(connection.Key); // Entity Level Schema Readers foreach (var entity in _process.Entities.Where(e => e.Connection == connection.Name)) { builder.Register <ISchemaReader>(ctx => new ElasticSchemaReader(ctx.ResolveNamed <IConnectionContext>(entity.Key), ctx.ResolveNamed <IElasticLowLevelClient>(connection.Key))).Named <ISchemaReader>(entity.Key); } } // Entity Input foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Connection).Provider == "elasticsearch")) { builder.Register <IInputVersionDetector>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); switch (input.Connection.Provider) { case "elasticsearch": return(new ElasticInputVersionDetector(input, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key))); default: return(new NullVersionDetector()); } }).Named <IInputVersionDetector>(entity.Key); // INPUT READER builder.Register <IRead>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); switch (input.Connection.Provider) { case "elasticsearch": return(new ElasticReader(input, input.InputFields, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key), rowFactory, ReadFrom.Input)); default: return(new NullReader(input, false)); } }).Named <IRead>(entity.Key); } // Entity Output if (_process.Output().Provider == "elasticsearch") { // PROCESS OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>(); // PROCESS INITIALIZER builder.Register <IInitializer>(ctx => { var output = ctx.Resolve <OutputContext>(); return(new ElasticInitializer(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key))); }).As <IInitializer>(); foreach (var entity in _process.Entities) { // UPDATER builder.Register <IUpdate>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); output.Warn($"{output.Connection.Provider} does not denormalize."); return(new NullMasterUpdater()); }).Named <IUpdate>(entity.Key); // OUTPUT builder.Register <IOutputController>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "elasticsearch": var initializer = _process.Mode == "init" ? (IAction) new ElasticEntityInitializer(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)) : new NullInitializer(); return(new ElasticOutputController( output, initializer, ctx.ResolveNamed <IInputVersionDetector>(entity.Key), new ElasticOutputVersionDetector(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)), ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key) )); default: return(new NullOutputController()); } }).Named <IOutputController>(entity.Key); // WRITER builder.Register <IWrite>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "elasticsearch": return(new ElasticWriter(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key))); default: return(new NullWriter(output)); } }).Named <IWrite>(entity.Key); // DELETE HANDLER if (entity.Delete) { builder.Register <IEntityDeleteHandler>(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); var inputContext = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", inputContext.RowCapacity)); IRead input = new NullReader(context); var primaryKey = entity.GetPrimaryKey(); switch (inputContext.Connection.Provider) { case "elasticsearch": input = new ElasticReader( inputContext, primaryKey, ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key), rowFactory, ReadFrom.Input ); break; } IRead output = new NullReader(context); IDelete deleter = new NullDeleter(context); var outputConnection = _process.Output(); var outputContext = ctx.ResolveNamed <OutputContext>(entity.Key); switch (outputConnection.Provider) { case "elasticsearch": output = new ElasticReader( outputContext, primaryKey, ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key), rowFactory, ReadFrom.Output ); deleter = new ElasticPartialUpdater( outputContext, new[] { context.Entity.TflDeleted() }, ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key) ); break; } var handler = new DefaultDeleteHandler(context, input, output, deleter); // since the primary keys from the input may have been transformed into the output, you have to transform before comparing // feels a lot like entity pipeline on just the primary keys... may look at consolidating handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray())); handler.Register(TransformFactory.GetTransforms(ctx, _process, entity, primaryKey)); handler.Register(new StringTruncateTransfom(context, primaryKey)); return(new ParallelDeleteHandler(handler)); }).Named <IEntityDeleteHandler>(entity.Key); } } } }
public void Build() { //MAPS foreach (var map in _process.Maps.Where(m => m.Connection != string.Empty && m.Query != string.Empty)) { var connection = _process.Connections.First(c => c.Name == map.Connection); if (connection != null && connection.Provider == "elasticsearch") { _builder.Register <IMapReader>(ctx => new DefaultMapReader()).Named <IMapReader>(map.Name); } } //CONNECTIONS foreach (var connection in _process.Connections.Where(c => c.Provider == "elasticsearch")) { if (connection.Servers.Any(s => s.Url != "None")) { var uris = new List <Uri>(); foreach (var server in connection.Servers.Where(s => s.Url != "None")) { server.Url = server.GetElasticUrl(); uris.Add(new Uri(server.Url)); } // for now, just use static connection pool, there are 2 other types... _builder.Register <IConnectionPool>(ctx => new StaticConnectionPool(uris)).Named <IConnectionPool>(connection.Key); } else { connection.Url = connection.GetElasticUrl(); _builder.Register <IConnectionPool>(ctx => new SingleNodeConnectionPool(new Uri(connection.Url))).Named <IConnectionPool>(connection.Key); } // Elasticsearch.Net _builder.Register(ctx => { var settings = new ConnectionConfiguration(ctx.ResolveNamed <IConnectionPool>(connection.Key)); if (!string.IsNullOrEmpty(connection.User)) { settings.BasicAuthentication(connection.User, connection.Password); } if (_process.Mode != "init" && connection.RequestTimeout >= 0) { settings.RequestTimeout(new TimeSpan(0, 0, 0, connection.RequestTimeout * 1000)); } if (connection.Timeout > 0) { settings.PingTimeout(new TimeSpan(0, 0, connection.Timeout)); } return(new ElasticLowLevelClient(settings)); }).Named <IElasticLowLevelClient>(connection.Key); // Process-Level Schema Reader _builder.Register <ISchemaReader>(ctx => new ElasticSchemaReader(ctx.ResolveNamed <IConnectionContext>(connection.Key), ctx.ResolveNamed <IElasticLowLevelClient>(connection.Key))).Named <ISchemaReader>(connection.Key); // Entity Level Schema Readers foreach (var entity in _process.Entities.Where(e => e.Input == connection.Name)) { _builder.Register <ISchemaReader>(ctx => new ElasticSchemaReader(ctx.ResolveNamed <IConnectionContext>(entity.Key), ctx.ResolveNamed <IElasticLowLevelClient>(connection.Key))).Named <ISchemaReader>(entity.Key); } } // Entity Input foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Input).Provider == "elasticsearch")) { _builder.Register <IInputProvider>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); return(new ElasticInputProvider(input, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key))); }).Named <IInputProvider>(entity.Key); // INPUT READER _builder.Register <IRead>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); if (entity.Query == string.Empty) { return(new ElasticReader(input, input.InputFields, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key), rowFactory, ReadFrom.Input)); } return(new ElasticQueryReader(input, ctx.ResolveNamed <IElasticLowLevelClient>(input.Connection.Key), rowFactory)); }).Named <IRead>(entity.Key); } // Entity Output if (_process.GetOutputConnection().Provider == "elasticsearch") { // PROCESS OUTPUT CONTROLLER _builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>(); // PROCESS INITIALIZER _builder.Register <IInitializer>(ctx => { var output = ctx.Resolve <OutputContext>(); return(new ElasticInitializer(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key))); }).As <IInitializer>(); foreach (var entity in _process.Entities) { // UPDATER _builder.Register <IUpdate>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); output.Debug(() => $"{output.Connection.Provider} does not denormalize."); return(new NullMasterUpdater()); }).Named <IUpdate>(entity.Key); // OUTPUT _builder.Register <IOutputController>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "elasticsearch": var initializer = _process.Mode == "init" ? (IAction) new ElasticEntityInitializer(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)) : new NullInitializer(); return(new ElasticOutputController( output, initializer, ctx.ResolveNamed <IInputProvider>(entity.Key), new ElasticOutputProvider(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key)), ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key) )); default: return(new NullOutputController()); } }).Named <IOutputController>(entity.Key); // WRITER _builder.Register <IWrite>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "elasticsearch": return(new ElasticWriter(output, ctx.ResolveNamed <IElasticLowLevelClient>(output.Connection.Key))); default: return(new NullWriter(output)); } }).Named <IWrite>(entity.Key); // DELETE HANDLER if (entity.Delete) { _builder.Register <IEntityDeleteHandler>(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); var inputContext = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", inputContext.RowCapacity)); IRead input = new NullReader(context); var primaryKey = entity.GetPrimaryKey(); switch (inputContext.Connection.Provider) { case "elasticsearch": input = new ElasticReader( inputContext, primaryKey, ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key), rowFactory, ReadFrom.Input ); break; } IRead output = new NullReader(context); IDelete deleter = new NullDeleter(context); var outputConnection = _process.GetOutputConnection(); var outputContext = ctx.ResolveNamed <OutputContext>(entity.Key); switch (outputConnection.Provider) { case "elasticsearch": output = new ElasticReader( outputContext, primaryKey, ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key), rowFactory, ReadFrom.Output ); deleter = new ElasticPartialUpdater( outputContext, new[] { context.Entity.TflDeleted() }, ctx.ResolveNamed <IElasticLowLevelClient>(inputContext.Connection.Key) ); break; } var handler = new DefaultDeleteHandler(context, input, output, deleter); // since the primary keys from the input may have been transformed into the output, you have to transform before comparing // feels a lot like entity pipeline on just the primary keys... may look at consolidating handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray())); handler.Register(TransformFactory.GetTransforms(ctx, context, primaryKey)); handler.Register(new StringTruncateTransfom(context, primaryKey)); return(handler); }).Named <IEntityDeleteHandler>(entity.Key); } } } }
protected override void Load(ContainerBuilder builder) { if (_process == null) { return; } // connections foreach (var connection in _process.Connections.Where(c => c.Provider.In(_ado))) { // Connection Factory builder.Register <IConnectionFactory>(ctx => { switch (connection.Provider) { case "sqlserver": return(new SqlServerConnectionFactory(connection)); case "mysql": return(new MySqlConnectionFactory(connection)); case "postgresql": return(new PostgreSqlConnectionFactory(connection)); case "sqlite": return(new SqLiteConnectionFactory(connection)); default: return(new NullConnectionFactory()); } }).Named <IConnectionFactory>(connection.Key).InstancePerLifetimeScope(); // Schema Reader builder.Register <ISchemaReader>(ctx => { var factory = ctx.ResolveNamed <IConnectionFactory>(connection.Key); return(new AdoSchemaReader(ctx.ResolveNamed <IConnectionContext>(connection.Key), factory)); }).Named <ISchemaReader>(connection.Key); } //ISchemaReader //IOutputController //IRead (Process for Calculated Columns) //IWrite (Process for Calculated Columns) //IInitializer (Process) // Per Entity // IInputVersionDetector // IRead (Input, per Entity) // IOutputController // -- ITakeAndReturnRows (for matching) // -- IWriteMasterUpdateQuery (for updating) // IUpdate // IWrite // IEntityDeleteHandler // entitiy input foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Connection).Provider.In(_ado))) { // INPUT READER builder.Register <IRead>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); switch (input.Connection.Provider) { case "mysql": case "postgresql": case "sqlite": case "sqlserver": return(new AdoInputReader( input, input.InputFields, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key), rowFactory )); default: return(new NullReader(input, false)); } }).Named <IRead>(entity.Key); // INPUT VERSION DETECTOR builder.Register <IInputVersionDetector>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); switch (input.Connection.Provider) { case "mysql": case "postgresql": case "sqlite": case "sqlserver": return(new AdoInputVersionDetector(input, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key))); default: return(new NullVersionDetector()); } }).Named <IInputVersionDetector>(entity.Key); } // entity output if (_process.Output().Provider.In(_ado)) { var calc = _process.ToCalculatedFieldsProcess(); // PROCESS OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.Resolve <OutputContext>(); if (_process.Mode != "init") { return(new NullOutputController()); } switch (output.Connection.Provider) { case "mysql": case "postgresql": case "sqlite": case "sqlserver": return(new AdoStarController(output, new AdoStarViewCreator(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)))); default: return(new NullOutputController()); } }).As <IOutputController>(); // PROCESS CALCULATED READER builder.Register <IRead>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext, new Incrementer(calcContext)); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); var capacity = outputContext.Entity.Fields.Count + outputContext.Entity.CalculatedFields.Count; var rowFactory = new RowFactory(capacity, false, false); return(new AdoStarParametersReader(outputContext, _process, cf, rowFactory)); }).As <IRead>(); // PROCESS CALCULATED FIELD WRITER builder.Register <IWrite>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext, new Incrementer(calcContext)); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); return(new AdoCalculatedFieldUpdater(outputContext, _process, cf)); }).As <IWrite>(); // PROCESS INITIALIZER builder.Register <IInitializer>(ctx => { var output = ctx.Resolve <OutputContext>(); return(new AdoInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key))); }).As <IInitializer>(); // ENTITIES foreach (var entity in _process.Entities) { // ENTITY OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "mysql": case "postgresql": case "sqlite": case "sqlserver": var initializer = _process.Mode == "init" ? (IAction) new AdoEntityInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) : new NullInitializer(); return(new AdoOutputController( output, initializer, ctx.ResolveNamed <IInputVersionDetector>(entity.Key), new AdoOutputVersionDetector(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)), ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key) )); default: return(new NullOutputController()); } }).Named <IOutputController>(entity.Key); // OUTPUT ROW MATCHER builder.Register(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", output.GetAllEntityFields().Count())); var cf = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); switch (output.Connection.Provider) { case "sqlite": return(new TypedEntityMatchingKeysReader(new AdoEntityMatchingKeysReader(output, cf, rowFactory), output)); default: return((ITakeAndReturnRows) new AdoEntityMatchingKeysReader(output, cf, rowFactory)); } }).Named <ITakeAndReturnRows>(entity.Key); // MASTER UPDATE QUERY builder.Register <IWriteMasterUpdateQuery>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var factory = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); switch (output.Connection.Provider) { case "mysql": return(new MySqlUpdateMasterKeysQueryWriter(output, factory)); case "postgresql": return(new PostgreSqlUpdateMasterKeysQueryWriter(output, factory)); default: return(new SqlServerUpdateMasterKeysQueryWriter(output, factory)); } }).Named <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys"); // UPDATER builder.Register <IUpdate>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "mysql": case "postgresql": case "sqlserver": return(new AdoMasterUpdater( output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key), ctx.ResolveNamed <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys") )); case "sqlite": return(new AdoTwoPartMasterUpdater(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key))); default: return(new NullMasterUpdater()); } }).Named <IUpdate>(entity.Key); // WRITER builder.Register <IWrite>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "sqlserver": return(new SqlServerWriter( output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key), ctx.ResolveNamed <ITakeAndReturnRows>(entity.Key), new AdoEntityUpdater(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) )); case "mysql": case "postgresql": case "sqlite": var cf = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); return(new AdoEntityWriter( output, ctx.ResolveNamed <ITakeAndReturnRows>(entity.Key), new AdoEntityInserter(output, cf), new AdoEntityUpdater(output, cf) )); default: return(new NullWriter(output)); } }).Named <IWrite>(entity.Key); // DELETE HANDLER if (entity.Delete) { builder.Register <IEntityDeleteHandler>(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); var inputContext = ctx.ResolveNamed <InputContext>(entity.Key); var rowCapacity = inputContext.Entity.GetPrimaryKey().Count(); var rowFactory = new RowFactory(rowCapacity, false, true); IRead input = new NullReader(context); var primaryKey = entity.GetPrimaryKey(); switch (inputContext.Connection.Provider) { case "mysql": case "postgresql": case "sqlite": case "sqlserver": input = new AdoReader( inputContext, primaryKey, ctx.ResolveNamed <IConnectionFactory>(inputContext.Connection.Key), rowFactory, ReadFrom.Input ); break; } IRead output = new NullReader(context); IDelete deleter = new NullDeleter(context); var outputConnection = _process.Output(); var outputContext = ctx.ResolveNamed <OutputContext>(entity.Key); switch (outputConnection.Provider) { case "mysql": case "postgresql": case "sqlite": case "sqlserver": var ocf = ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key); output = new AdoReader(context, entity.GetPrimaryKey(), ocf, rowFactory, ReadFrom.Output); deleter = new AdoDeleter(outputContext, ocf); break; } var handler = new DefaultDeleteHandler(context, input, output, deleter); // since the primary keys from the input may have been transformed into the output, you have to transform before comparing // feels a lot like entity pipeline on just the primary keys... may look at consolidating handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray())); handler.Register(TransformFactory.GetTransforms(ctx, _process, entity, primaryKey)); handler.Register(new StringTruncateTransfom(context, primaryKey)); return(new ParallelDeleteHandler(handler)); }).Named <IEntityDeleteHandler>(entity.Key); } } } }
protected override void Load(ContainerBuilder builder) { if (_process == null) { return; } // connections foreach (var connection in _process.Connections.Where(c => _ado.Contains(c.Provider))) { var cn = connection; // Connection Factory builder.Register <IConnectionFactory>(ctx => { switch (cn.Provider) { case "sqlserver": return(new SqlServerConnectionFactory(cn)); default: return(new NullConnectionFactory()); } }).Named <IConnectionFactory>(connection.Key).InstancePerLifetimeScope(); // Schema Reader builder.Register <ISchemaReader>(ctx => { var factory = ctx.ResolveNamed <IConnectionFactory>(cn.Key); return(new AdoSchemaReader(ctx.ResolveNamed <IConnectionContext>(cn.Key), factory)); }).Named <ISchemaReader>(connection.Key); } //ISchemaReader //IOutputController //IRead (Process for Calculated Columns) //IWrite (Process for Calculated Columns) //IInitializer (Process) // Per Entity // IInputVersionDetector // IRead (Input, per Entity) // IOutputController // -- IBatchReader (for matching) // -- IWriteMasterUpdateQuery (for updating) // IUpdate // IWrite // IEntityDeleteHandler // entitiy input foreach (var entity in _process.Entities.Where(e => _ado.Contains(_process.Connections.First(c => c.Name == e.Connection).Provider))) { // INPUT READER builder.Register(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); IRead dataReader; switch (input.Connection.Provider) { case "mysql": case "sqlserver": dataReader = new AdoInputReader( input, input.InputFields, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key), rowFactory ); break; default: dataReader = new NullReader(input, false); break; } // "form" mode support if filter on primary key exists if (_process.Mode == "form" && entity.GetPrimaryKey().Any() && entity.GetPrimaryKey().All(f => entity.Filter.Any(i => i.Field == f.Alias || i.Field == f.Name))) { if (entity.GetPrimaryKey().All(pk => entity.Filter.First(i => i.Field == pk.Alias || i.Field == pk.Name).Value == (pk.Default == Constants.DefaultSetting ? Constants.StringDefaults()[pk.Type] : pk.Default))) { // primary key is default, don't read from database return(new ParameterRowReader(input, new DefaultRowReader(input, rowFactory))); } // read from database and update with parameters, otherwise just return the data reader if (HttpContext.Current.Request.HttpMethod == "POST") { return(new ParameterRowReader(input, dataReader, rowFactory)); } } return(dataReader); }).Named <IRead>(entity.Key); // INPUT VERSION DETECTOR builder.Register <IInputProvider>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); switch (input.Connection.Provider) { case "mysql": case "sqlserver": return(new AdoInputProvider(input, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key))); default: return(new NullInputProvider()); } }).Named <IInputProvider>(entity.Key); } // entity output if (_ado.Contains(_process.Output().Provider)) { var calc = _process.ToCalculatedFieldsProcess(); // PROCESS OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.Resolve <OutputContext>(); if (_process.Mode != "init") { return(new NullOutputController()); } switch (output.Connection.Provider) { case "mysql": case "sqlserver": var actions = new List <IAction> { new AdoStarViewCreator(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) }; if (_process.Flatten) { actions.Add(new AdoFlatTableCreator(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key))); } return(new AdoStarController(output, actions)); default: return(new NullOutputController()); } }).As <IOutputController>(); // PROCESS CALCULATED READER builder.Register <IRead>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); var capacity = outputContext.Entity.Fields.Count + outputContext.Entity.CalculatedFields.Count; var rowFactory = new RowFactory(capacity, false, false); return(new AdoStarParametersReader(outputContext, _process, cf, rowFactory)); }).As <IRead>(); // PROCESS CALCULATED FIELD WRITER builder.Register <IWrite>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); return(new AdoCalculatedFieldUpdater(outputContext, _process, cf)); }).As <IWrite>(); // PROCESS INITIALIZER builder.Register <IInitializer>(ctx => { var output = ctx.Resolve <OutputContext>(); return(new AdoInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key))); }).As <IInitializer>(); // ENTITIES foreach (var e in _process.Entities) { var entity = e; // WRITER builder.Register <IWrite>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var cf = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); switch (output.Connection.Provider) { case "sqlserver": return(new SqlServerWriter( output, cf, ctx.ResolveNamed <IBatchReader>(entity.Key), new AdoEntityUpdater(output, cf) )); case "mysql": return(new AdoEntityWriter( output, ctx.ResolveNamed <IBatchReader>(entity.Key), new AdoEntityInserter(output, cf), entity.Update ? (IWrite) new AdoEntityUpdater(output, cf) : new NullWriter(output) )); default: return(new NullWriter(output)); } }).Named <IWrite>(entity.Key); builder.Register <IOutputProvider>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); return(new AdoOutputProvider(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key), ctx.ResolveNamed <IWrite>(entity.Key))); }).Named <IOutputProvider>(entity.Key); // ENTITY OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "mysql": case "sqlserver": var initializer = _process.Mode == "init" ? (IAction) new AdoEntityInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) : new NullInitializer(); return(new AdoOutputController( output, initializer, ctx.ResolveNamed <IInputProvider>(entity.Key), ctx.ResolveNamed <IOutputProvider>(entity.Key), ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key) )); default: return(new NullOutputController()); } }).Named <IOutputController>(entity.Key); // OUTPUT ROW MATCHER builder.Register <IBatchReader>(ctx => { if (!entity.Update) { return(new NullBatchReader()); } var output = ctx.ResolveNamed <OutputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", output.GetAllEntityFields().Count())); var cf = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); return(new AdoEntityMatchingKeysReader(output, cf, rowFactory)); }).Named <IBatchReader>(entity.Key); // MASTER UPDATE QUERY builder.Register <IWriteMasterUpdateQuery>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var factory = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); return(new SqlServerUpdateMasterKeysQueryWriter(output, factory)); }).Named <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys"); // MASTER UPDATER builder.Register <IUpdate>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "mysql": case "postgresql": case "sqlserver": return(new AdoMasterUpdater( output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key), ctx.ResolveNamed <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys") )); case "sqlite": case "sqlce": return(new AdoTwoPartMasterUpdater(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key))); default: return(new NullMasterUpdater()); } }).Named <IUpdate>(entity.Key); // DELETE HANDLER if (entity.Delete) { // register input keys and hashcode reader if necessary var provider = _process.Connections.First(c => c.Name == entity.Connection).Provider; if (_ado.Contains(provider)) { builder.Register <IReadInputKeysAndHashCodes>(ctx => { var inputContext = ctx.ResolveNamed <InputContext>(entity.Key); var rowCapacity = inputContext.Entity.GetPrimaryKey().Count(); var rowFactory = new RowFactory(rowCapacity, false, true); return(new AdoReader( inputContext, entity.GetPrimaryKey(), ctx.ResolveNamed <IConnectionFactory>(inputContext.Connection.Key), rowFactory, ReadFrom.Input )); }).Named <IReadInputKeysAndHashCodes>(entity.Key); } // register output keys and hash code reader if necessary builder.Register <IReadOutputKeysAndHashCodes>((ctx => { var context = ctx.ResolveNamed <OutputContext>(entity.Key); var rowCapacity = context.Entity.GetPrimaryKey().Count(); var rowFactory = new RowFactory(rowCapacity, false, true); var outputConnection = _process.Output(); switch (outputConnection.Provider) { case "mysql": case "sqlserver": var ocf = ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key); return(new AdoReader(context, entity.GetPrimaryKey(), ocf, rowFactory, ReadFrom.Output)); default: return(new NullReader(context)); } })).Named <IReadOutputKeysAndHashCodes>(entity.Key); builder.Register((ctx) => { var outputConnection = _process.Output(); var outputContext = ctx.ResolveNamed <OutputContext>(entity.Key); switch (outputConnection.Provider) { case "mysql": case "sqlserver": var ocf = ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key); return(new AdoDeleter(outputContext, ocf)); default: return(ctx.IsRegisteredWithName <IDelete>(entity.Key) ? ctx.ResolveNamed <IDelete>(entity.Key) : new NullDeleter(outputContext)); } }).Named <IDelete>(entity.Key); builder.Register <IEntityDeleteHandler>(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); var primaryKey = entity.GetPrimaryKey().ToArray(); var handler = new DefaultDeleteHandler( context, ctx.ResolveNamed <IReadInputKeysAndHashCodes>(entity.Key), ctx.ResolveNamed <IReadOutputKeysAndHashCodes>(entity.Key), ctx.ResolveNamed <IDelete>(entity.Key) ); // since the primary keys from the input may have been transformed into the output, you have to transform before comparing // feels a lot like entity pipeline on just the primary keys... may look at consolidating handler.Register(new DefaultTransform(context, primaryKey)); handler.Register(TransformFactory.GetTransforms(ctx, context, primaryKey)); handler.Register(new StringTruncateTransfom(context, primaryKey)); return(new ParallelDeleteHandler(handler)); }).Named <IEntityDeleteHandler>(entity.Key); } } } }
protected override void Load(ContainerBuilder builder) { if (!builder.Properties.ContainsKey("Process")) { return; } var process = (Process)builder.Properties["Process"]; // connections foreach (var connection in process.Connections.Where(c => c.Provider == Access)) { // Connection Factory builder.Register <IConnectionFactory>(ctx => { switch (connection.Provider) { case "access": return(new AccessConnectionFactory(connection)); default: return(new NullConnectionFactory()); } }).Named <IConnectionFactory>(connection.Key).InstancePerLifetimeScope(); // Schema Reader builder.Register <ISchemaReader>(ctx => { var factory = ctx.ResolveNamed <IConnectionFactory>(connection.Key); return(new AdoSchemaReader(ctx.ResolveNamed <IConnectionContext>(connection.Key), factory)); }).Named <ISchemaReader>(connection.Key); } // entity input foreach (var entity in process.Entities.Where(e => process.Connections.First(c => c.Name == e.Input).Provider == Access)) { // INPUT READER builder.Register <IRead>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity)); switch (input.Connection.Provider) { case "access": return(new AdoInputReader( input, input.InputFields, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key), rowFactory )); default: return(new NullReader(input, false)); } }).Named <IRead>(entity.Key); // INPUT VERSION DETECTOR builder.Register <IInputProvider>(ctx => { var input = ctx.ResolveNamed <InputContext>(entity.Key); switch (input.Connection.Provider) { case "access": return(new AdoInputProvider(input, ctx.ResolveNamed <IConnectionFactory>(input.Connection.Key))); default: return(new NullInputProvider()); } }).Named <IInputProvider>(entity.Key); } // entity output if (process.GetOutputConnection().Provider == Access) { var calc = process.ToCalculatedFieldsProcess(); // PROCESS OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.Resolve <OutputContext>(); if (process.Mode != "init") { return(new NullOutputController()); } switch (output.Connection.Provider) { case "access": var actions = new List <IAction> { new AdoStarViewCreator(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) }; if (process.Flatten) { actions.Add(new AdoFlatTableCreator(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key))); } return(new AdoStarController(output, actions)); default: return(new NullOutputController()); } }).As <IOutputController>(); // PROCESS CALCULATED READER builder.Register <IRead>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); var capacity = outputContext.Entity.Fields.Count + outputContext.Entity.CalculatedFields.Count; var rowFactory = new RowFactory(capacity, false, false); return(new AdoStarParametersReader(outputContext, process, cf, rowFactory)); }).As <IRead>(); // PROCESS CALCULATED FIELD WRITER builder.Register <IWrite>(ctx => { var calcContext = new PipelineContext(ctx.Resolve <IPipelineLogger>(), calc, calc.Entities.First()); var outputContext = new OutputContext(calcContext); var cf = ctx.ResolveNamed <IConnectionFactory>(outputContext.Connection.Key); return(new AdoCalculatedFieldUpdater(outputContext, process, cf)); }).As <IWrite>(); // PROCESS INITIALIZER builder.Register <IInitializer>(ctx => { var output = ctx.Resolve <OutputContext>(); var adoInit = new AdoInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)); switch (output.Connection.Provider) { case "access": return(new AccessInitializer(adoInit, output)); default: return(adoInit); } }).As <IInitializer>(); // ENTITIES foreach (var entity in process.Entities) { builder.Register <IOutputProvider>(ctx => { IWrite writer; var output = ctx.ResolveNamed <OutputContext>(entity.Key); var cf = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", output.GetAllEntityFields().Count())); // matcher determines what's an update vs. and insert var matcher = entity.Update ? (IBatchReader) new AdoEntityMatchingKeysReader(output, cf, rowFactory) : new NullBatchReader(); switch (output.Connection.Provider) { case "access": writer = new AdoEntityWriter( output, matcher, new AdoEntityInserter(output, cf), entity.Update ? (IWrite) new AdoEntityUpdater(output, cf) : new NullWriter(output) ); break; default: writer = new NullWriter(output); break; } return(new AdoOutputProvider(output, cf, writer)); }).Named <IOutputProvider>(entity.Key); // ENTITY OUTPUT CONTROLLER builder.Register <IOutputController>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var initializer = process.Mode == "init" ? (IAction) new AdoEntityInitializer(output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key)) : new NullInitializer(); switch (output.Connection.Provider) { case "access": return(new AdoOutputController( output, new AccessInitializer(initializer, output), ctx.ResolveNamed <IInputProvider>(entity.Key), ctx.ResolveNamed <IOutputProvider>(entity.Key), ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key) )); default: return(new NullOutputController()); } }).Named <IOutputController>(entity.Key); // MASTER UPDATE QUERY builder.Register <IWriteMasterUpdateQuery>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); var factory = ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key); return(new AccessUpdateMasterKeysQueryWriter(output, factory)); }).Named <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys"); // MASTER UPDATER builder.Register <IUpdate>(ctx => { var output = ctx.ResolveNamed <OutputContext>(entity.Key); switch (output.Connection.Provider) { case "access": return(new AdoMasterUpdater( output, ctx.ResolveNamed <IConnectionFactory>(output.Connection.Key), ctx.ResolveNamed <IWriteMasterUpdateQuery>(entity.Key + "MasterKeys") )); default: return(new NullMasterUpdater()); } }).Named <IUpdate>(entity.Key); // DELETE HANDLER if (entity.Delete) { // register input keys and hashcode reader if necessary builder.Register(ctx => { var inputContext = ctx.ResolveNamed <InputContext>(entity.Key); var rowCapacity = inputContext.Entity.GetPrimaryKey().Count(); var rowFactory = new RowFactory(rowCapacity, false, true); switch (inputContext.Connection.Provider) { case "access": return(new AdoReader( inputContext, entity.GetPrimaryKey(), ctx.ResolveNamed <IConnectionFactory>(inputContext.Connection.Key), rowFactory, ReadFrom.Input )); default: return(ctx.IsRegisteredWithName <IReadInputKeysAndHashCodes>(entity.Key) ? ctx.ResolveNamed <IReadInputKeysAndHashCodes>(entity.Key) : new NullReader(inputContext)); } }).Named <IReadInputKeysAndHashCodes>(entity.Key); // register output keys and hash code reader if necessary builder.Register((ctx => { var context = ctx.ResolveNamed <OutputContext>(entity.Key); var rowCapacity = context.Entity.GetPrimaryKey().Count(); var rowFactory = new RowFactory(rowCapacity, false, true); var outputConnection = process.GetOutputConnection(); switch (outputConnection.Provider) { case "access": var ocf = ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key); return(new AdoReader(context, entity.GetPrimaryKey(), ocf, rowFactory, ReadFrom.Output)); default: return(ctx.IsRegisteredWithName <IReadOutputKeysAndHashCodes>(entity.Key) ? ctx.ResolveNamed <IReadOutputKeysAndHashCodes>(entity.Key) : new NullReader(context)); } })).Named <IReadOutputKeysAndHashCodes>(entity.Key); builder.Register(ctx => { var outputConnection = process.GetOutputConnection(); var outputContext = ctx.ResolveNamed <OutputContext>(entity.Key); switch (outputConnection.Provider) { case "access": var ocf = ctx.ResolveNamed <IConnectionFactory>(outputConnection.Key); return(new AdoDeleter(outputContext, ocf)); default: return(ctx.IsRegisteredWithName <IDelete>(entity.Key) ? ctx.ResolveNamed <IDelete>(entity.Key) : new NullDeleter(outputContext)); } }).Named <IDelete>(entity.Key); builder.Register <IEntityDeleteHandler>(ctx => { var context = ctx.ResolveNamed <IContext>(entity.Key); var primaryKey = entity.GetPrimaryKey(); var handler = new DefaultDeleteHandler( context, ctx.ResolveNamed <IReadInputKeysAndHashCodes>(entity.Key), ctx.ResolveNamed <IReadOutputKeysAndHashCodes>(entity.Key), ctx.ResolveNamed <IDelete>(entity.Key) ); // since the primary keys from the input may have been transformed into the output, you have to transform before comparing // feels a lot like entity pipeline on just the primary keys... may look at consolidating handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray())); handler.Register(TransformFactory.GetTransforms(ctx, context, primaryKey)); handler.Register(new StringTruncateTransfom(context, primaryKey)); return(handler); }).Named <IEntityDeleteHandler>(entity.Key); } } } }