/// <summary> /// Sets the view factory. /// </summary> /// <param name="path">The path.</param> public static void SetViewFactory(string path) { using (var rockContext = new RockContext()) { InteractiveViews.SetViewCacheFactory(rockContext, new FileViewCacheFactory(path)); } }
public void FileViewCache_creates_views_if_dont_exist() { if (File.Exists(ViewFileName)) { File.Delete(ViewFileName); } using (var ctx = new FileViewCacheModel()) { InteractiveViews.SetViewCacheFactory( ctx, new FileViewCacheFactory(ViewFileName)); ctx.Entities.Count(); Assert.True(File.Exists(ViewFileName)); var viewsXml = XDocument.Load(ViewFileName); Assert.Equal( ((StorageMappingItemCollection) ((IObjectContextAdapter)ctx).ObjectContext .MetadataWorkspace.GetItemCollection(DataSpace.CSSpace)).ComputeMappingHashValue(), (string)viewsXml.Descendants("mapping-views").Single().Attribute("hash")); } }
public void FileViewCache_creates_views_if_dont_exist() { using (var ctx = new DatabaseViewCacheModel()) { var connectionString = ctx.Database.Connection.ConnectionString; InteractiveViews .SetViewCacheFactory( ctx, new SqlServerViewCacheFactory(connectionString)); ctx.Entities.Count(); XDocument viewsXml; using (var viewCacheContext = new DatabaseViewCacheContext(new SqlConnection(connectionString))) { viewsXml = XDocument.Parse(viewCacheContext.ViewCache.Single().ViewDefinitions); } Assert.Equal( ((StorageMappingItemCollection) ((IObjectContextAdapter)ctx).ObjectContext .MetadataWorkspace.GetItemCollection(DataSpace.CSSpace)).ComputeMappingHashValue(), (string)viewsXml.Descendants("mapping-views").Single().Attribute("hash")); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // Precompile views for entityframework var hp = DependencyResolver.Current.GetService <Ihp>(); if (hp.getStringFromAppConfig("usingPrecompileViews") == "true") { using (var context = new ExampleDB()) { // Build route from separated commas values in app.config var path = hp.getPathFromSeparatedCommaValue("preCompileViewEFInAppData"); InteractiveViews.SetViewCacheFactory ( context, new FileViewCacheFactory(path) ); } } }
public static void Main(string[] args) { var commandLineParser = new FluentCommandLineParser <Options>(); commandLineParser .Setup(options => options.Prefix) .As("prefix") .SetDefault("http://*****:*****@"views.xml")); } RunServer(commandLineParser.Object); }
public void Setup() { entities = new TestEntities(); InteractiveViews.SetViewCacheFactory( entities, new FileViewCacheFactory( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\70487AccessingData\EFCache\Cache.xml")); }
static MasterContext() { Database.SetInitializer <MasterContext>(null); using (var context = new MasterContext()) { InteractiveViews.SetViewCacheFactory(context, new SqlServerViewCacheFactory(_connectionString, "EntityFrameworkViewCache", "app")); } }
public static void EnableViewCache() { if (!DataAccess.Configuration.Database.EnableViewCache) { return; } using (var ctx = new EntityContext()) { InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); } }
static ContextDb() { Database.SetInitializer <ContextDb>(null); Log = LogManager.GetLogger(typeof(ContextDb)); using (var ctx = new ContextDb()) { InteractiveViews .SetViewCacheFactory( ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); } }
private void SetCache() { using (var ctx = new TuiContext()) { try { InteractiveViews .SetViewCacheFactory( ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); } catch (Exception) { Debug.WriteLine("not available"); } } }
public SFSServiceDeskContext(string conn, string pathCacheViews) : base(conn) { Database.SetInitializer(new NullDatabaseInitializer <SFSServiceDeskContext>()); Configuration.ProxyCreationEnabled = false; if (!string.IsNullOrEmpty(pathCacheViews)) { if (!InteractiveViewsHelper.Attached(this)) { try{ InteractiveViews.SetViewCacheFactory(this, new FileViewCacheFactory(pathCacheViews + @"MyViews.xml")); }catch { } } } }
public static void RegisterPrecompileViews() { // Precompile views for entityframework var hp = DependencyResolver.Current.GetService <Ihp>(); var changeDb = DependencyResolver.Current.GetService <IChangeDbConnection>(); bool usePrecomplieViews = hp.getStringFromAppConfig("usingPrecompileViews") == "true"; // Set configuration using (var context = new BaseContext(changeDb)) { if (usePrecomplieViews) { // Build route from separated commas values in app.config var path = hp.getPathFromSeparatedCommaValue("preCompileViewEFInAppData"); InteractiveViews.SetViewCacheFactory ( context, new FileViewCacheFactory(path) ); } } }
public PortfolioTrackerContext() : base("name=PortfolioTrackerContext") { InteractiveViews.SetViewCacheFactory(this, new FileViewCacheFactory("./DbContextViews.xml")); }
/// <summary> /// Force EF to generate the Model Metadata. /// </summary> public static void GenerateViews(string viewCachePath, ILog log = null) { // Use the provided ILog instance or create our own. log = log ?? LogProvider.Get(typeof(ContextPreloader)); log.Debug("View Cache Directory set to: {0}", viewCachePath); var admin = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new AdministrationDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\AdministrationDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Agency>().ToString(); timer.Stop(); log.Debug("AdministrationDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var reports = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new ReportsDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\ReportsDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Report>().ToString(); timer.Stop(); log.Debug("ReportsDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var summaries = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new SummariesDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\SummariesDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <Summary>().ToString(); timer.Stop(); log.Debug("SummariesDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var recentInfo = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new RecentInfoDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\RecentInfoDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <RecentEvent>().ToString(); timer.Stop(); log.Debug("RecentInfoDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var messaging = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new MessagingDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\MessagingDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.Set <MessageLog>().ToString(); timer.Stop(); log.Debug("MessagingDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); var audit = Task.Factory.StartNew(() => { var timer = Stopwatch.StartNew(); var ctx = new AuditDbContext(); InteractiveViews.SetViewCacheFactory(ctx, new FileViewCacheFactory(String.Format("{0}\\AuditDbContext.xml", viewCachePath))); //InteractiveViews.SetViewCacheFactory(ctx, new SqlServerViewCacheFactory(ctx.Database.Connection.ConnectionString)); ctx.AuditEntities.ToString(); timer.Stop(); log.Debug("AuditDbContext Initialized in {0}ms", timer.ElapsedMilliseconds); }); Task.WaitAll(admin, reports, summaries, recentInfo, messaging, audit); }