Table of Contents

Class BaseProvider

Namespace
Dynamicweb.DataIntegration
Assembly
Dynamicweb.DataIntegration.dll

Extensibility point for data integration providers — the components that act as the source and/or destination of a data integration job. A provider exposes a Schema, and acts as a source by returning an ISourceReader per table mapping from GetReader(Mapping), and/or as a destination by implementing RunJob(Job), which drains the source readers and writes the rows to the destination. Built-in providers include the SQL, Dynamicweb, Ecom, Order, User, XML, CSV and Excel providers.

[AddInName("Dynamicweb.DataIntegration.Providers.Provider")]
[AddInDescription("Base provider")]
public abstract class BaseProvider : ConfigurableAddIn, ISource, IDestination, IParameterizedDestination
Inheritance
BaseProvider
Implements
Derived
Inherited Members
Extension Methods

Remarks

How to create a custom provider: Subclass this class, decorate it with AddInNameAttribute, AddInLabelAttribute and AddInDescriptionAttribute, and expose configuration as properties decorated with AddInParameterAttribute (the class derives from ConfigurableAddIn). Deploy the assembly with the solution and the provider becomes selectable as source and/or destination in the data integration job editor.

Every provider MUST have Ctor() and Ctor(XmlNode xmlNode), as these are called implicitly through reflection in the frontend and in the Job class. The XmlNode constructor recreates the provider from its saved job configuration, and SaveAsXml(XmlTextWriter) writes that configuration — the two must round-trip. Some built-in providers additionally implement a Ctor(string) that builds an instance directly from a single provider-specific value — a file path for the CSV/Excel/XML providers, a connection string for the SQL/Ecom/Order/Dynamicweb providers — for that provider's own scenarios (e.g. processing one file directly). This third constructor is optional: implement it only when the provider has an equivalent single-value configuration to construct from; providers configured through other means (e.g. ODataProvider, which is configured via a predefined endpoint reference) don't need it.

Source provider contract: implement GetSchema(), GetOriginalSourceSchema(), GetReader(Mapping), Close() and SaveAsXml(XmlTextWriter). The job engine calls GetReader(Mapping) once per active table mapping and drains the reader; Close() is called when the job finishes.

