Table of Contents

Class BaseDestinationWriter

Namespace
Dynamicweb.DataIntegration.Integration
Assembly
Dynamicweb.DataIntegration.dll

Placeholder base class for destination writers. A destination writer receives the converted rows for a table Mapping one at a time through Write(Dictionary<string, object>) and persists them to the destination.

public class BaseDestinationWriter : IDestinationWriter
Inheritance
BaseDestinationWriter
Implements
Derived
Inherited Members

Remarks

This class provides almost no functionality — apart from the static GetRowValueNotFoundMessage(Dictionary<string, object>, string?, string?) helper, every member throws NotImplementedException, and the members are non-virtual so they cannot be overridden. It is kept for backwards compatibility only. When building a custom destination provider, implement IDestinationWriter directly instead, or derive from BaseSqlWriter when writing to a SQL database.

If existing code derives from this class (as BaseSqlWriter and its writers do), it must hide the members with new implementations and re-declare IDestinationWriter on the derived class; otherwise calls made through the interface dispatch to the throwing base implementations.

Implementing a writer directly on the interface:
using Dynamicweb.DataIntegration.Integration;
using Dynamicweb.DataIntegration.Integration.Interfaces;

public sealed class MyDestinationWriter : IDestinationWriter, IDisposable
{
    public MyDestinationWriter(Mapping mapping)
    {
        Mapping = mapping;
    }

    public Mapping Mapping { get; }

    public void Write(Dictionary<string, object> row)
    {
        foreach (var columnMapping in Mapping.GetColumnMappings())
        {
            if (!columnMapping.Active || columnMapping.SourceColumn is null)
                continue;
            if (!row.TryGetValue(columnMapping.SourceColumn.Name, out var value))
                throw new InvalidOperationException(BaseDestinationWriter.GetRowValueNotFoundMessage(
                    row, columnMapping.SourceColumn.Table?.Name, columnMapping.SourceColumn.Name));

            var outputValue = columnMapping.ConvertInputValueToOutputValue(value);
            // Persist outputValue to columnMapping.DestinationColumn here.
        }
    }

    public void Close()
    {
        // Commit/flush and release the destination connection.
    }

    public void Dispose() => Close();
}

Properties

Mapping

Gets the table mapping the writer writes rows for. Not implemented in this base class — always throws NotImplementedException.

public Mapping Mapping { get; }

Property Value

Mapping

Exceptions

NotImplementedException

Always thrown by this base implementation.

Methods

Close()

Closes the writer after the last row has been written. Not implemented in this base class — always throws NotImplementedException.

public void Close()

Exceptions

NotImplementedException

Always thrown by this base implementation.

DeleteRowsMissingFromSource()

Removes destination rows that were not present in the source, typically used when a full synchronization deletes stale data. Not implemented in this base class — always throws NotImplementedException.

public void DeleteRowsMissingFromSource()

Exceptions

NotImplementedException

Always thrown by this base implementation.

GetRowValueNotFoundMessage(Dictionary<string, object>, string?, string?)

Builds a diagnostic message for the situation where a source row does not contain a value for a mapped source column. The message includes the table name, the column name and up to the first 20 key/value pairs of the row. Providers typically log this message or use it as the text of an InvalidOperationException thrown from their Write method.

public static string GetRowValueNotFoundMessage(Dictionary<string, object> row, string? sourceTableName, string? sourceColumnName)

Parameters

row Dictionary<string, object>

The source row that is missing the value, keyed by source column name.

sourceTableName string

The name of the source table being read.

sourceColumnName string

The name of the source column the value could not be found for.

Returns

string

A message describing the missing value and the content of the row.

Initialize()

Initializes the writer before the first row is written. Not implemented in this base class — always throws NotImplementedException.

public void Initialize()

Exceptions

NotImplementedException

Always thrown by this base implementation.

Write(Dictionary<string, object>)

Writes a row to the destination. Not implemented in this base class — always throws NotImplementedException.

public void Write(Dictionary<string, object> value)

Parameters

value Dictionary<string, object>

The row to write, keyed by source column name.

Exceptions

NotImplementedException

Always thrown by this base implementation.

To top