Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.4.31</Version>
<Version>10.4.32</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Live Integration</Title>
<Description>Live Integration</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dynamicweb.Content;
using Dynamicweb.Core;
using Dynamicweb.DataIntegration.EndpointManagement;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Connectors;
Expand All @@ -11,7 +12,6 @@
using Dynamicweb.Rendering;
using Dynamicweb.Security.UserManagement;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand All @@ -29,7 +29,7 @@
[AddInIgnore(false)]
[AddInUseParameterGrouping(true)]
[AddInUseParameterOrdering(true)]
public class LiveIntegrationAddIn : BaseLiveIntegrationAddIn, IDropDownOptions, ISettings
public class LiveIntegrationAddIn : BaseLiveIntegrationAddIn, IParameterOptions, ISettings, IParameterVisibility
{
/// <summary>
/// Initializes a new instance of the <see cref="LiveIntegrationAddIn"/> class.
Expand Down Expand Up @@ -77,12 +77,19 @@
[AddInParameterOrder(6)]
public string InstanceLabel { get; set; }

[AddInParameterGroup("General")]
[AddInParameter("ConnectionToType")]
[AddInLabel("Connect to")]
[AddInParameterEditor(typeof(RadioParameterEditor), "")]
[AddInParameterOrder(9)]
public string ConnectionToType { get; set; } = nameof(ConnectionType.Endpoint);

/// <summary>
/// The web service Uri
/// </summary>
/// <value>The web service URI.</value>
[AddInParameter("Web service URL")]
[AddInParameterEditor(typeof(TextParameterEditor), "TextArea=True")]
[AddInParameterEditor(typeof(TextParameterEditor), "TextArea=True;")]
[AddInParameterGroup("General")]
[AddInParameterOrder(10)]
public override string WebServiceURI { get; set; }
Expand All @@ -92,7 +99,7 @@
/// </summary>
/// <value>The security key.</value>
[AddInParameter("Security key")]
[AddInParameterEditor(typeof(TextParameterEditor), "password=true")]
[AddInParameterEditor(typeof(TextParameterEditor), "password=true;")]
[AddInParameterGroup("General")]
[AddInParameterOrder(20)]
public override string SecurityKey { get; set; }
Expand Down Expand Up @@ -494,7 +501,7 @@
/// </summary>
/// <value>The notification email.</value>
[AddInParameter("Notification recipient groups")]
[AddInParameterEditor(typeof(UserGroupParameterEditor), "Multiple=true;")]
[AddInParameterEditor(typeof(UserGroupParameterEditor), "Multiple=true;")]
[AddInParameterGroup("Notifications")]
[AddInParameterOrder(235)]
public string RecipientGroups { get; set; }
Expand Down Expand Up @@ -621,66 +628,66 @@
/// </summary>
/// <param name="dropdownName">Name of the dropdown.</param>
/// <returns>Hashtable.</returns>
public Hashtable GetOptions(string dropdownName)
IEnumerable<ParameterOption> IParameterOptions.GetParameterOptions(string dropdownName)
{
var options = new Hashtable();
var options = new List<ParameterOption>();

switch (dropdownName)
{
case "Notification sending frequency":
foreach (NotificationFrequency frequencyLevel in Enum.GetValues(typeof(NotificationFrequency)))
{
options.Add(((int)frequencyLevel).ToString(), GetNotificationFrequencyText(frequencyLevel));
options.Add(new(GetNotificationFrequencyText(frequencyLevel), ((int)frequencyLevel).ToString()));
}
break;

case "Order state after export succeeded":
case "Order state after export failed":
options.Add(string.Empty, "Leave unchanged");
options.Add(new("Leave unchanged", string.Empty));
foreach (var state in Services.OrderStates.GetStatesByOrderType(OrderType.Order))
{
if (state.IsDeleted)
continue;

options.Add(state.Id, state.GetName(Services.Languages.GetDefaultLanguageId()));
options.Add(new(state.GetName(Services.Languages.GetDefaultLanguageId()), state.Id));
}
break;

case "Shop":
options.Add(string.Empty, "Any");
options.Add(new("Any", string.Empty));
var shops = Services.Shops.GetShops();
foreach (var shop in shops)
{
options.Add(shop.Id, shop.Name);
options.Add(new(shop.Name, shop.Id));
}
break;
case "Website":
foreach (var area in new AreaService().GetAreas())
{
options.Add(area.ID, area.Name);
options.Add(new(area.Name, area.ID));
}
break;
case "Cart communication type":
options.Add(Constants.CartCommunicationType.None, Constants.CartCommunicationType.None);
options.Add(Constants.CartCommunicationType.Full, Constants.CartCommunicationType.Full);
options.Add(Constants.CartCommunicationType.OnlyOnOrderComplete, Constants.CartCommunicationType.OnlyOnOrderComplete);
options.Add(Constants.CartCommunicationType.CartOnly, Constants.CartCommunicationType.CartOnly);
options.Add(new(Constants.CartCommunicationType.None, Constants.CartCommunicationType.None));
options.Add(new(Constants.CartCommunicationType.Full, Constants.CartCommunicationType.Full));
options.Add(new(Constants.CartCommunicationType.OnlyOnOrderComplete, Constants.CartCommunicationType.OnlyOnOrderComplete));
options.Add(new(Constants.CartCommunicationType.CartOnly, Constants.CartCommunicationType.CartOnly));
break;

case "Number format culture":
foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
if (!string.IsNullOrEmpty(culture.Name) && !culture.IsNeutralCulture && !options.ContainsKey(culture.Name))
if (!string.IsNullOrEmpty(culture.Name) && !culture.IsNeutralCulture && !options.Any(o => string.Equals(o.Value.ToString(), culture.Name, StringComparison.OrdinalIgnoreCase)))
{
options.Add(culture.Name, $"{culture.Name} - {culture.EnglishName}");
options.Add(new($"{culture.Name} - {culture.EnglishName}", culture.Name));
}
}
break;
case "Order cache level":
case "Product information cache level":
foreach (var cacheLevel in Enum.GetNames(typeof(Cache.ResponseCacheLevel)))
{
options.Add(cacheLevel, cacheLevel);
options.Add(new(cacheLevel, cacheLevel));
}
break;
case "Endpoint":
Expand Down Expand Up @@ -708,20 +715,24 @@
if (endpointFilters.ContainsKey(endpoint.Id))
{
string str = endpointFilters[endpoint.Id];
options.Add(str, endpoint.Name + str.Substring(str.IndexOf(";")));
options.Add(new(endpoint.Name + str.Substring(str.IndexOf(";")), str));
}
else
{
options.Add(endpoint.Id.ToString(), endpoint.Name);
options.Add(new(endpoint.Name, endpoint.Id.ToString()));
}
}
break;
case "ERP shipping item type":
options.Add(Constants.OrderConfiguration.DefaultShippingItemType, "Item Charge");
options.Add("Account", "G/L Account");
options.Add("Item", "Item");
options.Add("FixedAsset", "Fixed Asset");
options.Add("Resource", "Resource");
options.Add(new("Item Charge", Constants.OrderConfiguration.DefaultShippingItemType));
options.Add(new("G/L Account", "Account"));
options.Add(new("Item", "Item"));
options.Add(new("Fixed Asset", "FixedAsset"));
options.Add(new("Resource", "Resource"));
break;
case "ConnectionToType":
options.Add(new(nameof(ConnectionType.Endpoint), ConnectionType.Endpoint));
options.Add(new("Dynamicweb connector web service", ConnectionType.WebService));
break;
default:
throw new ArgumentException($"Unsupported dropdown: {dropdownName}", nameof(dropdownName));
Expand All @@ -730,6 +741,27 @@
return options;
}

