/// <summary> /// Method to create a catalog connection /// </summary> /// <param name="site">The site where to create the connection</param> /// <param name="catalogConnectionSettings">The catalog connection settings to create</param> /// <param name="overwriteIfExist">if true and existing, the connection will be deleted then recreated</param> public void CreateCatalogConnection(SPSite site, CatalogConnectionSettings catalogConnectionSettings, bool overwriteIfExist) { var catalogManager = new CatalogConnectionManager(site); // If catalog connection exist if (catalogManager.Contains(catalogConnectionSettings.CatalogUrl)) { if (overwriteIfExist) { // Delete the existing connection this.logger.Info("Deleting catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.DeleteCatalogConnection(catalogConnectionSettings.CatalogUrl); catalogManager.Update(); // Add connection to the catalog manager this.logger.Info("Creating catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.AddCatalogConnection(catalogConnectionSettings); catalogManager.Update(); } } else { this.logger.Info("Creating catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.AddCatalogConnection(catalogConnectionSettings); catalogManager.Update(); } }
public void ConnectToCatalog(string newUrlTemplate, string taxonomyFieldManagedProperty, bool isCustomCatalogItemUrlRewriteTemplate) { using (SPSite publishingPortalSite = new SPSite(this.portalSiteUrl)) { // Get the connection manager for the site where the catalog content will be rendered. CatalogConnectionManager manager = new CatalogConnectionManager(publishingPortalSite); // Use "Contains" to check whether a connection exists. if (manager.Contains(this.publishingCatalogUrl)) { throw new ArgumentException(string.Format("A connection to {0} already exists", this.publishingCatalogUrl)); } // Get the catalog to connect to. CatalogConnectionSettings settings = PublishingCatalogUtility.GetPublishingCatalog(publishingPortalSite, this.publishingCatalogUrl); manager.AddCatalogConnection(settings, // If the items in the catalog should have rewritten urls, specify what properties should be used in rewriting the url. newUrlTemplate, this.subscribingWebServerRelativeUrl, // The managed property which contains the category for the catalog item. // Typically starts with owstaxid, when created by the system. taxonomyFieldManagedProperty, isCustomCatalogItemUrlRewriteTemplate); // Perform any other adds/Updates // ... // Finally commit connection changes to store. manager.Update(); } }
/// <summary> /// Delete a catalog connection /// </summary> /// <param name="site">The site where to delete the connection</param> /// <param name="catalogConnectionSettings">The catalog connection settings to create</param> public void DeleteCatalogConnection(SPSite site, CatalogConnectionSettings catalogConnectionSettings) { var catalogManager = new CatalogConnectionManager(site); // If catalog connection exist if (catalogManager.Contains(catalogConnectionSettings.CatalogUrl)) { // Delete the existing connection this.logger.Info("Deleting catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.DeleteCatalogConnection(catalogConnectionSettings.CatalogUrl); catalogManager.Update(); } }
/// <summary> /// Method to get a CatalogConnectionSettings from the site /// </summary> /// <param name="site">The SPSite to get the connection from</param> /// <param name="webAbsoluteUrl">The full absolute url of the catalog</param> /// <param name="catalogWebRelativeUrl">The root url of the catalog.</param> /// <returns>A catalogConnectionSettings object</returns> public CatalogConnectionSettings GetCatalogConnectionSettings(SPSite site, Uri webAbsoluteUrl, Uri catalogWebRelativeUrl) { var tokens = catalogWebRelativeUrl.ToString().Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).ToList(); CatalogConnectionSettings catalogConnectionSettings = null; try { catalogConnectionSettings = PublishingCatalogUtility.GetPublishingCatalog(site, SPUtility.ConcatUrls(webAbsoluteUrl.AbsoluteUri, string.Join("/", tokens))); } catch (InternalQueryErrorException exception) { this.logger.Error("Publishing Catalog with tokens {0} was not found on site {1}", string.Join(", ", tokens.ToArray()), site.Url); this.logger.Exception(exception); } return(catalogConnectionSettings); }
public void DeleteCatalog() { using (SPSite publishingPortalSite = new SPSite(this.portalSiteUrl)) { // Get the connection manager for the site where the catalog content will be rendered. CatalogConnectionManager manager = new CatalogConnectionManager(publishingPortalSite); // Use "Contains" to check whether a connection exists. if (manager.Contains(this.publishingCatalogUrl)) { // Get the current settings CatalogConnectionSettings settings = manager.GetCatalogConnectionSettings(this.publishingCatalogUrl); manager.DeleteCatalogConnection(this.publishingCatalogUrl); // Perform any other adds/Updates // Finally Commit the update(s) to store. manager.Update(); } } }
/// <summary> /// Update the url rewrite template for a catalog connection. /// The url rewrite template provides the managed properties from the search schema used to rewrite urls to items from the catalog. /// </summary> /// <param name="newUrlTemplate"></param> public void UpdateCatalogUrlTemplate(string newUrlTemplate) { using (SPSite publishingPortalSite = new SPSite(this.portalSiteUrl)) { // Get the connection manager for the site where the catalog content will be rendered. CatalogConnectionManager manager = new CatalogConnectionManager(publishingPortalSite); // Get the current settings CatalogConnectionSettings settings = manager.GetCatalogConnectionSettings(this.publishingCatalogUrl); if (settings == null) { throw new ArgumentException(string.Format("This site is not connected to catalog {0}", this.publishingCatalogUrl)); } settings.CatalogItemUrlRewriteTemplate = newUrlTemplate; // Update in memory manager.UpdateCatalogConnection(settings); // Perform any other adds/Updates // Finally Commit the update(s) to store. manager.Update(); } }
/// <summary> /// Connect without any settings /// A result source will be created and the catalog will be available for content search webparts /// but item urls will have the original path to the source catalog library. /// </summary> public void ConnectToCatalog() { using (SPSite publishingPortalSite = new SPSite(this.portalSiteUrl)) { // Get the connection manager for the site where the catalog content will be rendered. CatalogConnectionManager manager = new CatalogConnectionManager(publishingPortalSite, createResultSource: true); // Use "Contains" to check whether a connection exists. if (manager.Contains(this.publishingCatalogUrl)) { throw new ArgumentException(string.Format("A connection to {0} already exists", this.publishingCatalogUrl)); } // Get the catalog to connect to. CatalogConnectionSettings settings = PublishingCatalogUtility.GetPublishingCatalog(publishingPortalSite, this.publishingCatalogUrl); settings.ConnectedWebServerRelativeUrl = this.subscribingWebServerRelativeUrl; manager.AddCatalogConnection(settings); // Perform any other adds/Updates // ... // Finally commit connection changes to store. manager.Update(); } }
/// <summary> /// Delete a catalog connection /// </summary> /// <param name="site">The site where to delete the connection</param> /// <param name="catalogConnectionSettings">The catalog connection settings to create</param> public void DeleteCatalogConnection(SPSite site, CatalogConnectionSettings catalogConnectionSettings) { var catalogManager = new CatalogConnectionManager(site); // If catalog connection exist if (catalogManager.Contains(catalogConnectionSettings.CatalogUrl)) { // Delete the existing connection this.logger.Info("Deleting catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.DeleteCatalogConnection(catalogConnectionSettings.CatalogUrl); catalogManager.Update(); } }
/// <summary> /// Method to create a catalog connection /// </summary> /// <param name="site">The site where to create the connection</param> /// <param name="catalogConnectionSettings">The catalog connection settings to create</param> /// <param name="overwriteIfExist">if true and existing, the connection will be deleted then recreated</param> public void CreateCatalogConnection(SPSite site, CatalogConnectionSettings catalogConnectionSettings, bool overwriteIfExist) { var catalogManager = new CatalogConnectionManager(site); // If catalog connection exist if (catalogManager.Contains(catalogConnectionSettings.CatalogUrl)) { if (overwriteIfExist) { // Delete the existing connection this.logger.Info("Deleting catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.DeleteCatalogConnection(catalogConnectionSettings.CatalogUrl); catalogManager.Update(); // Add connection to the catalog manager this.logger.Info("Creating catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.AddCatalogConnection(catalogConnectionSettings); catalogManager.Update(); } } else { this.logger.Info("Creating catalog connection: " + catalogConnectionSettings.CatalogUrl); catalogManager.AddCatalogConnection(catalogConnectionSettings); catalogManager.Update(); } }