Skip to content

Commit

Permalink
Added extension of IParameterVisibility to control what add-ins to hi…
Browse files Browse the repository at this point in the history
…de. adjusted Mode-add-in so it doesn't have full-replication as default plus made it required
  • Loading branch information
MatthiasSort committed Aug 16, 2024
1 parent 677e5a2 commit b1c06b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.6.2</Version>
<Version>10.6.3</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>OData Provider</Title>
<Description>The Odata Provider lets you fetch and map data from or to any OData endpoint.</Description>
Expand Down
32 changes: 29 additions & 3 deletions src/ODataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Dynamicweb.DataIntegration.Providers.ODataProvider;
[AddInIgnore(false)]
[AddInUseParameterSectioning(true)]
[ResponseMapping(true)]
public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOptions, IODataBaseProvider
public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOptions, IODataBaseProvider, IParameterVisibility
{
internal readonly EndpointService _endpointService = new EndpointService();
internal Schema _schema;
Expand Down Expand Up @@ -61,7 +61,7 @@ public string EndpointId
}

[AddInParameter("Mode")]
[AddInParameterEditor(typeof(DropDownParameterEditor), "Info=Required;none=true;nonetext=Full Replication;noneHint=This mode gets all records and deletes nothing. This option should only run once.;columns=Mode|Comment;SortBy=Key;HideParameters=Run request in intervals (pages),Do not store last response in log file")]
[AddInParameterEditor(typeof(DropDownParameterEditor), "required=true;reloadOnChange=true;none=true;nonetext=Please select a Mode;SortBy=Key;")]
[AddInParameterGroup("Source")]
[AddInParameterSection("Advanced activity settings")]
public string Mode { get; set; }
Expand Down Expand Up @@ -168,6 +168,27 @@ internal void SetCredentials()
}
}

IEnumerable<string> IParameterVisibility.GetHiddenParameterNames(string parameterName, object parameterValue)
{
var parameters = new List<string>();
switch (parameterName)
{
case nameof(Mode):
if (!"Full Replication".Equals((string)parameterValue, StringComparison.OrdinalIgnoreCase))
{
parameters.Add("Run request in intervals (pages)");
parameters.Add("Do not store last response in log file");
}
if (!"Delta replication".Equals((string)parameterValue, StringComparison.OrdinalIgnoreCase))
{
parameters.Add("Delta modifier");
}
break;
}

return parameters;
}

IEnumerable<ParameterOption> IParameterOptions.GetParameterOptions(string parameterName)
{
switch (parameterName ?? "")
Expand All @@ -176,6 +197,7 @@ IEnumerable<ParameterOption> IParameterOptions.GetParameterOptions(string parame
{
return new List<ParameterOption>()
{
{ new("Full Replication", "Full Replication") { Hint = "This mode gets all records and deletes nothing. This option should only run once." } },
{ new("Delta replication", "Delta Replication") { Hint = "This mode filters records on date and time, whenever possible, and it only acts on new or updated records. It never deletes." } },
{ new("First page", "First page") { Hint = "If maximum page size is 100 then this setting only handles the 100 records of the first page." } }
};
Expand Down Expand Up @@ -427,7 +449,7 @@ public override ISourceReader GetReader(Mapping mapping)
throw new Exception("License check for OData failed.");
}

if (!string.IsNullOrEmpty(Mode))
if (!string.IsNullOrEmpty(Mode) && !Mode.Equals("Full Replication", StringComparison.OrdinalIgnoreCase))
{
RequestIntervals = 0;
DoNotStoreLastResponseInLogFile = false;
Expand All @@ -449,6 +471,10 @@ public override string ValidateSourceSettings()
{
return "Predefined endpoint can not be empty. Please select any predefined endpoint.";
}
if (string.IsNullOrEmpty(Mode))
{
return "Mode can not be empty. Please select a mode.";
}
if (_endpoint?.Authentication == null)
{
return "Credentials not set for endpoint, please add credentials before continue.";
Expand Down

0 comments on commit b1c06b1

Please sign in to comment.