Skip to content

Commit

Permalink
Completed the recipient provider cleanup
Browse files Browse the repository at this point in the history
Now also works for jobs, not just lists.
  • Loading branch information
evest committed Apr 17, 2015
1 parent eca4c92 commit a44f02f
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 236 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CommerceUsersProvider.ascx.cs" Inherits="BVNetwork.EPiSendMail.CommerceProvider.modules.bvn.SendMail.Plugin.WorkItemProviders.CommerceUsersProvider" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CommerceUsersProvider.ascx.cs"
Inherits="BVNetwork.EPiSendMail.CommerceProvider.Plugin.ItemProviders.CommerceUsersProvider" %>
<asp:Panel ID="Panel1" runat="server" DefaultButton="cmdCustomerViewEmailAddresses">
<b>Select Commerce users</b>
<br />
<asp:DropDownList runat="server" ID="dropListUserViews" enableviewstate="true"
style="margin-top: 0.7em;"/>
<asp:DropDownList runat="server" ID="dropListUserViews" enableviewstate="true" style="margin-top: 0.7em;"/>
<br />
<asp:Button id="cmdCustomerViewEmailAddresses" runat="server"
Text="Add" style="margin-top: 1em;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
using System.Collections.Generic;
using BVNetwork.EPiSendMail.DataAccess;
using BVNetwork.EPiSendMail.Plugin;
using BVNetwork.EPiSendMail.Plugin.ItemProviders;
using BVNetwork.EPiSendMail.Plugin.WorkItemProviders;
using EPiServer.Framework.Localization;
using Mediachase.BusinessFoundation.Core;
using Mediachase.BusinessFoundation.Data.Business;
using Mediachase.Commerce.Security;

namespace BVNetwork.EPiSendMail.CommerceProvider.modules.bvn.SendMail.Plugin.WorkItemProviders
namespace BVNetwork.EPiSendMail.CommerceProvider.Plugin.ItemProviders
{
public partial class CommerceUsersProvider : System.Web.UI.UserControl, IWorkItemProvider
public partial class CommerceUsersProvider : System.Web.UI.UserControl, IEmailImporterProvider
{
private Job _job;
private IJobUi _jobUi;
private IEmailImporter _job;
private IShowFeedback _jobUi;
private const string MetaClassName = "Contact";

protected void Page_Load(object sender, EventArgs e)
Expand All @@ -37,7 +38,7 @@ private void LoadCommerceProfileViewsGroups()
List<KeyValuePair<string, string>> allCustomerViews = new List<KeyValuePair<string, string>>();
foreach (ListViewProfile listViewProfile in systemProfiles)
{
arrayList.Add((object)listViewProfile.Id);
arrayList.Add((object) listViewProfile.Id);
string name = listViewProfile.Name;
if (name.StartsWith("{"))
{
Expand All @@ -48,21 +49,21 @@ private void LoadCommerceProfileViewsGroups()
}
allCustomerViews.Add(new KeyValuePair<string, string>(listViewProfile.Id, " " + name));
}
ListViewProfile[] userProfiles = ListViewProfile.GetProfiles(MetaClassName, "EntityList", SecurityContext.Current.CurrentContactId);
ListViewProfile[] userProfiles = ListViewProfile.GetProfiles(MetaClassName, "EntityList",
SecurityContext.Current.CurrentContactId);
foreach (ListViewProfile listViewProfile in userProfiles)
{
if (!arrayList.Contains((object)listViewProfile.Id))
allCustomerViews.Add(new KeyValuePair<string, string>(listViewProfile.Id, " " + listViewProfile.Name));
if (!arrayList.Contains((object) listViewProfile.Id))
allCustomerViews.Add(new KeyValuePair<string, string>(listViewProfile.Id,
" " + listViewProfile.Name));
}
dropListUserViews.DataSource = allCustomerViews;
dropListUserViews.DataTextField = "Value";
dropListUserViews.DataValueField = "Key";
dropListUserViews.DataBind();
}
}


}

