Custom resolving

Customizing the resolving process involves manipulating the list of items to publish that results from a publish action.

The following example illustrates which steps to take to customize resolving. In this example, we want to remove all Components from the list of resolved items, unless they are based on certain Schemas. These Schemas are configured in a custom configuration section in the Content Manager configuration file.

Create a custom resolver class in .NET

To start, implement your business logic in a custom resolver class. This class implements the IResolver interface, found in the Tridion.ContentManager.Publishing.Resolving namespace.

In this example, the custom resolver reads a set of Schemas, loops through the resolved items as produced by Content Manager, and excluded all Components based on a Schema not listed in the set of Schemas.

public class MyCustomResolver : IResolver
{
	// Get the value of schemaTitles from the custom configuration section for this custom resolver
	private string SCHEMA_TITLES = Config.GetConfig("My.Tridion.CustomResolving", "schemaTitles");

	#region IResolver Members
	// This Resolve method executes after the default resolver has done its job and produced a set of resolved items.
	public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, ISet<ResolvedItem> resolvedItems)
	{
		// If the item being resolved currently is not a Component, skip it.
		if (!(item is Component))
		{
			return;
		}
		else
		{
			// Also skip the item if it is a Component, but it is not based on a configured Schema.
			Component component = item as Component;
			if (ConfigContains(component.Schema.Title))
			{
				// If this is a Component based on one of the configured Schemas, loop over the list of resolved items.
				// Assemble a list of those items that meet one or more of the following conditions:
				// 1. Not a Component
				// 2. Identical to the current item
				// 3. Based on a Schema that is _not_ listed among those configured.

				List<ResolvedItem> tempItems = new List<ResolvedItem>();
				foreach (ResolvedItem resolvedItem in resolvedItems)
				{
					if (!(resolvedItem.Item is Component) || 
						resolvedItem.Item.Id == item.Id || 
						!ConfigContains(((Component)resolvedItem.Item).Schema.Title))
					{
						tempItems.Add(resolvedItem);
					}
					// Now empty the resolvedItems array and copy all the saved items into it.
					resolvedItems.Clear();
					foreach (ResolvedItem tempResolvedItem in tempItems)
					{
						resolvedItems.Add(tempResolvedItem);
					}
				}
			}
		}
	}
	#endregion
}
Create a .NET assembly for this file and add it to your Content Manager configuration

Create an assembly from this MyCustomResolver .NET class and add it to the Global Assembly Cache (GAC). Next, access your Content Manager server and open the Content Manager configuration file in a plain-text or XML editor. This file is called Tridion.ContentManager.config and is located in the config\ subfolder of %TRIDION_HOME% (defaults to C:\Program Files (x86)\Tridion\).

In this file, find the <resolving> section, which contains a <mappings> section with a number of add elements, one for each publishable item type. Here is one such add element:

<add itemType="Tridion.ContentManager.CommunicationManagement.PageTemplate">
	<resolvers>
		<add type="Tridion.ContentManager.Publishing.Legacy.Resolving.PageTemplateResolver" assembly="Tridion.ContentManager.Publishing.Legacy, Version=5.4.0.1110, Culture=neutral, PublicKeyToken=360aac4d3354074b"/>
	</resolvers>
</add>

The itemType attribute indicates the type of items being resolved (Page Template in this case) and the <resolvers> element contains a list of resolvers for this type (by default, just the one standard resolver that SDL Tridion ships with), specifying the class and assembly information.

To add your custom resolver, add a new add element below the one already present. For example, to add the MyCustomResolver class above to the list of resolvers for the Component item type, add a new add element inside the <resolvers> and specify the class and assembly information:

<add itemType="Tridion.ContentManager.ContentManagement.Component">
	<resolvers>
		<add type="Tridion.ContentManager.Publishing.Legacy.Resolving.ComponentResolver" assembly="Tridion.ContentManager.Publishing.Legacy, Version=5.4.0.1110, Culture=neutral, PublicKeyToken=360aac4d3354074b"/>
		<add type="MyCompany.Tridion.CustomResolving.MyCustomResolver" assembly="MyCompany.Tridion.CustomResolving, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0565a33f351b321"/>
	</resolvers>
</add>
Optional: add custom configuration

In our example, the MyCustomerResolver class required custom configuration. If your custom resolver also requires configuration, SDL Tridion expects to find such configuration in the same Tridion.ContentManager.config file, in the section named as specified in the code (in the code example above, My.Tridion.CustomResolving). To create and specfiy such a section, do the following:

  • In the <configSections> section at the top of the file, add a section element, provide a name, and set the type attribute to a class that can handle the contents of the section. In this example, the section will contain a simple named property, for which the default .NET class System.Configuration.NameValueSectionHandler is used:

    <section name="My.Tridion.CustomResolving" type="System.Configuration.NameValueSectionHandler" />
  • Next, add a configuration section with the name you specified at the bottom of the file, and fill it with content that the class you specified can handle. In this example, the section contains an add element with a key and a value attribute:

    <My.Tridion.CustomResolving>
    	<add key="schemaTitles" value="FullArticleSchema" />
    </My.Tridion.CustomResolving>
Apply your changes
Finally, save and close the Tridion.ContentManager.config file and from your list of Windows Services, restart all Windows services that start with Tridion Content Manager. Also restart IIS and the SDL Tridion Content Manager COM+ application. This applies your changes.