private IEnumerable <string> GetCacheDependencies(QueryBase query, IEnumerable entities)
        {
            CacheParameters cacheParameters = Owner.GetCacheParameters();
            var             dependencies    = new List <string>();

            // get the global dependencies
            foreach (CacheKeyDependency ckd in cacheParameters.Dependencies)
            {
                dependencies.Add(ckd.GetCacheKey(Context, Owner, query));
            }

            // get the item dependencies
            foreach (Entity entity in entities)
            {
                dependencies.Add("xrm:dependency:entity:{0}:id={1}".FormatWith(entity.LogicalName, entity.Id));

                foreach (CacheKeyDependency ckd in cacheParameters.ItemDependencies)
                {
                    dependencies.Add(ckd.GetCacheKey(Context, Owner, entity));
                }
            }

            // add other dependencies
            var dependencyCalculator = new CacheDependencyCalculator("xrm:dependency");

            dependencies = dependencies.Concat(dependencyCalculator.GetDependenciesForObject(query)).Distinct().ToList();

            return(dependencies);
        }
Example #2
0
        public string GenerateBeginUnitOfWork(CacheParameters parameter)
        {
            StringBuilder sb = new StringBuilder();

            INHibernateConfig config = parameter.Driver as INHibernateConfig;

            sb.AppendLine(
                $"var nHibConfig = {config.ConfigName}.ConnectionString(configuration.ConnectionStrings[\"{parameter.ConnectionName}\"]);");
            sb.AppendLine("             Configuration = Fluently.Configure().Database(nHibConfig)");
            sb.AppendLine(
                "               .Mappings(o => o.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()).Conventions.Add(");
            sb.AppendLine("                 FluentNHibernate.Conventions.Helpers.ConventionBuilder.Class.Always(");
            sb.AppendLine("                     z =>");
            sb.AppendLine("                         {");
            sb.AppendLine("                             z.BatchSize(512);");
            sb.AppendLine("                             z.Cache.ReadWrite();");
            sb.AppendLine("                     })");
            sb.AppendLine("                 )).Cache(");
            sb.AppendLine(
                "                     o => o.ProviderClass<NHibernate.Caches.CoreMemoryCache.CoreMemoryCacheProvider>().UseQueryCache().UseSecondLevelCache()");
            sb.AppendLine("             ).BuildConfiguration();");


            sb.AppendLine("             Factory = Configuration.BuildSessionFactory();");
            sb.AppendLine();
            sb.AppendLine("             container.Configure(");
            sb.AppendLine("             config =>");
            sb.AppendLine("             {");
            sb.AppendLine(
                $"                config.For<IUnitOfWork>().LifecycleIs(Lifecycles.Transient).Use<{parameter.Driver.Prefix}{parameter.ContextName}>()");
            sb.AppendLine("                 .Ctor<ISessionFactory>(\"factory\").Is(Factory);");
            sb.AppendLine("             });");

            return(sb.ToString());
        }
Example #3
0
        public string GenerateBeginUnitOfWork(CacheParameters parameter)
        {
            if (this.EnableCache)
            {
                return(this.CurrentCache.GenerateBeginUnitOfWork(parameter));
            }
            else
            {
                StringBuilder sb = new StringBuilder();

                INHibernateConfig config = parameter.Driver as INHibernateConfig;

                sb.AppendLine(
                    $"var nHibConfig = {config.ConfigName}.ConnectionString(configuration.ConnectionStrings[\"{parameter.ConnectionName}\"]);");
                sb.AppendLine("             Configuration = Fluently.Configure().Database(nHibConfig)");
                sb.AppendLine(
                    "               .Mappings(o => o.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()));");
                sb.AppendLine("             Factory = Configuration.BuildSessionFactory();");
                sb.AppendLine();
                sb.AppendLine("             container.Configure(");
                sb.AppendLine("             config =>");
                sb.AppendLine("             {");
                sb.AppendLine($"                config.For<IUnitOfWork>().LifecycleIs(Lifecycles.Transient).Use<{parameter.Driver.Prefix}{parameter.ContextName}>()");
                sb.AppendLine("                 .Ctor<ISessionFactory>(\"factory\").Is(Factory);");
                sb.AppendLine("             });");

                return(sb.ToString());
            }
        }
 internal AutoPollConfigService(
     IConfigFetcher configFetcher,
     CacheParameters cacheParameters,
     TimeSpan pollingInterval,
     TimeSpan maxInitWaitTime,
     ILogger logger) : this(configFetcher, cacheParameters, pollingInterval, maxInitWaitTime, logger, true)
 {
 }
Example #5
0
        protected ConfigServiceBase(IConfigFetcher configFetcher, CacheParameters cacheParameters, ILogger log)
        {
            this.configFetcher = configFetcher;

            this.configCache = cacheParameters.ConfigCache;

            this.cacheKey = cacheParameters.CacheKey;

            this.log = log;
        }
