public virtual IClousotCache Create(IClousotCacheOptions options) { if (String.IsNullOrWhiteSpace(DbName) || options == null) { return(null); } var connection = BuildConnectionString(options).ToString(); Contract.Assert(DbName != null, "Helping cccheck"); SQLCacheModel model; if (options.ClearCache) { model = new SqlCacheModelClearExisting(connection, DbName, options.Trace); } else if (options.SaveToCache) { if (this.deleteOnModelChange) { model = new SqlCacheModelDropOnModelChange(connection, DbName, options.Trace); } else { model = new SqlCacheModelUseExisting(connection, DbName, options.Trace); } } else { model = new SqlCacheModelNoCreate(connection, DbName, options.Trace); } return(new ClousotCache(model, options)); }
public IClousotCache Create(IClousotCacheOptions options) { Contract.Ensures(Contract.Result <IClousotCache>() != null); var model = new MemCacheModel(); return(new ClousotCache(model, options)); }
IClousotCache IClousotCacheFactory.Create(IClousotCacheOptions options) { if (existing == null) { var memCache = new MemClousotCacheFactory().Create(options); this.existing = new UndisposableCacheDataAccessor(memCache); } return(this.existing); }
public StdDB(IClousotCacheOptions options) : base(new IClousotCacheFactory[] { new SQLClousotCacheFactory(options.CacheServer), //new SQLClousotCacheFactory(@"localhost\sqlexpress", true), new LocalDbClousotCacheFactory(), }) { Contract.Requires(options != null); }
public StdDB(IClousotCacheOptions options) : base(new IClousotCacheFactory[] { new SQLClousotCacheFactory(options.CacheServer) , //new SQLClousotCacheFactory(@"localhost\sqlexpress", true), new LocalDbClousotCacheFactory(), }) { Contract.Requires(options != null); }
protected virtual SqlConnectionStringBuilder BuildConnectionString(IClousotCacheOptions options) { Contract.Requires(options != null); Contract.Ensures(Contract.Result <SqlConnectionStringBuilder>() != null); return(new SqlConnectionStringBuilder { IntegratedSecurity = true, InitialCatalog = options.GetCacheDBName(), DataSource = this.DbName, UserInstance = false, MultipleActiveResultSets = true, ConnectTimeout = options.CacheServerTimeout, }); }
protected override SqlConnectionStringBuilder BuildConnectionString(IClousotCacheOptions options) { if (!string.IsNullOrWhiteSpace(options.CacheDirectory)) { var name = options.GetCacheDBName(); return(new SqlConnectionStringBuilder { IntegratedSecurity = true, InitialCatalog = name, DataSource = this.DbName, UserInstance = false, MultipleActiveResultSets = true, ConnectTimeout = options.CacheServerTimeout, AttachDBFilename = Path.Combine(options.CacheDirectory.AssumeNotNull(), name + ".mdf") }); } return(base.BuildConnectionString(options)); }
public virtual IClousotCache Create(IClousotCacheOptions options) { if (this.cacheAccessor == null) // avoids locking if not necessary { lock (this.LockCacheAccessor) if (this.cacheAccessor == null) { foreach (var factory in this.cacheDataAccessorFactories) { this.cacheAccessor = factory.Create(options); //test the db connection if (this.cacheAccessor != null && this.cacheAccessor.TestCache()) { break; } this.cacheAccessor = null; } } } return(new UndisposableCacheDataAccessor(this.cacheAccessor)); }
public ClousotCache(ICacheModel model, IClousotCacheOptions options) { Contract.Requires(model != null); Contract.Requires(options != null); this.options = options; this.model = model; try { // force db initialization var ignored = this.model.Metadatas.FirstOrDefault(); if (model.IsFresh) { var md = model.NewMetadata(); md.Key = "Version"; md.Value = Encoding.UTF8.GetBytes(options.ClousotVersion.AssumeNotNull()); model.AddOrUpdate(md); model.SaveChanges(now: true); } } catch (Exception e) { // failed this.model = null; if (options.Trace) { Console.WriteLine("[cache] Cannot open cache: {0}", e.Message); for (var inner = e.InnerException; inner != null; inner = inner.InnerException) { Console.WriteLine("[cache] Inner Exception: {0}", inner.Message); } } } }
/// <summary> /// Extension method that creates cache asynchronously. /// </summary> /// <remarks> /// Task's result would be null if <see cref="factory"/>'s Create method returns null or when /// TestCache will return false. /// </remarks> public static Task<IClousotCache> CreateAndCheckAsync(this IClousotCacheFactory factory, IClousotCacheOptions options) { Contract.Requires(factory != null); Contract.Requires(options != null); // This implementation violates common TPL practice that suggest not to wrap // sync functions into async. But this helps to fix particular issue with // cache selection. // This implementation could be refined in the future by switching to appropriate // asynchronous implementation. return Task.Factory.StartNew(() => { var cache = factory.Create(options); if (cache == null || !cache.TestCache()) { return null; } return cache; }); }
IClousotCache IClousotCacheFactory.Create(IClousotCacheOptions options) { if (existing == null) { var memCache = new MemClousotCacheFactory().Create(options); this.existing = new UndisposableCacheDataAccessor(memCache); } return this.existing; }