Esempio n. 1
0
        public override bool Execute()
        {
            Console.WriteLine($"ApplicationPath: {ApplicationPath}");

            var finder       = new AttributeFinder();
            var assemblyPath = ApplicationPath;
            var foundType    = finder.FindAttribute(assemblyPath);

            Console.WriteLine(foundType);

            if (foundType != null)
            {
                var cacheGenerator = new CacheWarmupGenerator();

                var cacheResult = cacheGenerator.WarmupCache(assemblyPath, foundType);
                if (cacheResult != null)
                {
                    DcAssembly         = cacheResult.DcAssemblyFilePath;
                    ModelAssembly      = cacheResult.ModelAssemblyFilePath;
                    ModelCache         = cacheResult.ModelCacheFilePath;
                    ModulesVersionInfo = cacheResult.ModulesVersionInfoFilePath;

                    Console.WriteLine("Done");
                    return(true);
                }
            }

            return(false);
        }
        public override bool Execute()
        {
            Log.LogMessage($"ApplicationPath: {ApplicationPath}");
            Log.LogMessage($"Mode: {Mode}");

            if (Mode == "InProcess")
            {
                var finder       = new AttributeFinder();
                var assemblyPath = ApplicationPath;
                var foundType    = finder.FindAttribute(assemblyPath);

                Console.WriteLine(foundType);

                if (foundType != null)
                {
                    var cacheGenerator = new CacheWarmupGenerator();

                    var cacheResult = cacheGenerator.WarmupCache(assemblyPath, foundType.ApplicationType, foundType.FactoryType);
                    if (cacheResult != null)
                    {
                        DcAssembly         = cacheResult.DcAssemblyFilePath;
                        ModelAssembly      = cacheResult.ModelAssemblyFilePath;
                        ModelCache         = cacheResult.ModelCacheFilePath;
                        ModulesVersionInfo = cacheResult.ModulesVersionInfoFilePath;

                        Console.WriteLine("Done");
                        return(true);
                    }
                }
            }

            if (Mode == "OutOfProcess")
            {
                if (string.IsNullOrEmpty(CliPath))
                {
                    CliPath = Path.Combine(Path.GetDirectoryName(ApplicationPath), "Scissors.Xaf.CacheWarmup.Generators.Cli");
                }

                using (var process = new Process())
                {
                    process.StartInfo = new ProcessStartInfo(CliPath, ApplicationPath)
                    {
                        RedirectStandardOutput = true,
                        WindowStyle            = ProcessWindowStyle.Hidden,
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        WorkingDirectory       = Path.GetDirectoryName(ApplicationPath)
                    };
                    process.OutputDataReceived += (s, e) => Log.LogMessage(e.Data);
                    if (process.Start())
                    {
                        process.WaitForExit(10000);
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var finder       = new AttributeFinder();
            var assemblyPath = args[0];
            var mode         = Mode.OutOfProcess;
            var foundType    = finder.FindAttribute(assemblyPath, mode);

            Console.WriteLine(foundType);

            if (foundType != null)
            {
                var cacheGenerator = new CacheWarmupGenerator();

                var cacheResult = cacheGenerator.WarmupCache(assemblyPath, foundType.ApplicationType, foundType.FactoryType, mode);
                if (cacheResult != null)
                {
                }
            }

            Console.WriteLine("Done");
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var finder       = new AttributeFinder();
            var assemblyPath = @"C:\F\github\how-to-precache-an-xaf-winforms-application\src\PreCacheDemo.Win\bin\Debug\PreCacheDemo.Win.exe";
            var foundType    = finder.FindAttribute(assemblyPath);

            Console.WriteLine(foundType);

            if (foundType != null)
            {
                var cacheGenerator = new CacheWarmupGenerator();

                var cacheResult = cacheGenerator.WarmupCache(assemblyPath, foundType);
                if (cacheResult != null)
                {
                }
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            var assemblyPath = args[0];

            Console.WriteLine($"ARGUMENTS: '{assemblyPath}'");
            var assemblyDirectory = Path.GetDirectoryName(assemblyPath);

            Console.WriteLine($"AssemblyDirectory: '{assemblyDirectory}'");

            Console.WriteLine("Clean All old asserts");

            foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(typeof(Program).Assembly.Location)))
            {
                if (file == typeof(Program).Assembly.Location)
                {
                    continue;
                }
                if (File.Exists(file))
                {
                    Console.WriteLine($"Deleting: {file}");
                    File.Delete(file);
                }
            }

            AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs e) =>
            {
                Console.WriteLine($"AssemblyResolve: {e.Name}");
                var assemblyName = e.Name.Split(',').First();
                var aPath        = Path.Combine(assemblyDirectory, assemblyName + ".dll");
                Console.WriteLine($"New AssemblyPath: '{aPath}'");
                if (File.Exists(aPath))
                {
                    Console.WriteLine($"New AssemblyPath exists!: '{aPath}'");
                    var loadedAssembly = Assembly.LoadFile(aPath);
                    Console.WriteLine($"New Assembly?: '{loadedAssembly}'");
                    return(loadedAssembly);
                }

                return(null);
            };

            var finder = new AttributeFinder();

            Console.WriteLine($"Loading Assembly: {assemblyPath}");
            var assembly = Assembly.LoadFile(assemblyPath);

            Console.WriteLine($"Loaded Assembly: {assembly.GetName().FullName}");
            Console.WriteLine($"Try To Find Type");
            var foundType = finder.FindAttribute(assembly);

            Console.WriteLine($"Found-Type: '{foundType}'");

            if (foundType != null)
            {
                var cacheGenerator = new CacheWarmupGenerator();

                var cacheResult = cacheGenerator.WarmupCache(assembly, foundType.ApplicationType, foundType.FactoryType);
                if (cacheResult != null)
                {
                    CopyFile(cacheResult.DcAssemblyFilePath, assemblyDirectory);
                    CopyFile(cacheResult.ModelAssemblyFilePath, assemblyDirectory);
                    CopyFile(cacheResult.ModelCacheFilePath, assemblyDirectory);
                    CopyFile(cacheResult.ModulesVersionInfoFilePath, assemblyDirectory);
                }
            }

            Console.WriteLine("Done");
        }