SHARE
TWEET

Untitled

a guest Aug 17th, 2018 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace Sitecore.Feature.EmailConfiguration.Facets{
  2. [Serializable]
  3. [FacetKey(DefaultFacetKey)]
  4. public class EmailUser:Sitecore.XConnect.Facet
  5. {
  6.     public const string DefaultFacetKey = "EmailUser";
  7.     public string Username { get; set; }
  8.     public string Password { get; set; }
  9.     public EmailUser()
  10.     {
  11.  
  12.     }
  13. }
  14. }
  15.    
  16. namespace Sitecore.Feature.EmailConfiguration.Models
  17.     {
  18.     public  class EmailUserModel
  19.     {
  20.         public static XdbModel Model { get; } = EmailUserModel.BuildModel();
  21.  
  22.         public static XdbModel BuildModel()
  23.         {
  24.             XdbModelBuilder modelBuilder = new XdbModelBuilder("EmailUserModel", new XdbModelVersion(0, 1));
  25.  
  26.             modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
  27.             modelBuilder.DefineFacet<Contact, EmailUser>(EmailUser.DefaultFacetKey);
  28.  
  29.             return modelBuilder.BuildModel();
  30.         }
  31.     }
  32. }
  33.    
  34. namespace Sitecore.Feature.EmailConfiguration.Mappers
  35. {
  36.     public class EmailUserFacetMapper : IFacetMapper
  37.     {
  38.         private readonly PreferredEmailFacetMapper mapper;
  39.  
  40.         public EmailUserFacetMapper(): this(CollectionModel.FacetKeys.AddressList)
  41.         {
  42.         }
  43.         public EmailUserFacetMapper(string facetName)
  44.         {
  45.             Assert.ArgumentNotNull(facetName, nameof(facetName));
  46.  
  47.             this.FacetName = facetName;
  48.         }
  49.  
  50.         public string FacetName { get; }
  51.  
  52.         public MappingResult Map(string facetKey, Facet facet, ContactMappingInfo mappings, string[] data)
  53.         {
  54.             using (EventLog eventLog = new EventLog("Application"))
  55.             {
  56.                 eventLog.Source = "Application";
  57.                 eventLog.WriteEntry("EmailUserFacetMapperCalled facetKey:" +facetKey+" data"+ string.Join("; ", data));
  58.             }
  59.  
  60.             if (facetKey != this.FacetName)
  61.             {
  62.                 return new NoMatch(facetKey);
  63.             }
  64.  
  65.             var emailUser = new EmailUser();
  66.  
  67.             var username = mappings.GetValue("EmailUser_Username", data);
  68.             var password = mappings.GetValue("EmailUser_Password",data);
  69.  
  70.             if (!string.IsNullOrEmpty(username)) { emailUser.Username = username; }
  71.             if (!string.IsNullOrEmpty(password)) { emailUser.Password = password; }
  72.  
  73.             return (MappingResult)new FacetMapped(facetKey, (Facet) emailUser);
  74.         }
  75.     }
  76. }
  77.    
  78. namespace Sitecore.Feature.EmailConfiguration.TokenMaps
  79. {
  80.     public class EmailUserPropertyTokenMap : DefaultRecipientPropertyTokenMap
  81.     {
  82.         protected static readonly MethodInfo GetUsernameValue = typeof(FacetExtensions).GetMethod(nameof(FacetExtensions.GetUsernameValue), new[] { typeof(EmailUser) });
  83.         protected static readonly MethodInfo GetPasswordValue = typeof(FacetExtensions).GetMethod(nameof(FacetExtensions.GetPasswordValue), new[] { typeof(EmailUser) });
  84.  
  85.  
  86.  
  87.  
  88.         static EmailUserPropertyTokenMap()
  89.         {
  90.             if (TokenBindings == null)
  91.             {
  92.                 TokenBindings = new Dictionary<Token, RecipientPropertyTokenBinding>();
  93.             }
  94.             RecipientPropertyTokenBinding usernameTokenBinding = RecipientPropertyTokenBinding.Build<EmailUser>(new Token("username"), null, GetUsernameValue);
  95.             RecipientPropertyTokenBinding passwordTokenBinding = RecipientPropertyTokenBinding.Build<EmailUser>(new Token("password"), null, GetPasswordValue);
  96.  
  97.             TokenBindings.Add(usernameTokenBinding.Token, usernameTokenBinding);
  98.             TokenBindings.Add(passwordTokenBinding.Token, passwordTokenBinding);
  99.         }
  100.     }
  101.     public static class FacetExtensions
  102.     {
  103.         public static string GetUsernameValue(this EmailUser facet)
  104.         {
  105.             return facet.Username;
  106.         }
  107.  
  108.         public static string GetPasswordValue(this EmailUser facet)
  109.         {
  110.             return facet.Password;
  111.         }
  112.     }
  113. }
  114.    
  115. <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set">
  116.   <sitecore>
  117.     <exm>
  118.       <dispatchTask type="Sitecore.Feature.EmailConfiguration.DispatchTasks.EmailUserDispatchTask, Sitecore.Feature.EmailConfiguration" patch:instead="*[@type='Sitecore.EmailCampaign.Cm.Dispatch.DispatchTask, Sitecore.EmailCampaign.Cm']">
  119.         <param ref="exm/dispatchFailedTaskPool"/>
  120.         <param desc="recipientValidator" ref="exm/recipientValidator" />
  121.         <param desc="contactService" ref="exm/contactService" />
  122.         <param desc="dataProvider" ref="exm/dataProvider" />
  123.         <param desc="itemUtil" ref="exm/itemUtil" />
  124.         <param desc="eventDataService" ref="exm/eventDataService" />
  125.         <param desc="dispatchManager" ref="exm/dispatchManager" />
  126.         <param desc="emailAddressHistoryManager" ref="exm/emailAddressHistoryManager" />
  127.         <param desc="recipientManagerFactory" ref="exm/recipientManagerFactory" />
  128.         <param desc="sentHistoryManager" ref="exm/sentHistoryManager" />
  129.       </dispatchTask>
  130.     </exm>
  131.     <recipients>
  132.       <recipientPropertyTokenMap type="Sitecore.Feature.EmailConfiguration.TokenMaps.EmailUserPropertyTokenMap, Sitecore.Feature.EmailConfiguration" singleInstance="true" patch:instead="*[@type='Sitecore.Modules.EmailCampaign.Core.Personalization.DefaultRecipientPropertyTokenMap, Sitecore.EmailCampaign']" />
  133.     </recipients>
  134.  
  135.     <import>
  136.       <facetMappers hint="list:Add">
  137.       <facetMapper type="Sitecore.Feature.EmailConfiguration.Mappers.EmailUserFacetMapper,Sitecore.Feature.EmailConfiguration" />
  138.         </facetMappers>
  139.     </import>
  140.     <settings>
  141.       <setting name="ListManagement.Import.FacetsToMap">
  142.         <set:attribute name="value">Emails|Personal|Addresses|EmailUser</set:attribute>
  143.       </setting>
  144.     </settings>
  145.  
  146.  <xconnect>
  147.       <runtime type="Sitecore.XConnect.Client.Configuration.RuntimeModelConfiguration,Sitecore.XConnect.Client.Configuration">
  148.         <schemas hint="list:AddModelConfiguration">
  149.               <schema name="EmailUserModel" type="Sitecore.XConnect.Client.Configuration.StaticModelConfiguration,Sitecore.XConnect.Client.Configuration">
  150.                   <param desc="modeltype">Sitecore.Feature.EmailConfiguration.Models.EmailUserModel,Sitecore.Feature.EmailConfiguration</param>
  151.               </schema>
  152.         </schemas>
  153.       </runtime>
  154.     </xconnect>
  155.  
  156.   </sitecore>
  157. </configuration>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top