Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v1.3.4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
afaniuolo committed Apr 17, 2021
2 parents 74bbd54 + eb20d49 commit f48b162
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.3.0")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: AssemblyVersion("1.3.4.0")]
[assembly: AssemblyFileVersion("1.3.4.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@
using System.Text.RegularExpressions;
using WFFM.ConversionTool.Library.Converters;
using WFFM.ConversionTool.Library.Helpers;
using WFFM.ConversionTool.Library.Logging;
using WFFM.ConversionTool.Library.Repositories;

namespace WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.Converters
{
public class SendEmailConverter : BaseFieldConverter
{
private IDestMasterRepository _destMasterRepository;
private ILogger _logger;

public SendEmailConverter(IDestMasterRepository destMasterRepository)
public SendEmailConverter(IDestMasterRepository destMasterRepository, ILogger logger)
{
_destMasterRepository = destMasterRepository;
_logger = logger;
}

public override string ConvertValue(string sourceValue)
{
// example of sourceValue
// <host>example.host</host><from>example@mail.net</from><isbodyhtml>true</isbodyhtml><to>to@example.com</to><cc>cc@example.com</cc><bcc>bcc@example.com</bcc><localfrom>example@mail.net</localfrom><subject>This is the subject of the email.</subject><mail><p>This is the body of the email.</p><p>[<label id="{CFA55E36-3018-41A4-9F4D-2EA1293D5902}">Single-Line Text</label>]</p></mail>
var host = XmlHelper.GetXmlElementValue(sourceValue, "host");
var from = XmlHelper.GetXmlElementValue(sourceValue, "from");
var isbodyhtml = XmlHelper.GetXmlElementValue(sourceValue, "isbodyhtml");
var to = XmlHelper.GetXmlElementValue(sourceValue, "to");
var cc = XmlHelper.GetXmlElementValue(sourceValue, "cc");
var bcc = XmlHelper.GetXmlElementValue(sourceValue, "bcc");
var localfrom = XmlHelper.GetXmlElementValue(sourceValue, "localfrom");
var subject = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "subject"));
var mail = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "mail"));
var host = XmlHelper.GetXmlElementValue(sourceValue, "host", true);
var from = XmlHelper.GetXmlElementValue(sourceValue, "from", true);
var isbodyhtml = XmlHelper.GetXmlElementValue(sourceValue, "isbodyhtml", true);
var to = XmlHelper.GetXmlElementValue(sourceValue, "to", true);
var cc = XmlHelper.GetXmlElementValue(sourceValue, "cc", true);
var bcc = XmlHelper.GetXmlElementValue(sourceValue, "bcc", true);
var localfrom = XmlHelper.GetXmlElementValue(sourceValue, "localfrom", true);
var subject = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "subject", true));
var mail = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "mail", true));

var fromValue = !string.IsNullOrEmpty(from) ? from : localfrom;

Expand Down Expand Up @@ -63,7 +66,7 @@ private string ConvertFieldTokens(string fieldText)
else // case of token in message field
{
// get field label value
fieldName = XmlHelper.GetXmlElementValue(matchValue, "label");
fieldName = XmlHelper.GetXmlElementValue(matchValue, "label", true);
}

