Skip to content

Commit

Permalink
Upgraded code for umbraco 8.4.1 and umbraco forms 8.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
harikrishna43 committed Feb 4, 2020
1 parent d3c50e3 commit 67336bd
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 111 deletions.
2 changes: 1 addition & 1 deletion UFMailchimpWorkFlowType/Publish Package.BAT
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nuget push UmbracoForm.MailChimp.WorkFlow.2.1.1.nupkg oy2l5x7rwewc6nn3l6dqlrlfcdne6zoetorp7optanbaye -Source https://api.nuget.org/v3/index.json
nuget push UmbracoForm.MailChimp.WorkFlow.3.0.0.nupkg oy2l5x7rwewc6nn3l6dqlrlfcdne6zoetorp7optanbaye -Source https://api.nuget.org/v3/index.json
pause
71 changes: 36 additions & 35 deletions UFMailchimpWorkFlowType/UFMailChimpWorkFlowType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Newtonsoft.Json;
using Umbraco.Forms.Core;
using Umbraco.Forms.Core.Enums;
using Umbraco.Forms.Core.Persistence.Dtos;
using Umbraco.Forms.Core.Providers.Models;
using UmbracoSetting = Umbraco.Forms.Core.Attributes.Setting;

Expand All @@ -20,16 +21,16 @@ public class UFMailChimpWorkFlowType : WorkflowType
{
#region Settings

[UmbracoSetting("API KEY", view = "TextField", description = "Enter the Mailchimp API key.")]
[UmbracoSetting("API KEY", View = "TextField", Description = "Enter the Mailchimp API key.")]
public string ApiKey { get; set; }

[UmbracoSetting("List ID", view = "TextField", description = "Enter the Mailchimp List ID.")]
[UmbracoSetting("List ID", View = "TextField", Description = "Enter the Mailchimp List ID.")]
public string ListID { get; set; }

[UmbracoSetting("Fields", view = "FieldMapper", description = "Map the needed fields .Minimum Email field for subscribe.")]
[UmbracoSetting("Fields", View = "FieldMapper", Description ="Map the needed fields .Minimum Email field for subscribe.")]
public string Fields { get; set; }

[UmbracoSetting("Tags", view = "TextField", description = "List of Tags. Separate by semicolon ';'. Tag must be created before being used. i.e: User; Help Center")]
[UmbracoSetting("Tags", View = "TextField", Description ="List of Tags. Separate by semicolon ';'. Tag must be created before being used. i.e: User; Help Center")]
public string Tags { get; set; }

#endregion
Expand All @@ -54,37 +55,6 @@ public override List<Exception> ValidateSettings()
return exceptionList;
}

public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
{
try
{
var data = ParseEmailAndMergeFields(record, this.Fields);
if (string.IsNullOrEmpty(data.Item1))
{
throw new Exception("Email is missing");
}

Task.Run(async () =>
{
await SubscribeMember(data.Item1, data.Item2);

var tagNames = ParseTags(this.Tags);
if (tagNames.Count() > 0)
{
await TagMember(data.Item1, tagNames);
}
});

return WorkflowExecutionStatus.Completed;

}
catch (Exception ex)
{
Umbraco.Core.Logging.LogHelper.Error<string>("error : UFMailchimp FlowType", ex);
return WorkflowExecutionStatus.Failed;
}
}

private async Task SubscribeMember(string email, Dictionary<string, object> mergeFields)
{
var mc = new MailChimpManager(this.ApiKey);
Expand Down Expand Up @@ -179,6 +149,37 @@ private static bool IsEmail(string str)
return Regex.IsMatch(str, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
}

public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
{
try
{
var data = ParseEmailAndMergeFields(record, this.Fields);
if (string.IsNullOrEmpty(data.Item1))
{
throw new Exception("Email is missing");
}

Task.Run(async () =>
{
await SubscribeMember(data.Item1, data.Item2);

var tagNames = ParseTags(this.Tags);
if (tagNames.Count() > 0)
{
await TagMember(data.Item1, tagNames);
}
});

return WorkflowExecutionStatus.Completed;

}
catch (Exception ex)
{
Umbraco.Core.Composing.Current.Logger.Error(typeof(UFMailChimpWorkFlowType), ex);
return WorkflowExecutionStatus.Failed;
}
}

#endregion
}
}
Loading

0 comments on commit 67336bd

Please sign in to comment.