Esempio n. 1
0
        /// <summary>
        /// Warmup's the cache.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <param name="xafApplicationTypeName">Name of the xaf application type.</param>
        /// <param name="xafApplicationFactoryTypeName">Name of the xaf application factory type.</param>
        /// <returns></returns>
        public CacheWarmupGeneratorResponse WarmupCache(Assembly assembly, string xafApplicationTypeName, string xafApplicationFactoryTypeName)
        {
            var applicationType = assembly.GetType(xafApplicationTypeName);

            if (applicationType != null)
            {
                WriteLine($"Found {xafApplicationTypeName} in {assembly.Location}");

                var factory = string.IsNullOrEmpty(xafApplicationFactoryTypeName)
                    ? new Func <System.IDisposable>(() => (System.IDisposable)applicationType.CreateInstance())
                    : new Func <System.IDisposable>(() =>
                {
                    WriteLine($"Try to find {xafApplicationFactoryTypeName} in {assembly.Location}");
                    var factoryType = assembly.GetType(xafApplicationFactoryTypeName);
                    var f           = factoryType.CreateInstance();
                    return((System.IDisposable)f.CallMethod("CreateApplication"));
                });

                WriteLine($"Creating Application");
                using (var xafApplication = factory())
                {
                    WriteLine($"Created Application");
                    WriteLine($"Remove SplashScreen");
                    xafApplication.SetPropertyValue("SplashScreen", null);
                    WriteLine($"Set DatabaseUpdateMode: 'Never'");
                    xafApplication.SetPropertyValue("DatabaseUpdateMode", 0);
                    WriteLine($"Set EnableModelCache: 'true'");
                    xafApplication.SetPropertyValue("EnableModelCache", true);

                    WriteLine($"Setting up application");
                    WriteLine($"Starting cache warmup");
                    xafApplication.CallMethod("Setup");
                    WriteLine($"Setup application done.");
                    WriteLine($"Wormed up caches.");

                    var dcAssemblyFilePath         = (string)xafApplication.CallMethod(getDcAssemblyFilePath);
                    var modelAssemblyFilePath      = (string)xafApplication.CallMethod(getModelAssemblyFilePath);
                    var modelCacheFileLocationPath = (string)xafApplication.CallMethod(getModelCacheFileLocationPath);
                    var modulesVersionInfoFilePath = (string)xafApplication.CallMethod(getModulesVersionInfoFilePath);

                    var cacheResult = new CacheWarmupGeneratorResponse
                    {
                        DcAssemblyFilePath         = dcAssemblyFilePath,
                        ModelAssemblyFilePath      = modelAssemblyFilePath,
                        ModelCacheFilePath         = Path.Combine(modelCacheFileLocationPath, "Model.Cache.xafml"),
                        ModulesVersionInfoFilePath = modulesVersionInfoFilePath
                    };

                    WriteLine($"{nameof(cacheResult.DcAssemblyFilePath)}: {cacheResult.DcAssemblyFilePath}");
                    WriteLine($"{nameof(cacheResult.ModelAssemblyFilePath)}: {cacheResult.ModelAssemblyFilePath}");
                    WriteLine($"{nameof(cacheResult.ModelCacheFilePath)}: {cacheResult.ModelCacheFilePath}");
                    WriteLine($"{nameof(cacheResult.ModulesVersionInfoFilePath)}: {cacheResult.ModulesVersionInfoFilePath}");

                    return(cacheResult);
                }
            }

            return(null);
        }
Esempio n. 2
0
        public CacheWarmupGeneratorResponse WarmupCache(string assemblyPath, string xafApplicationTypeName)
        {
            using (var context = AppDomainContext.Create(new AppDomainSetup
            {
                ApplicationBase = Path.GetDirectoryName(typeof(CacheWarmupGenerator).Assembly.Location),
                PrivateBinPath = Path.GetDirectoryName(assemblyPath),
                ConfigurationFile = $"{assemblyPath}.config"
            }))
            {
                context.LoadAssemblyWithReferences(LoadMethod.LoadFile, assemblyPath);
                return(RemoteFunc.Invoke(context.Domain, new CacheWarmupGeneratorRequest
                {
                    AssemblyPath = assemblyPath,
                    XafApplicationTypeName = xafApplicationTypeName,
                },
                                         (args) =>
                {
                    WriteLine($"Try to find {args.XafApplicationTypeName} in {args.AssemblyPath}");
                    var assembly = AppDomain.CurrentDomain.GetAssemblies().First(b => b.Location == args.AssemblyPath);
                    var applicationType = assembly.GetType(args.XafApplicationTypeName);

                    if (applicationType != null)
                    {
                        WriteLine($"Found {args.XafApplicationTypeName} in {args.AssemblyPath}");

                        WriteLine($"Creating Application");
                        using (var xafApplication = (System.IDisposable)applicationType.CreateInstance())
                        {
                            WriteLine($"Created Application");
                            WriteLine($"Remove SplashScreen");
                            xafApplication.SetPropertyValue("SplashScreen", null);
                            WriteLine($"Set DatabaseUpdateMode: 'Never'");
                            xafApplication.SetPropertyValue("DatabaseUpdateMode", 0);

                            WriteLine($"Setting up application");
                            WriteLine($"Starting cache warmup");
                            xafApplication.CallMethod("Setup");
                            WriteLine($"Setup application done.");
                            WriteLine($"Wormed up caches.");

                            var dcAssemblyFilePath = (string)xafApplication.CallMethod(GetDcAssemblyFilePath);
                            var modelAssemblyFilePath = (string)xafApplication.CallMethod(GetModelAssemblyFilePath);
                            var modelCacheFileLocationPath = (string)xafApplication.CallMethod(GetModelCacheFileLocationPath);
                            var modulesVersionInfoFilePath = (string)xafApplication.CallMethod(GetModulesVersionInfoFilePath);

                            var cacheResult = new CacheWarmupGeneratorResponse
                            {
                                DcAssemblyFilePath = dcAssemblyFilePath,
                                ModelAssemblyFilePath = modelAssemblyFilePath,
                                ModelCacheFilePath = modelCacheFileLocationPath,
                                ModulesVersionInfoFilePath = modulesVersionInfoFilePath
                            };

                            WriteLine($"{nameof(cacheResult.DcAssemblyFilePath)}: {cacheResult.DcAssemblyFilePath}");
                            WriteLine($"{nameof(cacheResult.ModelAssemblyFilePath)}: {cacheResult.ModelAssemblyFilePath}");
                            WriteLine($"{nameof(cacheResult.ModelCacheFilePath)}: {cacheResult.ModelCacheFilePath}");
                            WriteLine($"{nameof(cacheResult.ModulesVersionInfoFilePath)}: {cacheResult.ModulesVersionInfoFilePath}");

                            return cacheResult;
                        }
                    }

                    return null;
                }));
            }
        }