Example #6
0
        protected EntityCacheRepository(IOptions <DataAccessConfiguration> dbOptions, string collectionName,
                                        IOptions <List <CacheSettings> > cacheOptions, string cacheSettingsName, IMemoryCache memoryCache) : base(dbOptions, collectionName)
        {
            _memoryCache = memoryCache;

            if (cacheOptions?.Value != null && cacheOptions.Value.Any())
            {
                var entityCacheSettings = cacheOptions.Value.FirstOrDefault(x => x.Name.Equals(cacheSettingsName));
                if (entityCacheSettings != null)
                {
                    _entityCacheParameters = entityCacheSettings.Parameters;
                }
            }
        }
        /// <summary>
        /// For test purpose only
        /// </summary>
        /// <param name="configFetcher"></param>
        /// <param name="cacheParameters"></param>
        /// <param name="pollingInterval"></param>
        /// <param name="maxInitWaitTime"></param>
        /// <param name="logger"></param>
        /// <param name="startTimer"></param>
        internal AutoPollConfigService(
            IConfigFetcher configFetcher,
            CacheParameters cacheParameters,
            TimeSpan pollingInterval,
            TimeSpan maxInitWaitTime,
            ILogger logger,
            bool startTimer
            ) : base(configFetcher, cacheParameters, logger)
        {
            if (startTimer)
            {
                this.timer = new Timer(RefreshLogic, "auto", TimeSpan.Zero, pollingInterval);
            }

            this.maxInitWaitExpire = DateTime.UtcNow.Add(maxInitWaitTime);
        }
Example #8
0
        public string GenerateBeginUnitOfWork(CacheParameters parameter)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Provider = ConfigureServices.GetInMemoryCacheServiceProvider();");
            sb.AppendLine("             EFSecondLevelCache.Core.EFServiceProvider.ApplicationServices = Provider;");
            sb.AppendLine();
            sb.AppendLine("             container.Configure(");
            sb.AppendLine("                 config =>");
            sb.AppendLine("                 {");
            sb.AppendLine($"                    config.For<IUnitOfWork>().LifecycleIs(Lifecycles.Transient).Use<{parameter.Driver.Prefix}{parameter.ContextName}>()");
            sb.AppendLine($"                         .Ctor<string>(\"connectionString\").Is(configuration.ConnectionStrings[\"{parameter.ConnectionName}\"])");
            sb.AppendLine("                         .Ctor<IServiceProvider>(\"provider\").Is(Provider);");
            sb.AppendLine("                 });");

            return(sb.ToString());
        }
Example #9
0
        private ConfigCatClient(ConfigurationBase configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            configuration.Validate();

            this.log = configuration.Logger;
            this.configDeserializer = new ConfigDeserializer(this.log, JsonSerializer.Create());
            this.configEvaluator    = new RolloutEvaluator(this.log, this.configDeserializer);
            this.cacheParameters    = new CacheParameters
            {
                ConfigCache = configuration.ConfigCache ?? new InMemoryConfigCache(),
                CacheKey    = GetCacheKey(configuration)
            };
        }
        private string GetCacheKey(QueryBase query)
        {
            if (_cacheKey == null)
            {
                CacheParameters cacheParameters = Owner.GetCacheParameters();
                _cacheKey = cacheParameters.CacheKey.GetCacheKey(
                    Context,
                    Owner,
                    Owner,
                    delegate
                {
                    string serializedQuery = Serialize(query);
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("QueryByAttribute : {0}", serializedQuery.GetHashCode().ToString(CultureInfo.InvariantCulture)));
                    return("Adxstudio:Type={0}:ID={1}:Hash={2}".FormatWith(Owner.GetType().FullName, Owner.ID, serializedQuery.GetHashCode()).ToLower());
                });
            }

            return(_cacheKey);
        }
Example #11
0
        public string GenerateBeginUnitOfWork(CacheParameters parameter)
        {
            if (this.EnableCache && this.CurrentCache != null)
            {
                return(this.CurrentCache.GenerateBeginUnitOfWork(parameter));
            }
            else
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("container.Configure(");
                sb.AppendLine("                 config =>");
                sb.AppendLine("                 {");
                sb.AppendLine($"                    config.For<IUnitOfWork>().LifecycleIs(Lifecycles.Transient).Use<{parameter.Driver.Prefix}{parameter.ContextName}>()");
                sb.AppendLine($"                         .Ctor<string>(\"connectionString\").Is(configuration.ConnectionStrings[\"{parameter.ConnectionName}\"]);");
                sb.AppendLine("                 });");

                return(sb.ToString());
            }
        }
Example #12
0
 internal ManualPollConfigService(IConfigFetcher configFetcher, CacheParameters cacheParameters, ILogger logger)
     : base(configFetcher, cacheParameters, logger)
 {
 }
Example #13
0
 internal LazyLoadConfigService(IConfigFetcher configFetcher, CacheParameters cacheParameters, ILogger logger, TimeSpan cacheTimeToLive)
     : base(configFetcher, cacheParameters, logger)
 {
     this.cacheTimeToLive = cacheTimeToLive;
 }
 public FakeConfigService(IConfigFetcher configFetcher, CacheParameters cacheParameters, ILogger log) : base(configFetcher, cacheParameters, log)
 {
 }