private static ConnectionStringSettings GetConnectionStringSettings(string connectionStringName) { var settings = ConfigurationManager.ConnectionStrings[connectionStringName]; if (settings == null) { if (connectionStringName == "SharePoint") { // Try to use the CRM connection string "Xrm" if (ConfigurationManager.ConnectionStrings.Count != 0) { settings = ConfigurationManager.ConnectionStrings["Xrm"]; } else if (CrmConfigurationManager.GetCrmSection().ConnectionStrings.Count != 0) { settings = CrmConfigurationManager.GetCrmSection().ConnectionStrings["Xrm"]; } } if (settings == null) { throw new ConfigurationErrorsException("Unable to find a connection string with the name {0}.".FormatWith(connectionStringName)); } } return(settings); }
private static string GetServiceCacheName(out string connectionId) { // try the default provider var section = CrmConfigurationManager.GetCrmSection(); var defaultElement = section.ServiceCache.GetElementOrDefault(null); if (IsExtendedOrganizationServiceCache(defaultElement.DependencyType)) { connectionId = GetConnectionId(defaultElement.Parameters); return(defaultElement.Name); } // return the first element that has a ServiceBusObjectCache dependency var element = section.ServiceCache.Cast <OrganizationServiceCacheElement>().FirstOrDefault(cache => IsExtendedOrganizationServiceCache(cache.DependencyType)); if (element != null) { connectionId = GetConnectionId(element.Parameters); return(element.Name); } connectionId = null; return(null); }
protected virtual IEnumerable <IOrganizationServiceCache> GetServiceCaches() { var section = CrmConfigurationManager.GetCrmSection(); var elements = section.ServiceCache.Cast <OrganizationServiceCacheElement>().ToList(); if (!elements.Any()) { yield return(CrmConfigurationManager.CreateServiceCache(null, (string)null, true)); } else { // ignore service cache objects that are nested in a composite service cache var ignored = ( from element in elements let inner = element.Parameters["innerServiceCacheName"] where !string.IsNullOrWhiteSpace(inner) select inner).ToList(); foreach (var element in elements.Where(e => !ignored.Contains(e.Name))) { var connectionId = GetConnectionId(element.Parameters); yield return(CrmConfigurationManager.CreateServiceCache(element.Name, connectionId, true)); } } }
public WebCrmEntityIndex(Directory directory, Analyzer analyzer, Version version, string indexQueryName) { if (directory == null) { throw new ArgumentNullException("directory"); } if (analyzer == null) { throw new ArgumentNullException("analyzer"); } if (indexQueryName == null) { throw new ArgumentNullException("indexQueryName"); } Directory = directory; Version = version; IndexQueryName = indexQueryName; Name = string.IsNullOrEmpty(_dataContextName) ? CrmConfigurationManager.GetCrmSection().Contexts.Current.Name : _dataContextName; _defaultAnalyzer = analyzer; Analyzer = GetAnalyzer(); }
private static string GetDefaultContextName() { var section = CrmConfigurationManager.GetCrmSection(); var element = section.Contexts.GetElementOrDefault(null); return(element.Name); }
protected virtual Type GetCrmDataContextType() { try { return(CrmConfigurationManager.GetCrmSection().Contexts.Current.DependencyType ?? typeof(OrganizationServiceContext)); } catch { return(typeof(OrganizationServiceContext)); } }
private static int GetDefaultTimeout() { var section = CrmConfigurationManager.GetCrmSection(); if (section != null && section.MutexTimeout != null) { var timeout = (int)section.MutexTimeout.Value.TotalMilliseconds; return(timeout); } return(Timeout.Infinite); }
private static ObjectCacheProvider CreateProvider() { var section = CrmConfigurationManager.GetCrmSection(); if (!string.IsNullOrWhiteSpace(section.ObjectCacheProviderType)) { var typeName = section.ObjectCacheProviderType; var type = TypeExtensions.GetType(typeName); if (type == null || !type.IsA <ObjectCacheProvider>()) { throw new ConfigurationErrorsException("The value '{0}' is not recognized as a valid type or is not of the type '{1}'.".FormatWith(typeName, typeof(ObjectCacheProvider))); } return(Activator.CreateInstance(type) as ObjectCacheProvider); } return(new ObjectCacheProvider()); }
private static IEnumerable <ObjectCache> GetObjectCaches() { var section = CrmConfigurationManager.GetCrmSection(); var elements = section.ObjectCache.Cast <ObjectCacheElement>().ToList(); if (!elements.Any()) { yield return(CrmConfigurationManager.CreateObjectCache()); } else { var ignored = elements.Select(element => new { element, inner = element.Parameters["innerObjectCacheName"] }) .Where(param0 => !string.IsNullOrWhiteSpace(param0.inner)) .Select(param0 => param0.inner) .ToList(); foreach (var objectCacheElement in elements.Where(e => !ignored.Contains(e.Name))) { yield return(CrmConfigurationManager.CreateObjectCache(objectCacheElement.Name)); } } }
private IOrganizationServiceCache CreateDefaultServiceCache(string serviceCacheName = null, string connectionId = null, bool allowDefaultFallback = false) { var section = CrmConfigurationManager.GetCrmSection(); var serviceCacheElement = section.ServiceCache.GetElementOrDefault(serviceCacheName, allowDefaultFallback); var objectCacheName = !string.IsNullOrWhiteSpace(serviceCacheElement.ObjectCacheName) ? serviceCacheElement.ObjectCacheName : serviceCacheElement.Name; var objectCacheElement = section.ObjectCache.GetElementOrDefault(objectCacheName, allowDefaultFallback); var settings = new OrganizationServiceCacheSettings(connectionId) { ConnectionId = connectionId, CacheRegionName = serviceCacheElement.CacheRegionName, QueryHashingEnabled = serviceCacheElement.QueryHashingEnabled, PolicyFactory = objectCacheElement, }; var objectCache = CrmConfigurationManager.CreateObjectCache(objectCacheName, true); var serviceCache = CreateDefaultServiceCache(objectCache, settings); return(serviceCache); }
private static IEnumerable <IOrganizationServiceCache> GetServiceCaches() { var section = CrmConfigurationManager.GetCrmSection(); var elements = section.ServiceCache.Cast <OrganizationServiceCacheElement>().ToList(); if (!elements.Any()) { yield return(CrmConfigurationManager.CreateServiceCache(null, (string)null, true)); } else { var ignored = elements.Select(element => new { element, inner = element.Parameters["innerServiceCacheName"] }) .Where(param0 => !string.IsNullOrWhiteSpace(param0.inner)) .Select(param0 => param0.inner) .ToList(); foreach (var serviceCacheElement in elements.Where(e => !ignored.Contains(e.Name))) { var connectionId = GetConnectionId(serviceCacheElement.Parameters); yield return(CrmConfigurationManager.CreateServiceCache(serviceCacheElement.Name, connectionId, true)); } } }