protected virtual void GetCrawlRules(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { // Crawl rule order is important e.g. filter rules will usually be applied before additional post-processing rules, so loop through properties and // add crawl rules in the order that they are listed in the model. foreach (string propertyKey in properties.Keys) { if (propertyKey.Equals(CrawlRuleTypes.ExcludeSimpleQuestions, StringComparison.OrdinalIgnoreCase)) { SimpleQuestionFilter filter = new SimpleQuestionFilter(); _crawlRules.Add(filter); } else if (propertyKey.Equals(CrawlRuleTypes.ExcludeSpecifiedQuestions, StringComparison.OrdinalIgnoreCase)) { SpecifiedQuestionFilter filter = new SpecifiedQuestionFilter((string)properties[CrawlRuleTypes.ExcludeSpecifiedQuestions]); _crawlRules.Add(filter); } else if (propertyKey.Equals(CrawlRuleTypes.IncludeParents, StringComparison.OrdinalIgnoreCase)) { IncludeParentsTransform transform = new IncludeParentsTransform(); _crawlRules.Add(transform); } else if (propertyKey.Equals(CrawlRuleTypes.IncludeChildren, StringComparison.OrdinalIgnoreCase)) { IncludeChildrenTransform transform = new IncludeChildrenTransform(); _crawlRules.Add(transform); } } } }
protected virtual void GetEnableSecuritySetting(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { if (properties.ContainsKey(GlymaModelConstants.EnableSecurity)) { _isSecurityEnabled = (bool)properties[GlymaModelConstants.EnableSecurity]; } } }
protected virtual void GetEnableNodeAclCacheSetting(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { if (properties.ContainsKey(GlymaModelConstants.EnableNodeAclCache)) { _isNodeAclCacheEnabled = (bool)properties[GlymaModelConstants.EnableNodeAclCache]; } } }
protected virtual void GetSecurityConnectionString(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { if (!properties.ContainsKey(GlymaModelConstants.SecurityConnectionString) || string.IsNullOrEmpty((string)properties[GlymaModelConstants.SecurityConnectionString])) { throw new ArgumentException("A security repository connection string has not been specified in the model."); } _securityConnectionString = (string)properties[GlymaModelConstants.SecurityConnectionString]; } }
/// <summary> /// Gets a property value from a INamedPropertyDictionary object using a key and a specific string comparer to examine the keys. /// </summary> /// <param name="properties">A INamedPropertyDictionary 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>An object that matches the key; otherwise, null.</returns> public static object GetByKey(this INamedPropertyDictionary properties, string key, StringComparison comparisonType) { object propertyValue = null; foreach (string propertyKey in properties.Keys) { if (propertyKey.Equals(key, comparisonType)) { propertyValue = properties[propertyKey]; break; } } return(propertyValue); }
/// <summary> /// Checks the existence of a key within a INamedPropertyDictionary object using a specific string comparer. /// </summary> /// <param name="lobInstances">A INamedPropertyDictionary 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 INamedPropertyDictionary properties, string key, StringComparison comparisonType) { bool result = false; foreach (string propertyKey in properties.Keys) { if (propertyKey.Equals(key, comparisonType)) { result = true; break; } } return(result); }
public void SetGlobalSettings(GlymaRepositoryProxy proxy, INamedPropertyDictionary properties) { // The global settings will be accessed by multiple threads, so synchronise access to them when configuring a proxy. lock (_globalSettingsLock) { if (!_globalSettingsInitialised) { GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Medium, "Initialised global settings."); GetDataAccessType(properties); GetSecurityConnectionString(properties); GetCrawlRules(properties); GetEnableNodeAclCacheSetting(properties); GetNodeAclType(properties); GetEnableSecuritySetting(properties); GetNodeAclCacheDuration(properties); GetNodeAclCacheAutoExpirePeriod(properties); GetNodeAclCacheMaxItems(properties); GetNodeAclTaskWaitDuration(properties); _globalSettingsInitialised = true; } IGlymaSecurityRepository securityRepository = null; if (_dataAccessType == DataAccessType.Sql) { securityRepository = new SqlGlymaSecurityRepository(_securityConnectionString); } GlymaSecurityManager securityManager = null; if (_nodeAclType == NodeAclType.Windows) { if (_isNodeAclCacheEnabled) { securityManager = new WindowsGlymaSecurityManager(securityRepository, _nodeAclCacheAutoExpirePeriod, _nodeAclCacheMaxItems, _nodeAclCacheDuration, _nodeAclTaskWaitDuration); } else { securityManager = new WindowsGlymaSecurityManager(securityRepository); } } else { throw new ApplicationException("Only the Windows node ACL type is currently supported."); } proxy.IsSecurityEnabled = _isSecurityEnabled; proxy.SecurityRepository = securityRepository; proxy.SecurityManager = securityManager; proxy.CrawlRules = _crawlRules.DeepCopy(); } }
protected virtual void SetMapConnectionString(GlymaRepositoryProxy proxy, INamedPropertyDictionary properties, string repositoryName) { string connectionString = string.Empty; if (!properties.ContainsKey(GlymaModelConstants.MapConnectionString) || string.IsNullOrEmpty((string)properties[GlymaModelConstants.MapConnectionString])) { throw new ArgumentException("A map repository connection string has not been specified in the model for the LOB instance: " + repositoryName + "."); } connectionString = (string)properties[GlymaModelConstants.MapConnectionString]; if (_dataAccessType == DataAccessType.Sql) { proxy.MapRepository = new SqlGlymaMapRepository(connectionString); } }
protected virtual void GetNodeAclTaskWaitDuration(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { if (properties.ContainsKey(GlymaModelConstants.NodeAclTaskWaitDuration)) { int aclWaitDuration = (int)properties[GlymaModelConstants.NodeAclTaskWaitDuration]; if (aclWaitDuration < 0) { throw new ArgumentException("The propery: " + GlymaModelConstants.NodeAclTaskWaitDuration + ", cannot be a negative number."); } _nodeAclTaskWaitDuration = new TimeSpan(0, 0, (int)properties[GlymaModelConstants.NodeAclTaskWaitDuration]); } } }
protected virtual void GetNodeAclCacheMaxItems(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { if (properties.ContainsKey(GlymaModelConstants.NodeAclCacheMaxItems)) { int maxItems = (int)properties[GlymaModelConstants.NodeAclCacheMaxItems]; if (maxItems < 0) { throw new ArgumentException("The propery: " + GlymaModelConstants.NodeAclCacheMaxItems + ", cannot be a negative number."); } _nodeAclCacheMaxItems = maxItems; } } }
protected virtual void GetNodeAclCacheAutoExpirePeriod(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { if (properties.ContainsKey(GlymaModelConstants.NodeAclCacheAutoExpirePeriod)) { int cacheAutoExpirePeriod = (int)properties[GlymaModelConstants.NodeAclCacheAutoExpirePeriod]; if (cacheAutoExpirePeriod < 0) { throw new ArgumentException("The propery: " + GlymaModelConstants.NodeAclCacheAutoExpirePeriod + ", cannot be a negative number."); } _nodeAclCacheAutoExpirePeriod = new TimeSpan(0, 0, (int)properties[GlymaModelConstants.NodeAclCacheAutoExpirePeriod]); } } }
protected virtual void GetDataAccessType(INamedPropertyDictionary properties) { lock (_globalSettingsLock) { if (!properties.ContainsKey(GlymaModelConstants.DataAccessType) || string.IsNullOrEmpty((string)properties[GlymaModelConstants.DataAccessType])) { throw new ArgumentException("The property: " + GlymaModelConstants.DataAccessType + ", has not been specified in the model."); } string dataAccessTypeString = (string)properties[GlymaModelConstants.DataAccessType]; DataAccessType dataAccessType; try { dataAccessType = ParseEnum <DataAccessType>(dataAccessTypeString); } catch (ArgumentException) { throw new ArgumentException("The property: " + GlymaModelConstants.DataAccessType + ", has an invalid value. The allowed values are: (" + string.Join(", ", Enum.GetNames(typeof(DataAccessType))) + ")."); } _dataAccessType = dataAccessType; } }
/// <summary> /// Reads configuration parameters from BDCM and instantiates the ShopifyClient. /// </summary> /// <returns></returns> private ShopifyClient GetShopifyClient() { INamedPropertyDictionary properties = LobSystemInstance.GetProperties(); string apiKey; string apiPassword; string apiHostName; if (properties.ContainsKey("ApiKey") && !string.IsNullOrWhiteSpace(properties["ApiKey"].ToString())) { apiKey = properties["ApiKey"].ToString(); } else { throw new ArgumentException("ApiKey property must be defined for LOB System Instance"); } if (properties.ContainsKey("ApiPassword") && !string.IsNullOrWhiteSpace(properties["ApiPassword"].ToString())) { apiPassword = properties["ApiPassword"].ToString(); } else { throw new ArgumentException("ApiPassword property must be defined for LOB System Instance"); } if (properties.ContainsKey("ApiHostName") && !string.IsNullOrWhiteSpace(properties["ApiHostName"].ToString())) { apiHostName = properties["ApiHostName"].ToString(); } else { throw new ArgumentException("ApiHostName property must be defined for LOB System Instance"); } return(new ShopifyClient(apiKey, apiPassword, apiHostName)); }