/// <summary>
            /// Get the templates
            /// </summary>
            /// <param name="service">The organization service</param>
            /// <param name="tracingService">The tracing service</param>
            /// <param name="ignoreCache">A value indicating whether to ignore cache</param>
            /// <returns>Template Entity</returns>
            public static ConcurrentDictionary <Guid, Template> GetTemplates(IOrganizationService service, ITracingService tracingService, bool ignoreCache = false)
            {
                lock (LockTemplateCache)
                {
                    if (ignoreCache || TemplateCache.None() || DateTime.Now > TemplateCacheExpiry)
                    {
                        TemplateCache.Clear();

                        var query = new QueryExpression()
                        {
                            EntityName = Template.EntityLogicalName,
                            ColumnSet  = new ColumnSet(true),
                        };

                        var entities = service.RetrieveMultiple(query).Entities;

                        foreach (var template in entities.Select(e => e.ToEntity <Template>()))
                        {
                            TemplateCache.TryAdd(template.Id, template);
                        }

                        TemplateCacheExpiry = DateTime.Now.AddMinutes(CacheValidMinutes);
                    }

                    return(TemplateCache);
                }
            }
示例#2
0
 public void ClearItemCaches()
 {
     if (cachedItems != null)
     {
         cachedItems.Clear();
     }
 }
示例#3
0
 private void FreeTemplateCache(TemplateCache cache)
 {
     cache.Clear();
     cachePool.Add(cache);
 }