protected virtual IEnumerable <ObjectCache> GetObjectCaches() { var section = CrmConfigurationManager.GetCrmSection(); var elements = section.ObjectCache.Cast <ObjectCacheElement>().ToList(); if (!elements.Any()) { yield return(CrmConfigurationManager.CreateObjectCache()); } else { // ignore service cache objects that are nested in a composite service cache var ignored = ( from element in elements let inner = element.Parameters["innerObjectCacheName"] where !string.IsNullOrWhiteSpace(inner) select inner).ToList(); foreach (var element in elements.Where(e => !ignored.Contains(e.Name))) { yield return(CrmConfigurationManager.CreateObjectCache(element.Name)); } } }
/// <summary> /// Retrieves the <see cref="ObjectCache"/>. /// </summary> /// <param name="objectCacheName">The configuration name of the cache.</param> /// <returns>The cache.</returns> private static ObjectCache GetCache(string objectCacheName) { var cache = CrmConfigurationManager.GetObjectCaches(objectCacheName).FirstOrDefault() ?? CrmConfigurationManager.CreateObjectCache(objectCacheName); return(cache); }
private static IEnumerable <ObjectCache> GetCaches(string objectCacheName) { var caches = CrmConfigurationManager.GetObjectCaches(objectCacheName); if (caches.Any()) { return(caches); } return(new[] { CrmConfigurationManager.CreateObjectCache(objectCacheName) }); }
/// <summary> /// Initializes custom settings. /// </summary> /// <param name="name"></param> /// <param name="config"></param> public virtual void Initialize(string name, NameValueCollection config) { _name = name; if (config != null && Cache == null) { var innerTypeName = config["innerType"]; if (!string.IsNullOrWhiteSpace(innerTypeName)) { // instantiate by type var innerType = TypeExtensions.GetType(innerTypeName); if (innerType == typeof(MemoryCache)) { Cache = new MemoryCache(name, config); } else if (innerType.IsA <MemoryCache>()) { Cache = Activator.CreateInstance(innerType, name, config) as ObjectCache; } else { Cache = Activator.CreateInstance(innerType) as ObjectCache; } } var innerObjectCacheName = config["innerObjectCacheName"]; if (!string.IsNullOrWhiteSpace(innerObjectCacheName)) { // instantiate by config Cache = CrmConfigurationManager.CreateObjectCache(innerObjectCacheName); } } if (Cache == null) { // fall back to MemoryCache Cache = new MemoryCache(name, config); } }
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); }
/// <summary> /// Retrieves a configured <see cref="ObjectCache"/>. /// </summary> /// <param name="objectCacheName"></param> /// <returns></returns> public virtual ObjectCache GetInstance(string objectCacheName = null) { return(CrmConfigurationManager.CreateObjectCache(objectCacheName)); }