Friday, May 27, 2016

Sitecore EXM: The remote name could not be resolved: 'default-cd-cluster'

While configuring sending EXM messages on Sitecore I faced with problem. Some emails were delivered, others not. Sitecore Email Experience Manager log reported next error:

ERROR Failed to enroll a contact in the engagement plan.
Exception: System.Net.WebException
Message: The remote name could not be resolved: 'default-cd-cluster'
Source: System
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at Sitecore.Modules.EmailCampaign.Core.Gateways.DefaultAnalyticsGateway.EnrollOrUpdateContact(Guid contactId, Guid planId, Guid automationStateId, EcmCustomValues customValues, String[] validStates)
   at Sitecore.Modules.EmailCampaign.Core.Analytics.AutomationStatesManager.EnrollOrUpdateContact(Guid contactId, Guid planId, String stateName, EcmCustomValues customValues, String[] validStates)
   at Sitecore.Modules.EmailCampaign.Core.Dispatch.DispatchManager.EnrollOrUpdateContact(Guid contactId, DispatchQueueItem dispatchQueueItem, Guid planId, String stateName, EcmCustomValues customValues)
   at Sitecore.Modules.EmailCampaign.Core.Dispatch.DispatchTask.OnSendToNextRecipient()

After search this error message I found two articles (first, second) that say the same: you should change Analytics.ClusterName setting. And this solution really helps. This setting is located in Sitecore.Analytics.Tracking.config file and EXM uses it to access to /sitecore/AutomationStates.ashx handler to change contact state in engagement plan.

But, doesn't sound strange? That you should to configure something to start work with Sitecore single instance. How about installation CM/CD/Analytics on one server? Or how about development and testing environments? I know that there are a lot of places where Sitecore as web application requires host name, but everywhere it works automatically. You shouldn't configure something additionally. That's why I decided to customize Sitecore to use 'default-cd-cluster' as key that will be replaced in EXM with current host name. And it was quite easy:

public class CustomAnalyticsGateway : DefaultAnalyticsGateway
{
    public override ContactLockingStatus TryGetContactForUpdate(ID contactId, 
            LeaseOwner leaseOwner, 
            System.TimeSpan leaseDuration, 
            System.TimeSpan timeout, 
            out Sitecore.Analytics.Tracking.Contact contact, 
            out string webClusterName)
    {
       var r = base.TryGetContactForUpdate(contactId, leaseOwner, leaseDuration, timeout, out contact,
           out webClusterName);
       if (webClusterName!= null && webClusterName.Contains("default-cd-cluster"))
       {
           webClusterName = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
       }
       return r;
    }
}

If webClsterName contains 'default-cd-cluster' we change it with current sitename(it also will work if we will replace it with null due to Sitecore EXM later fill it with another value if it is null). And you should let EXM know to use this gateway in your configuration:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <gatewayFactory>
      <analyticsGateway type="YourSolution.CustomAnalyticsGateway, YourSolution"/>
    </gatewayFactory>
  </sitecore>
</configuration>

With this custom class and configuration Email Experience Manager started to work on all machines. And you should not change 'default-cd-cluster' with host name in all your solutions. But don't forget to change this setting when going to live environment.

Monday, May 9, 2016

Commerce Server Desktop Business Tools: Unsuccessful Attempt to Run on Mac OSX

I use .Net framework more than 10 years and long time ago wanted to try Mono. But, for web development it wasn't useful. Users see only frontend and does care what is under hood. Finally I have found task how I can try Mono: it is Commerce Server Desktop Business Tools.

Sitecore Commerce 8.1 powered by Commerce Server is shipped with two option of store management: Desktop Business Tools and Merchandising Manager. Merchandising Manager is SPEAK web application that allows to manage store from web application. Desktop Business Tools is set of Windows applications that also allows to manage store. Desktop Business Tools has much more features comparing Merchandising Manager. And if you have an option what to use I prefer Desktop Business Tools. Mac OSX users don't have such option(same for Linux users if someone uses Linux on desktop). But Desktop Business Tools are written majorly using .Net framework. What if we try to run them using Mono?

First of all you should forget about installer. You should install Desktop Business Tools on Windows machine and then copy all from C:\Program Files (x86)\Commerce Server 11 to your Mac. After copying and attempt to run 

sudo mono -v CatalogManager.exe

you will see that it requires additional assemblies, e.g. CommerceServer.Core.Catalog.dll. They could be added to Mogo GAC using gacutil (very similar as on Windows) or you should copy them from Commerce Server 11\Assemblies to Commerce Server 11\Business User Applications\bin. Trying to run again CatalogManager.exe via Mono again unsuccessful.  Commerce Server Business tools contains references to Windows unmanaged assemblies: msi.dll, kernel32.dll, user32.dll. You couldn't have them on Mac OSX.  But you could remove this references from code by changing Commerce Server Desktop Business Tools assemblies. Fortunately these reference are not related with business logic and you can replace with something that have similar logic or make stubs that return constants for some methods. Now we can see empty Catalog Manager window, but still get error: 



"System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) <0x2e486d8 + 0x0016b> in <filename unknown>:0 "

It is error in Mono itself so I stopped here. Google says that it is probably Mono bug. But Mono is cross-platform. Let's check if we can run Commerce Server Desktop Business Tools on Windows and Linux using Mono.

On Windows it works badly: there are a lot of appearance bugs and wizards don't work at all.

However you don't need to run it on Windows by Mono, here you have .Net framework.
On Ubuntu it works in a same way as on Windows, but probably looks a little bit better:


Conclusion: I managed to run Commerce Server Desktop Business Tools with Mono on Windows and Ubuntu. But as it was not designed to work on this platform it is very buggy. You can use it for management already existed content(everything that doesn't require wizards). For Mac OS I faced with Mono error, but I think that it is possible to run tools on Mac, probably you should try different Mono versions. And you always are able to setup Desktop Business Tools on Windows server and use RDP to it to manage anything in your store. It is much more better way!

P.S. I skipped few actions in description to make it faster:
  • Changing location of configuration files (there is no AppData folder on Mac or Linux)
  • Disabling tracing (it doesn't work)
And I don't recommend to use Commerce Server Desktop Business Tools anywhere except Windows platform. One thing that addition could be checked: how it is running under Wine? But it task for next time.