protected void cmdCustomerViewEmailAddresses_Click(object sender, EventArgs e)
{
ListViewProfile selectedProfile = ListViewProfile.Load(MetaClassName, dropListUserViews.SelectedValue, "EntityList");
Expand Down Expand Up @@ -117,15 +118,11 @@ protected void cmdCustomerViewEmailAddresses_Click(object sender, EventArgs e)

}

#region IRecipientItemProvider Members


#endregion

public void Initialize(Job job, IJobUi jobUi)
public void Initialize(IEmailImporter importer, IShowFeedback feedbackUi)
{
_job = job;
_jobUi = jobUi;
_job = importer;
_jobUi = feedbackUi;

}
}
}
11 changes: 0 additions & 11 deletions src/Newsletter/EPiCode.Newsletter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@
<Compile Include="Plugin\GettingStarted.ascx.designer.cs">
<DependentUpon>GettingStarted.ascx</DependentUpon>
</Compile>
<Compile Include="Plugin\WorkItemProviderDescriptor.cs" />
<Compile Include="Plugin\Jobs\WorkItemsEdit.aspx.cs">
<DependentUpon>WorkItemsEdit.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
Expand Down Expand Up @@ -444,13 +443,6 @@
<Compile Include="Plugin\RecipientLists\RecipientListDeleted.aspx.designer.cs">
<DependentUpon>RecipientListDeleted.aspx</DependentUpon>
</Compile>
<Compile Include="Plugin\RecipientLists\RemoveRecipients.ascx.cs">
<DependentUpon>RemoveRecipients.ascx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Plugin\RecipientLists\RemoveRecipients.ascx.designer.cs">
<DependentUpon>RemoveRecipients.ascx</DependentUpon>
</Compile>
<Compile Include="Plugin\RecipientLists\NewRecipientList.aspx.cs">
<DependentUpon>NewRecipientList.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
Expand Down Expand Up @@ -595,9 +587,6 @@
<SubType>ASPXCodeBehind</SubType>
</Content>
<Content Include="Plugin\RecipientLists\RecipientListDeleted.aspx" />
<Content Include="Plugin\RecipientLists\RemoveRecipients.ascx">
<SubType>ASPXCodeBehind</SubType>
</Content>
<Content Include="Plugin\RecipientLists\NewRecipientList.aspx" />
<Content Include="Plugin\RecipientLists\ListEdit.aspx">
<SubType>ASPXCodeBehind</SubType>
Expand Down
12 changes: 11 additions & 1 deletion src/Newsletter/Library/EPiMailEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Configuration;
using System.Net;
using System.Net.Mail;
using BVNetwork.EPiSendMail.Configuration;
using BVNetwork.EPiSendMail.DataAccess;
using EPiServer.Core;

