private void SetDestinationTableProperties() { DestinationTable.ConnectionManager = ConnectionManager; DestinationTable.TableName = TableName; DestinationTable.BatchSize = BatchSize; DestinationTable.MaxBufferSize = this.MaxBufferSize; DestinationTable.BeforeBatchWrite = batch => { if (MergeMode == MergeMode.Delta) { DeltaTable.AddRange(batch.Where(row => GetChangeAction(row) != ChangeAction.Delete)); } else if (MergeMode == MergeMode.OnlyUpdates) { DeltaTable.AddRange(batch.Where(row => GetChangeAction(row) == ChangeAction.Exists || GetChangeAction(row) == ChangeAction.Update)); } else { DeltaTable.AddRange(batch); } if (!UseTruncateMethod) { if (MergeMode == MergeMode.OnlyUpdates) { SqlDeleteIds(batch.Where(row => GetChangeAction(row) == ChangeAction.Update)); return(batch.Where(row => GetChangeAction(row) == ChangeAction.Update).ToArray()); } else { SqlDeleteIds(batch.Where(row => GetChangeAction(row) != ChangeAction.Insert && GetChangeAction(row) != ChangeAction.Exists)); return(batch.Where(row => GetChangeAction(row) == ChangeAction.Insert || GetChangeAction(row) == ChangeAction.Update) .ToArray()); } } else { if (MergeMode == MergeMode.Delta) { throw new ETLBoxNotSupportedException("If you provide a delta load, you must define at least one compare column." + "Using the truncate method is not allowed. "); } TruncateDestinationOnce(); if (MergeMode == MergeMode.OnlyUpdates) { return(batch.Where(row => GetChangeAction(row) != ChangeAction.Delete && GetChangeAction(row) != ChangeAction.Insert).ToArray()); } else { return(batch.Where(row => GetChangeAction(row) == ChangeAction.Insert || GetChangeAction(row) == ChangeAction.Update || GetChangeAction(row) == ChangeAction.Exists) .ToArray()); } } }; DestinationTable.OnCompletion = () => { IdentifyAndDeleteMissingEntries(); if (UseTruncateMethod && (MergeMode == MergeMode.OnlyUpdates || MergeMode == MergeMode.NoDeletions)) { ReinsertTruncatedRecords(); } if (Successors.Count > 0) { OutputSource.ExecuteAsync(); OutputSource.Completion.Wait(); //Careful: A TPL buffer never completes if it has no consumer linked to it!!! OutputSource.BufferCompletion.Wait(); } }; }
public async Task ExecuteAsync() => await OutputSource.ExecuteAsync();
public void ExecuteAsync() => OutputSource.ExecuteAsync();