Thursday, March 1, 2012

Sitecore and ServiceStack

While trying out Service Stack, I ran into the issue wherein it would not play nicely with Sitecore.

So after a bit of confusion about how location tags worked in web.config, it figured that the solution was as follows:

Include
"|/webservices"
into the IgnoreUrl variable, and add the following at the end of your web.config

<location path="webservices">
<system.web>
<httpHandlers>
<add path="webservices"
type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="webservices" name="ServiceStack.Factory"
type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
</handlers>
</system.webServer>
</location>


As you can see, it's basically the MVC version of the config offered by the site, but with the path of each of the handlers set to the same name as the location.

Wednesday, June 15, 2011

Updating CRM 4.0 Custom Workflows/Plugins

I was running into an issue as I merged a couple of development branches, in that none of the new plugins that were added appeared to work, resulting in a rather unhelpful error message on the function:

Microsoft.Crm.Application.Platform.CustomActivityInfoMetadata.GetActivityInfo(Guid pluginTypeId ...

Searching on the web gained only results suggesting that one reset IIS and restart the Async Service, which did not help the issue.

In the end, it was a combination of assigning a different version value and checking the Modules loaded that we found that despite the resets and re-registrations of the DLLs, the CRM was still using a cached version of the DLL. Deleting the temp ASP directories, solved the issue, and the spice flowed.

Wednesday, August 25, 2010

Switch Case Replacement With Resource Files

Right, one of the problems I've encountered a couple of times in regards to resx files, is that while they're awesome for providing an easily centralised way to store settings, by their very nature, they're not constant values.

So when you try to use something like:
switch ( CheckValue )
{
case ResourceItemFields.PatientResourcesPage:
case ResourceItemFields.TreatmentGuidelinesPage:
...
break;
case ResourceItemFields.ModuleData:
...
break;
}


you run into problems, because the compiler can't reference the values as a constant value, so it throws "A constant value is expected".

One solution around this is something that I've also used in Lua (as that language does not have switch/case at all), and that is to have a dictionary with the values as a function call.

private Dictionary<string, Func<ResourceItem, string>> TitleMapping = new Dictionary<string, Func<ResourceItem, string>>() 
{
{ResourceItemFields.PatientResourcesPage, rItem => rItem.Item[ ResourceItemFields.Title ]},
{ResourceItemFields.TreatmentGuidelinesPage, rItem => rItem.Item[ ResourceItemFields.Title ]},
{ResourceItemFields.ModuleData, rItem => rItem.Item[ ResourceItemFields.ModuleTitle ]},
};

public string Title
{
get
{
if ( TitleMapping.ContainsKey(Item.TemplateName) )
return TitleMapping[ Item.TemplateName ]( this );
return "";
}
}


Easily doable in Lua, as functions are first class values, and now viable in C# with the Func<T,TResult> declaration. You can also use Action<T> if you don't need to return any result. You can probably do this with delegates in 2.0, but the newer Func/Action calls are much easier to grok, imo.

Thursday, July 29, 2010

Sitecore TreeList Items

Straightforward Sitecore one.

If you have a treelist in your item, to access them without going through the rigmarole of splitting the guids up, use the following:


 MultilistField Tags = Sitecore.Context.Item.Fields["Product Tags"];

 Item[] TagList = Tags.GetItems();

Tuesday, June 29, 2010

External config file access

I'm currently using an external config file to organise how settings in this project are running. Thusly, I have an entry in the web.config to the effect of:
<section name="acmeConstruction" type="System.Configuration.NameValueFileSectionHandler" />
and a reference to the external file:
<acmeConstruction configSource="App_Config\acmeConstruction.config"/>
containing
<acmeConstruction>
<add key="Homepage Videos" value="/sitecore/content/Home/Sitewide Content/Homepage Videos"/>
<add key="acmeConstruction" value="abc123"/>
</acmeConstruction>
Of course, now accessing said settings wasn't quite as easy to figure out.


It turns out that you can use
var nvc = ConfigurationManager.GetSection("acmeConstruction") as System.Collections.Specialized.NameValueCollection;


and access the result quite simply. It was surprising the amount of documentation I had to search to find this.