Monday, February 18, 2013

Extension of Sitecore ECM ContactProfile

In this post is described a way how Email Campaign Manager personalization fields could be extended with calculated fields. By default you can output user profile fields that are present in /sitecore/templates/Modules/EmailCampaign/ Subscriber template. You can use this profile fields in email by using profile names that are surrounded by dollar signs(e.g.: $firstname$, $lastname$). Calculated user profile fields could be useful when you want to output data based on current date.
Sitecore Email Campaign Manager has a lot of abilities to be extended. One of the ways to extend it is change TypeResolver in Sitecore.EmailCampaign.config:
<TypeResolver type="YourNamespace.TypeResolver, YourAssembly" singleInstance="true" />
You are able to override in TypeResolver functions:
ContactList CreateCorrectContactList(string systemName)
Contact GetCorrectAnonymouseFromEmail(string email, ManagerRoot root)
Contact GetCorrectContactFromName(string userName)
ContactList GetCorrectContactListFromName(string contactListName)
ContactProfile GetCorrectContactProfile()
ManagerRoot GetCorrectManagerRootObject(Item rootItem)
LocalSettingsBase GetCorrectLocalSettingsObject(ManagerRoot root)
MessageItem GetCorrectMessageObject(Item item)
PostalEngineBase GetCorrectPostalEngine()
TargetAudience GetCorrectTargetAudience(Item item)

In our case we override GetCorrectContactProfile function:
namespace YourNamespace
{
  /// <summary>
  /// Extended Type Resolver to return extended contact profile
  /// </summary>
  public class TypeResolver : Sitecore.Modules.EmailCampaign.Core.TypeResolver
  {
    /// <summary>
    /// Gets the correct contact profile.
    /// </summary>
    /// <returns></returns>
    public override Sitecore.Modules.EmailCampaign.ContactProfile GetCorrectContactProfile()
    {
      return new ContactProfile();
    }
  }
}

The new ContactProfile is inherited from Sitecore.Modules.EmailCampaign.ContactProfile:
namespace YourNamespace
{
  /// <summary>
  /// Contact profile extended with ability to get calculated user profile properties
  /// </summary>
  public class ContactProfile : Sitecore.Modules.EmailCampaign.ContactProfile
  {
    /// <summary>
    /// Gets a named property value.
    /// </summary>
    /// <param name="propertyName">Name of the property.
    ///             </param>
    /// <returns>
    /// The value.
    /// </returns>
    protected override object GetPropertyValueCore(string propertyName)
    {
      //Here should be your code that will calculate Contact Profile value
    }

    /// <summary>
    /// Gets or sets a profile property value indexed by the property name.
    /// </summary>
    /// <param name="propertyName">The name of the profile property.</param>
    /// <returns>
    /// The value of the specified profile property, typed as object.
    /// </returns>
    public override string this[string propertyName]
    {
      get
      {
        //Here should be your code that will calculate Contact Profile value
      }
      set
      {
        base[propertyName] = value;
      }
    }
  }
}

Now you are able to use your own calculated values for personalization of emails.

Saturday, February 16, 2013

Sitecore Media Library Features & WebClient Error Relation

You will get “Web Client Service is Unavailable” while installation on Windows 2008 server without any configuration. There is a good article that describes possible problems. But if you don’t follow prerequisites described in article you still should be able to install Sitecore. And major part of functionality will work. But WebDav will not work.

webservicenotavailable

WebDAV - Web Distributed Authoring and Versioning. It is an extension of the Hypertext Transfer Protocol. WebDav allows user to work with files saved on web server. It used in Sitecore Media Library for drag and drop ability and other files operations.

Capture111

WebDav requires “Desktop experience” server feature. The Desktop Experience feature allows you to use Windows 7 features on your Windows Server 2008.

Also, don’t forget to add your Sitecore site to trusted sites or allows IE to load to launch programs and files in an iframe. Otherwise you will get empty drag and drop window without ability to edit folder content.

Iframe