/// <summary> /// Delete a catalog connection /// </summary> /// <param name="site">The target site</param> /// <param name="catalogConnectionInfo">The catalog connection information</param> public void DeleteCatalogConnection(SPSite site, CatalogConnectionInfo catalogConnectionInfo) { // Get the catalog var catalog = catalogConnectionInfo.Catalog; // Be careful, you must launch a search crawl before creating a catalog connection. // If a previous connection with the same catalog root folder ULR is already exists, this one will be taken instead of your new catalog var connectionSettings = this.GetCatalogConnectionSettings(site, catalogConnectionInfo.SourceWeb.Url, catalog.WebRelativeUrl.ToString()); if (connectionSettings != null) { this.DeleteCatalogConnection(site, connectionSettings); } }
/// <summary> /// Creates a new catalog connection /// </summary> /// <param name="site">The target site</param> /// <param name="catalogConnectionInfo">The catalog connection information</param> public void EnsureCatalogConnection(SPSite site, CatalogConnectionInfo catalogConnectionInfo) { // Get the catalog var catalog = catalogConnectionInfo.Catalog; // Be careful, you must launch a search crawl before creating a catalog connection. // If a previous connection with the same catalog root folder URL already exists, this one will be taken instead of your new catalog var connectionSettings = this.GetCatalogConnectionSettings(site, catalogConnectionInfo.SourceWeb.Url, catalog.WebRelativeUrl.ToString()); if (connectionSettings != null) { // Configure additional catalog connection settings connectionSettings.CatalogItemUrlRewriteTemplate = catalogConnectionInfo.CatalogItemUrlRewriteTemplate; connectionSettings.CatalogTaxonomyManagedProperty = catalogConnectionInfo.CatalogTaxonomyManagedProperty; connectionSettings.RewriteCatalogItemUrls = catalogConnectionInfo.RewriteCatalogItemUrls; // Rename the catalog (otherwise, can cause "The value must be at most 64 characters long" error // because of the name of the connection is generated automatically by SharePoint connectionSettings.CatalogName = catalogConnectionInfo.SourceWeb.Title + " - " + catalogConnectionInfo.SourceWeb.Locale.Name + " - " + this.resourceLocator.Find(catalogConnectionInfo.Catalog.DisplayNameResourceKey); connectionSettings.IsManualCatalogItemUrlRewriteTemplate = catalogConnectionInfo.IsManualCatalogItemUrlRewriteTemplate; connectionSettings.IsReusedWithPinning = catalogConnectionInfo.IsReusedWithPinning; connectionSettings.CatalogItemUrlRewriteTemplate = catalogConnectionInfo.CatalogItemUrlRewriteTemplate; // Update the publishing web infos connectionSettings.ConnectedWebId = catalogConnectionInfo.TargetWeb.ID; connectionSettings.ConnectedWebServerRelativeUrl = catalogConnectionInfo.TargetWeb.ServerRelativeUrl; // Create the connection this.CreateCatalogConnection(site, connectionSettings, catalogConnectionInfo.OverwriteIfAlreadyExists); } else { this.logger.Info( "Connection information not found for the catalog {0}. Maybe you forgot to start a search crawl before?", this.resourceLocator.Find(catalog.DisplayNameResourceKey)); } }
/// <summary> /// Creates a new catalog connection /// </summary> /// <param name="site">The target site</param> /// <param name="catalogConnectionInfo">The catalog connection information</param> public void EnsureCatalogConnection(SPSite site, CatalogConnectionInfo catalogConnectionInfo) { // Get the catalog var catalog = catalogConnectionInfo.Catalog; // Be careful, you must launch a search crawl before creating a catalog connection. // If a previous connection with the same catalog root folder URL already exists, this one will be taken instead of your new catalog var connectionSettings = this.GetCatalogConnectionSettings(site, catalogConnectionInfo.SourceWeb.Url, catalog.WebRelativeUrl.ToString()); if (connectionSettings != null) { // Configure additional catalog connection settings connectionSettings.CatalogItemUrlRewriteTemplate = catalogConnectionInfo.CatalogItemUrlRewriteTemplate; connectionSettings.CatalogTaxonomyManagedProperty = catalogConnectionInfo.CatalogTaxonomyManagedProperty; connectionSettings.RewriteCatalogItemUrls = catalogConnectionInfo.RewriteCatalogItemUrls; // Rename the catalog (otherwise, can cause "The value must be at most 64 characters long" error // because of the name of the connection is generated automatically by SharePoint connectionSettings.CatalogName = catalogConnectionInfo.SourceWeb.Title + " - " + catalogConnectionInfo.SourceWeb.Locale.Name + " - " + this.resourceLocator.Find(catalogConnectionInfo.Catalog.DisplayNameResourceKey); connectionSettings.IsManualCatalogItemUrlRewriteTemplate = catalogConnectionInfo.IsManualCatalogItemUrlRewriteTemplate; connectionSettings.IsReusedWithPinning = catalogConnectionInfo.IsReusedWithPinning; connectionSettings.CatalogItemUrlRewriteTemplate = catalogConnectionInfo.CatalogItemUrlRewriteTemplate; // Update the publishing web infos connectionSettings.ConnectedWebId = catalogConnectionInfo.TargetWeb.ID; connectionSettings.ConnectedWebServerRelativeUrl = catalogConnectionInfo.TargetWeb.ServerRelativeUrl; // Create the connection this.CreateCatalogConnection(site, connectionSettings, catalogConnectionInfo.OverwriteIfAlreadyExists); } else { this.logger.Info( "Connection information not found for the catalog {0}. Maybe you forgot to start a search crawl before?", this.resourceLocator.Find(catalog.DisplayNameResourceKey)); } }
/// <summary> /// Delete a catalog connection /// </summary> /// <param name="site">The target site</param> /// <param name="catalogConnectionInfo">The catalog connection information</param> public void DeleteCatalogConnection(SPSite site, CatalogConnectionInfo catalogConnectionInfo) { // Get the catalog var catalog = catalogConnectionInfo.Catalog; // Be careful, you must launch a search crawl before creating a catalog connection. // If a previous connection with the same catalog root folder ULR is already exists, this one will be taken instead of your new catalog var connectionSettings = this.GetCatalogConnectionSettings(site, catalogConnectionInfo.SourceWeb.Url, catalog.WebRelativeUrl.ToString()); if (connectionSettings != null) { this.DeleteCatalogConnection(site, connectionSettings); } }