IEnumerable<string> IParameterVisibility.GetHiddenParameterNames(string parameterName, object? parameterValue)

Check warning on line 744 in src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/LiveIntegrationAddIn.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 744 in src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/LiveIntegrationAddIn.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
var result = new List<string>();
var parameterValueStr = Converter.ToString(parameterValue);
switch (parameterName)
{
case nameof(ConnectionToType):
if (nameof(ConnectionType.Endpoint).Equals(parameterValueStr, StringComparison.OrdinalIgnoreCase))
{
result.Add("Web service URL");
result.Add("Security key");
}
else
{
result.Add("Endpoint");
}
break;
}
return result;
}

private Settings GetCurrentSettings()
{
Settings settings = null;
Expand Down Expand Up @@ -781,6 +813,11 @@
Settings settings = GetCurrentSettings();
Settings.UpdateFrom(settings, this);

if (string.IsNullOrEmpty(Endpoint) && !string.IsNullOrEmpty(WebServiceURI))
{
ConnectionToType = nameof(ConnectionType.WebService);
}

var xml = GetParametersToXml(false);

return xml;
Expand All @@ -792,6 +829,13 @@
public override void SaveSettings()
{
Settings settings = GetCurrentSettings();
// Do not allow Endpoint and WebService to be selected at the same time
if (!string.IsNullOrEmpty(Endpoint) && !string.IsNullOrEmpty(WebServiceURI)
&& Enum.TryParse<ConnectionType>(ConnectionToType, out var connectionType) && connectionType == ConnectionType.WebService)
{
Endpoint = "";
}

Settings.UpdateFrom(this, settings);
if (string.IsNullOrEmpty(settings.InstanceId))
{
Expand All @@ -807,7 +851,7 @@
{
AutoPingInterval = Constants.MinPingInterval;
}
if(ConnectionTimeout < Constants.DefaultConnectionTimeout)
if (ConnectionTimeout < Constants.DefaultConnectionTimeout)
{
ConnectionTimeout = Constants.DefaultConnectionTimeout;
}
Expand Down Expand Up @@ -930,5 +974,11 @@
Helpers.SaveTranslation(Constants.OrderConfiguration.OrderDiscountText, settings.OrderDiscountText);
Helpers.SaveTranslation(Constants.OrderConfiguration.ProductDiscountText, settings.ProductDiscountText);
}

private enum ConnectionType
{
Endpoint,
WebService,
}
}
}
Loading