public void CreateRuleManagedMetadataField(IContentOrganizerRuleCreationData data)
 {
     data.RequireNotNull("data");
     ILogUtility logger = new LogUtility();
     string conditionsXml = setConditions(data);
     logger.TraceDebugInformation(string.Format("Conditions:{0}", conditionsXml), GetType());
     using (SPSite site = new SPSite(data.SiteAbsoluteUrl))
     using (SPWeb web = site.OpenWeb())
     {
         creator.CreateRuleManagedMetadataField(data, conditionsXml, site, web, managedMetadataAutoCreator);
     }
 }
        private static string setConditions(IContentOrganizerRuleCreationData data)
        {
            StringBuilder conditionsSB = new StringBuilder("<Conditions>");

            foreach (var item in data.Conditions)
            {
                conditionsSB.Append(setConditional(item));
            }

            // The condition Xml can repeat 0-5 times depending on the number of conditions required for a document to match this rule.
            conditionsSB.Append("</Conditions>");
            return conditionsSB.ToString();
        }
        public void CreateAutofolder(IContentOrganizerRuleCreationData data, SPContentType ruleContentType, EcmDocumentRouterRule organizeDocument)
        {
            // Ensure the SPField for the autofolder property
            TaxonomyField autoFolderField = ruleContentType.Fields[data.AutoFolderPropertyName] as TaxonomyField;
            if (autoFolderField == null)
                throw new ArgumentException(String.Format("The field {0} is not a valid Taxonomy Field", data.AutoFolderPropertyName));

            // Get a handle to the rule auto folder settings.
            DocumentRouterAutoFolderSettings autoFolderSettings = organizeDocument.AutoFolderSettings;
            // Configure AutoFolderSettings for this rule based on the Taxonomy field.
            autoFolderSettings.AutoFolderPropertyName = autoFolderField.Title;
            autoFolderSettings.AutoFolderPropertyInternalName = autoFolderField.InternalName;
            autoFolderSettings.AutoFolderPropertyId = autoFolderField.Id;
            // Term store Id required to get the value of the field from the document. Required for TaxonomyField types.
            autoFolderSettings.TaxTermStoreId = autoFolderField.SspId;
            // Set a format for the name of the folder.
            autoFolderSettings.AutoFolderFolderNameFormat = data.AutoFolderNameFormat;
            // Enabled automatic folder creation for values of the field.
            autoFolderSettings.Enabled = true;
        }