Expand Down Expand Up @@ -112,9 +113,18 @@ public MailSenderBase GetMailSender()
public string GetMailSenderTypeName()
{
const string defSender = "MailSenderNetSmtp";
string typeName = Configuration.NewsLetterConfiguration.MailSenderTypename;

// First get from new config section
string typeName = NewsletterConfigurationSection.Instance.SenderType;
if(string.IsNullOrEmpty(typeName))
{
// Fallback to previous way of configuration in appSettings
typeName = NewsLetterConfiguration.MailSenderTypename;
}

if (typeName == null)
{
// Last resort - use SMTP as default as sensible default
typeName = this.GetType().Namespace + "." + defSender + ", " + this.GetType().Assembly.FullName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
success: function (data) {
var html = $('#successEPiServerGroupTemplate').render(data);
$('#pnlSendStatus').html(html);
// Ask to update the total count too
if (typeof updateListInfo === 'function') {
updateListInfo();
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.debug(jqXHR, textStatus, errorThrown);
Expand Down
5 changes: 5 additions & 0 deletions src/Newsletter/Plugin/ItemProviders/RecipientProvider.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
if (typeof updateListInfo === 'function') {
updateListInfo();
}
// Attempt to update the job status
if (typeof updateStatus === 'function') {
updateStatus();
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.debug(jqXHR, textStatus, errorThrown);
Expand Down
2 changes: 0 additions & 2 deletions src/Newsletter/Plugin/ItemProviders/RecipientProvider.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace BVNetwork.EPiSendMail.Plugin.ItemProviders
public partial class RecipientProvider : System.Web.UI.UserControl, IEmailImporterProvider
{
public string ApiUrl = null;
private IEmailImporter _importer;
private IShowFeedback _feedbackCtrl;

protected void Page_Load(object sender, EventArgs e)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Newsletter/Plugin/Jobs/JobEdit.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
$('#pnlSendStatus').html(html);
// Attempt to update the job status
if (updateStatus)
if (typeof updateStatus === 'function') {
updateStatus();
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.debug(jqXHR, textStatus, errorThrown);
Expand Down Expand Up @@ -130,7 +131,7 @@

<div class="col-md-12">
<h2>Test the Newsletter</h2>
<p>Send a test newsletter to make sure it looks OK. Add email addresses to the text box, separated by comma or newline.
<p>Send a test newsletter to make sure it looks OK. Add email addresses separated by comma or newline.
</p>
<p>
<b>Note!</b> The email subject will show "(TEST)"
Expand Down
15 changes: 8 additions & 7 deletions src/Newsletter/Plugin/Jobs/JobUiProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using BVNetwork.EPiSendMail.Plugin.ItemProviders;
using BVNetwork.EPiSendMail.Plugin.WorkItemProviders;

namespace BVNetwork.EPiSendMail.Plugin
{
public abstract class JobUiProviderBase : JobUiUserControlBase
{
const string PROVIDER_SUFFIX = "Provider";
private List<WorkItemProviderDescriptor> _workItemProviders = new List<WorkItemProviderDescriptor>();
private Dictionary<string, Control> _providerCtrls = new Dictionary<string, Control>();
private readonly List<RecipientListProviderDescriptor> _workItemProviders = new List<RecipientListProviderDescriptor>();
private readonly Dictionary<string, Control> _providerCtrls = new Dictionary<string, Control>();

public List<WorkItemProviderDescriptor> WorkItemProviders
public List<RecipientListProviderDescriptor> WorkItemProviders
{
get
{
Expand Down Expand Up @@ -41,7 +42,7 @@ public abstract Control UiContainer
protected void LoadProviderControls()
{
// Add controls from descriptors
foreach (WorkItemProviderDescriptor provider in _workItemProviders)
foreach (RecipientListProviderDescriptor provider in WorkItemProviders)
{
Control ctrl = null;
ctrl = Page.LoadControl(provider.UserControlUrl);
Expand All @@ -56,7 +57,7 @@ protected void LoadProviderControls()
protected void AddProvidersToUiContainer()
{
// Hide the other controls
foreach (KeyValuePair<string, Control> keyValue in _providerCtrls)
foreach (KeyValuePair<string, Control> keyValue in ProviderControls)
{
ProviderContainer.Controls.Add(keyValue.Value);
}
Expand All @@ -77,7 +78,7 @@ protected override void OnInit(EventArgs e)

}

protected void AddProviderWithChecks(List<WorkItemProviderDescriptor> providers, WorkItemProviderDescriptor provider)
protected void AddProviderWithChecks(List<RecipientListProviderDescriptor> providers, RecipientListProviderDescriptor provider)
{
if (provider.ProviderControlExists == true)
providers.Add(provider);
Expand Down Expand Up @@ -107,7 +108,7 @@ protected void ShowWorkItemProvider()
ctrl = _providerCtrls[CurrentProvider];
ctrl.Visible = true;
// Initialize provider
((IWorkItemProvider)ctrl).Initialize(NewsletterJob, this);
((IEmailImporterProvider)ctrl).Initialize(NewsletterJob, this);
// Databind it, to have it load it's values
ctrl.DataBind();

Expand Down
2 changes: 1 addition & 1 deletion src/Newsletter/Plugin/Jobs/JobUiUserControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace BVNetwork.EPiSendMail.Plugin
{
public class JobUiUserControlBase : EPiServer.UserControlBase, IJobUi
public class JobUiUserControlBase : EPiServer.UserControlBase, IJobUi, IShowFeedback
{
private Job _job;
private int _jobId = -1;
Expand Down
15 changes: 4 additions & 11 deletions src/Newsletter/Plugin/Jobs/RemoveWorkItems.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,18 @@ protected override void InitializeWorkItemDescriptors()

// Build the provider list, this will be configurable later

WorkItemProviderDescriptor recipientListProvider =
new WorkItemProviderDescriptor("RecipientList",
RecipientListProviderDescriptor recipientListProvider =
new RecipientListProviderDescriptor("RecipientList",
"Select one of your Block Lists",
BVNetwork.EPiSendMail.Configuration.NewsLetterConfiguration.GetModuleBaseDir() + "/plugin/workitemproviders/RecipientRemoveprovider.ascx");

AddProviderWithChecks(WorkItemProviders, recipientListProvider);

WorkItemProviderDescriptor textProvider =
new WorkItemProviderDescriptor("TextImportRemove",
RecipientListProviderDescriptor textProvider =
new RecipientListProviderDescriptor("TextImportRemove",
"Remove from manually entered email addresses",
BVNetwork.EPiSendMail.Configuration.NewsLetterConfiguration.GetModuleBaseDir() + "/plugin/workitemproviders/TextRemoveProvider.ascx");
AddProviderWithChecks(WorkItemProviders, textProvider);

//WorkItemProviderDescriptor sidGroupProvider =
// new WorkItemProviderDescriptor("EPiServerGroup",
// "Add email addresses from an EPiServer Group",
// BVNetwork.EPiSendMail.Configuration.NewsLetterConfiguration.GetModuleBaseDir() + "/plugin/workitemproviders/EPiServerGroupProvider.ascx");
//AddProviderWithChecks(_workItemProviders, sidGroupProvider);

}

protected void Page_Load(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Newsletter/Plugin/Newsletters.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="col-lg-12">
<h1>Newsletters</h1>
<%-- Newsletters that has not been sent, or that is in progress of beeing sent. --%>
<asp:Repeater runat="server" ID="rptNewsLettersInProgress" >
<asp:Repeater runat="server" ID="rptNewsLettersInProgress" EnableViewState="False" >
<HeaderTemplate>
<table class="table table-striped">
<thead>
Expand Down
2 changes: 1 addition & 1 deletion src/Newsletter/Plugin/RecipientLists/AddRecipients.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Inherits="BVNetwork.EPiSendMail.Plugin.AddRecipients" %>

<h2>Add Recipients</h2>
Please choose a provider for importing more recipients:
Please choose a provider for importing recipients:
<br />
<asp:Panel ID="pnlImportProviders" runat="server" style="padding-left: 1.5em;">
<asp:Repeater runat="server" ID="lstRecipientProviders2">
Expand Down
8 changes: 0 additions & 8 deletions src/Newsletter/Plugin/RecipientLists/ListEdit.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@
<asp:Panel ID="pnlAddEmailAddressesToList" runat="server">
<EPiSendMail:AddRecipients runat="server" id="ucAddRecipients" />
</asp:Panel>

<%-- Remove recipiants items from different sources
NOTE! This is not working yet, the providers can only add, not remove
--%>
<asp:Panel ID="pnlRemoveFromList" runat="server" Visible="false">
<EPiSendMail:removerecipients runat="server" id="ucRemoveRecipients" />
</asp:Panel>

</div>
<div class="col-lg-3 well" style="padding-top: 1em;">
<%-- Status of list --%>
Expand Down
18 changes: 0 additions & 18 deletions src/Newsletter/Plugin/RecipientLists/ListEdit.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions src/Newsletter/Plugin/RecipientLists/RemoveRecipients.ascx

This file was deleted.

Loading

0 comments on commit a44f02f

Please sign in to comment.