Class BaseActivityPreset
- Namespace
- Dynamicweb.DataIntegration.Integration
- Assembly
- Dynamicweb.DataIntegration.dll
Extensibility point for integration activity presets. A preset is a pre-packaged integration activity offered in the administration UI (the "install preset" screen and the data import flows); when the user installs it, Install(out string) creates a ready-to-run integration activity from the preset's bundled source/destination configuration.
public abstract class BaseActivityPreset : ConfigurableAddIn
- Inheritance
-
BaseActivityPreset
- Derived
- Inherited Members
Remarks
How to create a custom preset: Subclass this class, implement PresetName,
ValidateSettings() and Install(out string), and deploy the assembly with the solution.
The preset is discovered by the add-in system and becomes selectable in the preset installation screen. The class
derives from ConfigurableAddIn, so expose configuration as public properties decorated with
AddInParameterAttribute and an editor attribute — the UI renders and persists them automatically.
The installation command drives the preset in a fixed order: it creates the instance through AddInManager,
applies the user's parameter values (including the parameters of SourceProvider and
DestinationProvider when set), calls ValidateSettings(), then — when
NeedsEndpoint is true — saves the authentication and endpoint the user entered and passes the
endpoint to SetEndpoint(Endpoint), and finally calls Install(out string).
Things to be careful of:
- A new instance is created through
AddInManagerfor every screen refresh and command, so plain instance state does not survive between requests. Anything needed at install time must come from add-in parameter properties, or from SetEndpoint(Endpoint), which is called in the same command as Install(out string). - ValidateSettings() runs before the endpoint is created — do not depend on SetEndpoint(Endpoint) having been called during validation.
- Report installation failure by returning
falseand setting theerrorsoutput of Install(out string); exceptions thrown from the preset are not caught by the install command. - The class must have a public parameterless constructor so the add-in system can instantiate it.
- PresetName doubles as the name of the endpoint the framework saves when
NeedsEndpoint is
true.
using Dynamicweb.DataIntegration.EndpointManagement;
using Dynamicweb.DataIntegration.Integration;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Extensibility.Editors;
[AddInLabel("Import contacts from My CRM")]
public class MyCrmActivityPreset : BaseActivityPreset
{
private Endpoint? _endpoint;
[AddInParameter("ListName"), AddInLabel("Contact list"), AddInParameterEditor(typeof(TextParameterEditor), "")]
public string? ListName { get; set; }
public override string PresetName => "My CRM contact import";
public override bool NeedsEndpoint => true;
public override string? EndpointCollectionName => "My CRM endpoints";
public override void SetEndpoint(Endpoint endpoint) => _endpoint = endpoint;
public override string ValidateSettings()
=> string.IsNullOrEmpty(ListName) ? "Select a contact list to import." : string.Empty;
public override bool Install(out string errors)
{
errors = string.Empty;
if (_endpoint is null)
{
errors = "No endpoint was created for the preset.";
return false;
}
// Create and save the integration activity (job) here, using _endpoint
// and ListName to configure the source and destination providers.
return true;
}
}
Properties
DataImportPreset
Gets a value indicating whether the preset is a simplified data import preset. When true, the
administration UI uses the data import editing experience (file upload, sheet selection, preview) instead of
the generic preset installation screen. The default is false.
public virtual bool DataImportPreset { get; }
Property Value
DestinationProvider
Gets or sets the destination provider add-in the preset is configured with. When set, the installation UI
renders the provider's add-in parameters as an extra field group and writes the user's values back to the
instance before ValidateSettings() and Install(out string) run. The default is
null.
public virtual ConfigurableAddIn? DestinationProvider { get; set; }
Property Value
EndpointCollectionName
Gets the name of the endpoint collection the framework creates for the preset's endpoint when
NeedsEndpoint is true. The default is null, which results in a collection with an
empty name.
public virtual string? EndpointCollectionName { get; }
Property Value
NeedsEndpoint
Gets a value indicating whether the preset requires a remote endpoint. When true, the installation UI
collects an authentication add-in and an endpoint URL, saves them as an Endpoint in a collection
named EndpointCollectionName, and passes the endpoint to SetEndpoint(Endpoint)
before Install(out string) runs. The default is false.
public virtual bool NeedsEndpoint { get; }
Property Value
NeedsPreview
Gets a value indicating whether the preset can supply a data preview. When true, the preset editing
screens call GetPreviewListData(out List<Dictionary<string, object>>, out IEnumerable<string>, out string) and render the returned rows as a preview table.
The default is false.
public virtual bool NeedsPreview { get; }
Property Value
PresetName
Gets the display name of the preset. Also used as the name of the endpoint the framework saves before
calling SetEndpoint(Endpoint) when NeedsEndpoint is true.
public abstract string PresetName { get; }
Property Value
ServiceCachesList
Gets or sets the names of the service caches the installed activity should clear after it has run. Assigned from the user's selection by the data import update command before Install(out string); the preset is expected to persist the list on the activity it creates. The default is an empty list.
public virtual IEnumerable<string> ServiceCachesList { get; set; }
Property Value
SourceProvider
Gets or sets the source provider add-in the preset is configured with. When set, the installation UI renders
the provider's add-in parameters as an extra field group and writes the user's values back to the instance
before ValidateSettings() and Install(out string) run. The default is null.
public virtual ConfigurableAddIn? SourceProvider { get; set; }
Property Value
Methods
GetPreviewListData(out List<Dictionary<string, object>>, out IEnumerable<string>, out string)
Supplies the rows and columns shown as a data preview in the preset editing screens. Called when
NeedsPreview is true; the preview is only rendered when the method returns true.
The base implementation returns false with empty data.
public virtual bool GetPreviewListData(out List<Dictionary<string, object>> listData, out IEnumerable<string> columns, out string error)
Parameters
listDataList<Dictionary<string, object>>Receives the preview rows, each keyed by column name.
columnsIEnumerable<string>Receives the column names in display order.
errorstringReceives a message describing why the preview could not be produced.
Returns
- bool
truewhen preview data is available; otherwisefalse.
Install(out string)
Performs the installation — creates the integration activity (job) the preset represents. Called once by the
install command after ValidateSettings() returned an empty string and, when
NeedsEndpoint is true, after SetEndpoint(Endpoint) has been called.
public abstract bool Install(out string errors)
Parameters
errorsstringReceives a message describing why the installation failed; shown to the user when the method returns
false.
Returns
- bool
truewhen the activity was installed successfully; otherwisefalse.
LoadSettings()
Loads the preset's parameter values from an existing installed activity. Called by the data import query when the editing UI is opened for an already configured activity, after SourceProvider and DestinationProvider have been populated; override to read the persisted configuration back into the add-in parameter properties. The base implementation does nothing.
public virtual void LoadSettings()
SetEndpoint(Endpoint)
Receives the endpoint the framework saved for the preset. Called by the install command after
ValidateSettings() and before Install(out string), and only when
NeedsEndpoint is true. Override to store the endpoint for use during installation;
the base implementation does nothing.
public virtual void SetEndpoint(Endpoint endpoint)
Parameters
endpointEndpointThe saved endpoint, named after PresetName.
ValidateSettings()
Validates the preset configuration. Called by the install and update commands after the user's parameter values have been applied to the instance and before Install(out string); a non-empty return value aborts the installation and is shown to the user.
public abstract string ValidateSettings()
Returns
- string
An empty string when the settings are valid; otherwise a message describing the problems.