Destination provider contract: implement GetSchema(), GetOriginalDestinationSchema(), RunJob(Job) and SaveAsXml(XmlTextWriter). A typical RunJob(Job) loops the active mappings, gets the reader for each from job.Source.GetReader(mapping), calls ProcessInputRow(Dictionary<string, object>, Mapping) for every row (which applies null/empty handling and the mapping's TableScript), checks the mapping's conditionals with CheckCondition(MappingConditional, Dictionary<string, object>) and writes the row through an IDestinationWriter. Return true on success, false on failure, and log progress and errors to Logger.

Things to be careful of: the base implementations of the schema, reader, serialization and job members throw NotImplementedException — override every member that applies to the role (source, destination or both) the provider supports. Providers are also instantiated by the job editor UI just to render and validate settings, so constructors and Initialize() must not assume a job is running.

Properties

ABasePovider

protected BaseProvider ABasePovider { get; set; }

Property Value

BaseProvider

FilesFolderName

The Name of the files folder in the current installation of Dynamicweb. Empty if used for test.

public string FilesFolderName { get; set; }

Property Value

string

JobIsGoingToRun

Gets and sets "job is going to run" status

public bool JobIsGoingToRun { get; set; }

Property Value

bool

Logger

Gets or sets the logger for the current job run. Assigned by the job engine before the job executes; write progress and errors here from RunJob(Job) so they appear in the job log in the administration interface. May be null outside a job run.

public ILogger? Logger { get; set; }

Property Value

ILogger

Parameters

Gets or sets the request parameters passed to the job when it is triggered externally (for example through an endpoint), keyed by parameter name. Used by ReplaceMappingConditionalsWithValuesFromRequest(Job) to substitute placeholders in mapping conditionals and to add conditionals from a filter parameter. Never null.

public Dictionary<string, string> Parameters { get; set; }

Property Value

Dictionary<string, string>

SchemaIsEditable

Gets a value indicating whether the user can edit the provider's schema (add tables and columns) in the job editor. The default is false; file-based providers such as CSV and XML typically return true.

public virtual bool SchemaIsEditable { get; }

Property Value

bool

TableRelations

Gets the table dependency map used by IsSortable(Job, bool) and OrderTablesByRelations(Job, bool). Key is a table name, value is the list of table names it depends on; populate it in a derived provider to control the order table mappings are processed in.

protected Dictionary<string, List<string>> TableRelations { get; }

Property Value

Dictionary<string, List<string>>

WorkingDirectory

Gets and sets working directory path

public virtual string WorkingDirectory { get; set; }

Property Value

string

Methods

CheckCondition(MappingConditional, Dictionary<string, object>)

Evaluates a mapping conditional against a source row, comparing the row's value for the conditional's source column with the condition using the conditional's operator. The comparison is typed by the source column type (string, int, double, float, decimal, long or bool). Destination providers call this per row to decide whether the row should be imported.

public bool CheckCondition(MappingConditional mappingConditional, Dictionary<string, object> row)

Parameters

mappingConditional MappingConditional

The conditional to evaluate.

row Dictionary<string, object>

The source row, keyed by source column name.

Returns

bool

true when the row satisfies the condition — or when the conditional's column is absent from the row or its type is not supported; false when the row should be filtered out.

Close()

Closes the provider when the job has finished, releasing connections and other resources. Called on both the source and the destination provider. Must be overridden; the base implementation throws NotImplementedException.

public virtual void Close()

CreateParameterNode(Type, string, string?)

Creates a <Parameter> element in the format used by the add-in parameter XML, for use when building provider configuration in SaveAsXml(XmlTextWriter) or Serialize().

protected static XElement? CreateParameterNode(Type type, string name, string? value)

Parameters

type Type

The provider type the parameter belongs to; written to the addin attribute.

name string

The parameter name.

value string

The parameter value; an empty value is written when null or empty.

Returns

XElement

The parameter element, or null when type is null or name is empty.

GetDefaultValue(Type?)

Gets the default value used when a null/empty action replaces a missing source value: MinValue for DateTime, the zero-initialized value for other value types, and null for reference types or when type is null.

public static object? GetDefaultValue(Type? type)

Parameters

type Type

The destination column type to get a default value for.

Returns

object

The default value, or null.

GetDetails(string)

Gets a details text for the given identifier, or null when the provider does not expose details. The default implementation returns null.

public virtual string? GetDetails(string id)

Parameters

id string

The identifier returned by GetId().

Returns

string

The details text, or null.

GetFailedSourceRowMessage(Dictionary<string, object>?)

Gets the failed row data message

public static string GetFailedSourceRowMessage(Dictionary<string, object>? row)

Parameters

row Dictionary<string, object>

Data row

Returns

string

The failed row data as string

GetId()

Gets an identifier for the current provider configuration, or null when the provider does not expose one. The default implementation returns null.

public virtual string? GetId()

Returns

string

The identifier, or null.

GetOriginalDestinationSchema()

Gets the unmodified schema as read from the underlying destination, ignoring any user edits. Used by the job editor to reset or compare schemas. Must be overridden by destination providers; the base implementation throws NotImplementedException.

public virtual Schema GetOriginalDestinationSchema()

Returns

Schema

The original destination schema.

GetOriginalSourceSchema()

Gets the unmodified schema as read from the underlying source, ignoring any user edits. Used by the job editor to reset or compare schemas. Must be overridden by source providers; the base implementation throws NotImplementedException.

public virtual Schema GetOriginalSourceSchema()

Returns

Schema

The original source schema.

GetReader(Mapping)

Creates a reader that returns the source rows for a table mapping. Called by the destination provider's RunJob(Job) once per active mapping when this provider is the source of the job; the returned reader is drained via IsDone()/GetNext() and disposed afterwards. Must be overridden by source providers; the base implementation throws NotImplementedException.

public virtual ISourceReader GetReader(Mapping mapping)

Parameters

mapping Mapping

The table mapping to read source rows for.

Returns

ISourceReader

A reader positioned at the first row of the mapped source table.

GetSchema()

Gets the schema (tables and columns) the provider currently exposes, including any user edits when SchemaIsEditable is true. Used by the job editor to build table and column mappings. Must be overridden by every provider; the base implementation throws NotImplementedException.

public virtual Schema GetSchema()

Returns

Schema

The current schema of the provider.

Initialize()

Initializes the provider before use. Override to perform setup that must not run in the constructor. The default implementation does nothing.

public virtual void Initialize()

IsSortable(Job, bool)

Determines whether the user may reorder the job's table mappings freely. Returns false when TableRelations declares a dependency between two mapped tables, in which case the order is enforced with OrderTablesByRelations(Job, bool).

public virtual bool IsSortable(Job job, bool isSource)

Parameters

job Job

The job whose mappings are checked.

isSource bool

Whether this provider is the source (true) or the destination (false) of the job.

Returns

bool

true when mappings can be sorted freely; otherwise false.

LoadSettings(Job)

Called before the job runs to let the provider read settings from the job it participates in. Override to pick up job-level configuration; the default implementation does nothing.

public virtual void LoadSettings(Job job)

Parameters

job Job

The job the provider is the source or destination of.

OrderTablesByRelations(Job, bool)

Reorders the job's table mappings so tables listed as dependencies in TableRelations are processed first, in the order they are declared. No-op when none of the mapped tables appear as a dependency.

public void OrderTablesByRelations(Job job, bool isSource)

Parameters

job Job

The job whose mappings are reordered in place.

isSource bool

Whether to match relations against source (true) or destination (false) table names.

OverwriteDestinationSchemaToOriginal()

Discards user edits to the destination schema and reverts to GetOriginalDestinationSchema(). Must be overridden by destination providers; the base implementation throws NotImplementedException.

public virtual void OverwriteDestinationSchemaToOriginal()

OverwriteSourceSchemaToOriginal()

Discards user edits to the source schema and reverts to GetOriginalSourceSchema(). Must be overridden by source providers; the base implementation throws NotImplementedException.

public virtual void OverwriteSourceSchemaToOriginal()

ProcessInputRow(Dictionary<string, object>, Mapping)

Prepares a source row for writing: applies the null/empty actions configured on the mapping's column mappings (skip row, default value or replacement value), assigns the row to Dynamicweb.DataIntegration.Integration.Mapping.SourceRow, and runs the mapping's TableScript if one is configured. Destination providers call this for every row before converting and writing it. Table script instances are cached per script class for the lifetime of the provider, and exceptions they throw are logged to Logger without failing the row.

protected bool ProcessInputRow(Dictionary<string, object> row, Mapping mapping)

Parameters

row Dictionary<string, object>

The source row, keyed by source column name; modified in place.

mapping Mapping

The table mapping the row belongs to.

Returns

bool

false when the row should be skipped — because row or mapping is null, or a null/empty action of type skip row matched; otherwise true.

ReplaceMappingConditionalsWithValuesFromRequest(Job)

Substitutes request parameters into the job's mapping conditionals when the job's source implements IParameterizedDestination: placeholders in condition values are replaced from Parameters, conditions starting with @Code are expanded through the expression evaluator, and a filter parameter of the form {column|operator|value;...} adds conditionals to the matching mappings. Call this from RunJob(Job) before reading rows when the provider supports parameterized execution.

protected void ReplaceMappingConditionalsWithValuesFromRequest(Job job)

Parameters

job Job

The job whose mapping conditionals are updated in place.

RunJob(Job)

Executes the job with this provider as the destination. Called once by the job engine; the implementation loops the active table mappings, reads the rows from job.Source via GetReader(Mapping), processes each row with ProcessInputRow(Dictionary<string, object>, Mapping) and writes it to the destination. Must be overridden by destination providers; the base implementation throws NotImplementedException.

public virtual bool RunJob(Job job)

Parameters

job Job

The job to run.

Returns

bool

true when the job completed successfully; otherwise false. Log failures to Logger.

SaveAsXml(XmlTextWriter)

Writes the provider configuration as XML when the job definition is saved. Must round-trip with the Ctor(XmlNode) constructor that recreates the provider when the job is loaded. Must be overridden; the base implementation throws NotImplementedException.

public virtual void SaveAsXml(XmlTextWriter textWriter)

Parameters

textWriter XmlTextWriter

The writer positioned inside the job definition document.

Serialize()

Serializes the provider configuration to an XML fragment string, used when the provider settings are stored as part of a job definition. Must round-trip with the Ctor(XmlNode) constructor. The base implementation throws NotImplementedException.

public virtual string Serialize()

Returns

string

The provider configuration as an XML string.

UpdateDestinationSettings(IDestination)

Copies the settings of another instance of the same provider into this instance, used when the job editor saves updated destination settings onto an existing job. Must be overridden by destination providers; the base implementation throws NotImplementedException.

public virtual void UpdateDestinationSettings(IDestination destination)

Parameters

destination IDestination

The instance holding the new settings; cast to the concrete provider type.

UpdateIndexes(IList<string>, ILogger?)

Rebuilds the given repository index builds, typically called by destination providers after a successful import so search indexes reflect the imported data. Each entry has the form {repository}-{index}-{build}; missing indexes or builds are logged and skipped.

public static void UpdateIndexes(IList<string> indexes, ILogger? logger)

Parameters

indexes IList<string>

The index builds to run, formatted as {repository}-{index}-{build}.

logger ILogger

The logger progress and failures are written to; may be null.

UpdateSourceSettings(ISource)

Copies the settings of another instance of the same provider into this instance, used when the job editor saves updated source settings onto an existing job. Must be overridden by source providers; the base implementation throws NotImplementedException.

public virtual void UpdateSourceSettings(ISource source)

Parameters

source ISource

The instance holding the new settings; cast to the concrete provider type.

ValidateDestinationSettings()

Validates the destination settings. Used to validate properties when created by the AddinSelector.

public virtual string ValidateDestinationSettings()

Returns

string

ValidateSourceSettings()

Validates the source settings when the provider is configured as a source in the job editor. Override to check connectivity, file existence and similar; return an error description to show the user, or a non-error string when valid.

public virtual string ValidateSourceSettings()

Returns

string

A validation message; the default implementation performs no validation.

See Also

To top