/// <summary> /// Gets a LOB system instance from a INamedLobSystemInstanceDictionary object using a key and a specific string comparer to examine the keys. /// </summary> /// <param name="lobInstances">A INamedLobSystemInstanceDictionary object to be searched.</param> /// <param name="key">The key to search for.</param> /// <param name="comparisonType">The string comparer to use to compare the keys.</param> /// <returns>A ILobSystemInstance object that matches the key; otherwise, null.</returns> public static ILobSystemInstance GetByKey(this INamedLobSystemInstanceDictionary lobInstances, string key, StringComparison comparisonType) { ILobSystemInstance lobInstance = null; foreach (string lobInstanceKey in lobInstances.Keys) { if (lobInstanceKey.Equals(key, comparisonType)) { lobInstance = lobInstances[lobInstanceKey]; break; } } return(lobInstance); }
/// <summary> /// Initialises the class to map the content item URL. /// </summary> /// <param name="context">An IConnectionContext object that contains the content item URL to map.</param> /// <remarks> /// The following URL's are supported: /// glyma://[Repository Name] - Defines a crawl start address for a Glyma repository defined in the BCS model file. /// glyma://[Repository Name]/[Domain Guid] - Defines a crawl start adddress for the specified domain in a Glyma repository. /// glyma://[Repository Name]/[Domain GUID]/[Root Map GUID]/[Parent Map GUID]/[Node GUID]/ - Defines the URL for a Glyma Map. /// glyma://[Repository Name]/[Domain GUID]/[Root Map GUID]/[Parent Map GUID]/[Node GUID] - Defines the URL for a Glyma Node. /// </remarks> public override void Initialize(Microsoft.Office.Server.Search.Connector.IConnectionContext context) { _sourceUri = context.Path; if (!_sourceUri.Scheme.Equals(GlymaModelConstants.Protocol, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("Invalid Glyma URL provided. The URL must start with: glyma://."); } _lobSystem = this.Catalog.GetLobSystem(GlymaModelConstants.LobSystemName); // Get the LOB system instance based on the host specified in the context path. // The LOB system instance is passed as a parameter to the ExecuteStatic method in the GlymaRepositoryUtility class. if (string.IsNullOrEmpty(_sourceUri.Host)) { throw new ArgumentException("Invalid Glyma URL provided. The URL must specify a repository name in the form: glyma://[Repository Name] where [Repository Name] is the name of a LOB system instance in the BCS model file."); } INamedLobSystemInstanceDictionary lobInstances = _lobSystem.GetLobSystemInstances(); _lobSystemInstance = _lobSystem.GetLobSystemInstances().GetByKey(_sourceUri.Host, StringComparison.OrdinalIgnoreCase); if (_lobSystemInstance == null) { throw new ArgumentException("Invalid Glyma URL provided. The repository name specified does not exist in the BCS model file."); } // Set the entity to be a Glyma Map by default. When the URL is a crawl start address, it won't contain the identity of an entity instance. // By setting the entity but not the entity instance, the Finder method of the entity is executed to return entity instances to crawl. _entity = this.Catalog.GetEntity(GlymaModelConstants.Namespace, GlymaModelConstants.MapEntityName); // Extract the entity instance identity from the context path. The entity instance could either be a Glyma Map (which contains a trailing '/' in its URL) or a Glyma Node. // If an entity instance identity can be extracted, the SpecificFinder method of the entity is executed to return details for that entity instance. if (_sourceUri.Segments.Length == 5) { if (!_sourceUri.Segments[4].EndsWith("/")) { _entity = this.Catalog.GetEntity(GlymaModelConstants.Namespace, GlymaModelConstants.NodeEntityName); } string domainIdString = _sourceUri.Segments[1].TrimEnd('/'); string rootMapIdString = _sourceUri.Segments[2].TrimEnd('/'); string mapIdString = _sourceUri.Segments[3].TrimEnd('/'); string nodeIdString = _sourceUri.Segments[4].TrimEnd('/'); Guid domainId = new Guid(domainIdString); Guid rootMapId = new Guid(rootMapIdString); Guid mapId = new Guid(mapIdString); Guid nodeId = new Guid(nodeIdString); Object[] identifier = { _lobSystemInstance.Name, domainId, rootMapId, mapId, nodeId }; _identity = new Microsoft.BusinessData.Runtime.Identity(identifier); } }
/// <summary> /// Checks the existence of a key within a INamedLobSystemInstanceDictionary object using a specific string comparer. /// </summary> /// <param name="lobInstances">A INamedLobSystemInstanceDictionary object to be searched.</param> /// <param name="key">The key to search for.</param> /// <param name="comparisonType">The string comparer to use to compare the keys.</param> /// <returns>true if a match is found; otherwise, false.</returns> public static bool ContainsKey(this INamedLobSystemInstanceDictionary lobInstances, string key, StringComparison comparisonType) { bool result = false; foreach (string lobInstanceKey in lobInstances.Keys) { if (lobInstanceKey.Equals(key, comparisonType)) { result = true; break; } } return(result); }