if (!string.IsNullOrEmpty(fieldName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.3.0")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: AssemblyVersion("1.3.4.0")]
[assembly: AssemblyFileVersion("1.3.4.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Xml;
using WFFM.ConversionTool.Library.Factories;
using WFFM.ConversionTool.Library.Helpers;
using WFFM.ConversionTool.Library.Logging;
using WFFM.ConversionTool.Library.Models.Metadata;
using WFFM.ConversionTool.Library.Models.Sitecore;
using WFFM.ConversionTool.Library.Reporting;
Expand All @@ -17,11 +18,13 @@ public class DatasourceConverter : BaseFieldConverter
{
private IItemFactory _itemFactory;
private IReporter _analysisReporter;
private ILogger _logger;

public DatasourceConverter(IItemFactory itemFactory, IReporter analysisReporter)
public DatasourceConverter(IItemFactory itemFactory, IReporter analysisReporter, ILogger logger)
{
_itemFactory = itemFactory;
_analysisReporter = analysisReporter;
_logger = logger;
}

public override List<SCItem> ConvertValueElementToItems(SCField scField, string elementValue, MetadataTemplate metadataTemplate, SCItem sourceItem)
Expand All @@ -30,7 +33,17 @@ public override List<SCItem> ConvertValueElementToItems(SCField scField, string

var decodedElementValue = Uri.UnescapeDataString(elementValue).Replace("+", " ");

var queryElements = XmlHelper.GetXmlElementNodeList(decodedElementValue, "query");
XmlNodeList queryElements = null;
try
{
queryElements = XmlHelper.GetXmlElementNodeList(decodedElementValue, "query", true);
}
catch (Exception ex)
{
_logger.Log(new LogEntry(LoggingEventType.Error,
string.Format("ConvertValueElementToItems - Failed to parse Xml value. ItemID = {0} - FieldID = {1} - ElementName = {2} - ElementValue_Decoded = {3}",
scField.ItemId, scField.Id, "query", decodedElementValue), ex));
}
if (queryElements != null && queryElements.Count > 0)
{
foreach (XmlNode queryElement in queryElements)
Expand Down Expand Up @@ -88,7 +101,18 @@ public override List<SCField> ConvertValueElementToFields(SCField scField, strin

var decodedElementValue = Uri.UnescapeDataString(elementValue).Replace("+"," ");

var queryElement = XmlHelper.GetXmlElementNode(decodedElementValue, "query");
XmlNode queryElement = null;
try
{
queryElement = XmlHelper.GetXmlElementNode(decodedElementValue, "query", true);
}
catch (Exception ex)
{
_logger.Log(new LogEntry(LoggingEventType.Error,
string.Format("ConvertValueElementToFields - Failed to parse Xml value. ItemID = {0} - FieldID = {1} - ElementName = {2} - ElementValue_Decoded = {3}",
scField.ItemId, scField.Id, "query", decodedElementValue), ex));
}

if (queryElement != null)
{
if (queryElement.Attributes != null && queryElement.Attributes["t"] != null)
Expand Down
20 changes: 17 additions & 3 deletions src/WFFM.ConversionTool.Library/Converters/SubmitConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ public class SubmitConverter : ItemProcessor
private IFieldProvider _fieldProvider;
private AppSettings _appSettings;
private IReporter _analysisReporter;
private ILogger _logger;

public SubmitConverter(IMetadataProvider metadataProvider, IDestMasterRepository destMasterRepository, IItemConverter itemConverter, IItemFactory itemFactory, IFieldProvider fieldProvider, AppSettings appSettings, IReporter analysisReporter)
public SubmitConverter(IMetadataProvider metadataProvider, IDestMasterRepository destMasterRepository, IItemConverter itemConverter, IItemFactory itemFactory,
IFieldProvider fieldProvider, AppSettings appSettings, IReporter analysisReporter, ILogger logger)
: base(destMasterRepository, itemConverter, itemFactory, appSettings)
{
_destMasterRepository = destMasterRepository;
_metadataProvider = metadataProvider;
_fieldProvider = fieldProvider;
_appSettings = appSettings;
_analysisReporter = analysisReporter;
_logger = logger;
}

public void Convert(SCItem form, SCItem pageItem)
Expand Down Expand Up @@ -262,8 +265,19 @@ private void ConvertSaveActions(SCItem form, string tracking, SCItem buttonItem,
var submitActionValues = new Dictionary<Guid, string>();
submitActionValues.Add(new Guid(SubmitActionConstants.SubmitActionFieldId),
submitAction.destSubmitActionFieldValue);
submitActionValues.Add(new Guid(SubmitActionConstants.ParametersFieldId),
converter.ConvertValue(HttpUtility.HtmlDecode((saveActionItem.Parameters.Replace("&amp;","&")))));
try
{
submitActionValues.Add(new Guid(SubmitActionConstants.ParametersFieldId),
converter.ConvertValue(
HttpUtility.HtmlDecode((saveActionItem.Parameters.Replace("&amp;", "&")))));
}
catch (Exception ex)
{
_logger.Log(new LogEntry(LoggingEventType.Error,
string.Format("SubmitConverter - Failed to parse Xml value of Parameters field of Submit Action. FormID = {0} - FieldID = {1} - FieldValue = {2}",
form.ID, formSaveActionField.Id, saveActionItem.Parameters), ex));
}

ConvertFieldsToSubmitActionItem(submitAction.destSubmitActionItemName, submitActionValues, buttonItem);
}
else
Expand Down
25 changes: 22 additions & 3 deletions src/WFFM.ConversionTool.Library/Helpers/XmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using WFFM.ConversionTool.Library.Logging;

namespace WFFM.ConversionTool.Library.Helpers
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public static List<string> GetXmlElementNames(string fieldValue)
return elementNames;
}

public static string GetXmlElementValue(string fieldValue, string elementName)
public static string GetXmlElementValue(string fieldValue, string elementName, bool throwOnError = false)
{
if (!string.IsNullOrEmpty(fieldValue) && !string.IsNullOrEmpty(elementName))
{
Expand All @@ -61,12 +62,18 @@ public static string GetXmlElementValue(string fieldValue, string elementName)
Console.WriteLine("XmlHelper - GetXmlElementValue - Failed to parse Xml value - Value = " + fieldValue);
Console.WriteLine(e);
Console.WriteLine();
if (throwOnError)
{
Console.WriteLine("See logs for more details in the logs folder.");
Console.WriteLine();
throw;
}
}
}
return string.Empty;
}

public static XmlNode GetXmlElementNode(string fieldValue, string elementName)
public static XmlNode GetXmlElementNode(string fieldValue, string elementName, bool throwOnError = false)
{
if (!string.IsNullOrEmpty(fieldValue) && !string.IsNullOrEmpty(elementName))
{
Expand All @@ -89,12 +96,18 @@ public static XmlNode GetXmlElementNode(string fieldValue, string elementName)
Console.WriteLine("XmlHelper - GetXmlElementNode - Failed to parse Xml value - Value = " + fieldValue);
Console.WriteLine(e);
Console.WriteLine();
if (throwOnError)
{
Console.WriteLine("See logs for more details in the logs folder.");
Console.WriteLine();
throw;
}
}
}
return null;
}

public static XmlNodeList GetXmlElementNodeList(string fieldValue, string elementName)
public static XmlNodeList GetXmlElementNodeList(string fieldValue, string elementName, bool throwOnError = false)
{
if (!string.IsNullOrEmpty(fieldValue) && !string.IsNullOrEmpty(elementName))
{
Expand All @@ -117,6 +130,12 @@ public static XmlNodeList GetXmlElementNodeList(string fieldValue, string elemen
Console.WriteLine("XmlHelper - GetXmlElementNodeList - Failed to parse Xml value - Value = " + fieldValue);
Console.WriteLine(e);
Console.WriteLine();
if (throwOnError)
{
Console.WriteLine("See logs for more details in the logs folder.");
Console.WriteLine();
throw;
}
}
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/WFFM.ConversionTool.Library/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.3.0")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: AssemblyVersion("1.3.4.0")]
[assembly: AssemblyFileVersion("1.3.4.0")]
2 changes: 1 addition & 1 deletion src/WFFM.ConversionTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void Main(string[] args)
System.Console.WriteLine();
System.Console.WriteLine(" ***********************************************************************");
System.Console.WriteLine(" * *");
System.Console.WriteLine(" * WFFM Conversion Tool - v1.3.3 *");
System.Console.WriteLine(" * WFFM Conversion Tool - v1.3.4 *");
System.Console.WriteLine(" * *");
System.Console.WriteLine(" ***********************************************************************");
System.Console.WriteLine();
Expand Down
4 changes: 2 additions & 2 deletions src/WFFM.ConversionTool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.3.0")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: AssemblyVersion("1.3.4.0")]
[assembly: AssemblyFileVersion("1.3.4.0")]

0 comments on commit f48b162

Please sign in to comment.