コード例 #1
0
ファイル: Program2.cs プロジェクト: ikvm/dotvvm
        private static CompilationResult DoFullCompile(CompilerOptions options)
        {
            var compiler = new ViewStaticCompilerCompiler();

            compiler.Options = options;
            return(compiler.Execute());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: darilek/dotvvm
 static bool DoCompile(string optionsJson)
 {
     sw = Stopwatch.StartNew();
     WriteInfo("Starting");
     try
     {
         var compiler = new ViewStaticCompilerCompiler();
         compiler.Options = JsonConvert.DeserializeObject<CompilerOptions>(optionsJson);
         if (!String.IsNullOrEmpty(compiler.Options.WebSiteAssembly))
         {
             AssemblySearchPaths.Add(Path.GetDirectoryName(compiler.Options.WebSiteAssembly));
         }
         var result = compiler.Execute();
         Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
         Console.WriteLine();
         return true;
     }
     catch (Exception ex)
     {
         WriteInfo("Error occured!");
         var exceptionJson = JsonConvert.SerializeObject(ex);
         Console.WriteLine("!" + exceptionJson);
         Console.WriteLine();
         return false;
     }
 }
コード例 #3
0
 static bool DoCompile(string optionsJson)
 {
     sw = Stopwatch.StartNew();
     WriteInfo("Starting");
     try
     {
         var compiler = new ViewStaticCompilerCompiler();
         compiler.Options = JsonConvert.DeserializeObject <CompilerOptions>(optionsJson);
         if (!String.IsNullOrEmpty(compiler.Options.WebSiteAssembly))
         {
             AssemblySearchPaths.Add(Path.GetDirectoryName(compiler.Options.WebSiteAssembly));
         }
         var result = compiler.Execute();
         Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
         Console.WriteLine();
         return(true);
     }
     catch (Exception ex)
     {
         WriteInfo("Error occured!");
         var exceptionJson = JsonConvert.SerializeObject(ex);
         Console.WriteLine("!" + exceptionJson);
         Console.WriteLine();
         return(false);
     }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: fabbbiob/dotvvm
        private static bool DoCompile(CompilerOptions options)
        {
            InitStopwacher();
            WriteInfo("Starting");

            //Dont touch anything until the paths are filled we have to touch Json though
            try
            {
                var compiler = new ViewStaticCompilerCompiler();
                compiler.Options = options;

                var result = compiler.Execute();
                Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
                Console.WriteLine();
                return(true);
            }
            catch (Exception ex)
            {
                WriteError(ex);
                return(false);
            }
        }
コード例 #5
0
        public static DotvvmConfiguration InitDotVVM(Assembly webSiteAssembly, string webSitePath, ViewStaticCompilerCompiler viewStaticCompilerCompiler, Action <IServiceCollection> registerServices)
        {
            var dotvvmStartups = webSiteAssembly.GetLoadableTypes()
                                 .Where(t => typeof(IDotvvmStartup).IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null).ToArray();

            if (dotvvmStartups.Length > 1)
            {
                throw new Exception($"Found more than one implementation of IDotvvmStartup ({string.Join(", ", dotvvmStartups.Select(s => s.Name)) }).");
            }
            var startup = dotvvmStartups.SingleOrDefault()?.Apply(Activator.CreateInstance).CastTo <IDotvvmStartup>();

            var configureServices =
                webSiteAssembly.GetLoadableTypes()
                .Where(t => t.Name == "Startup")
                .Select(t => t.GetMethod("ConfigureDotvvmServices", new[] { typeof(IServiceCollection) }) ?? t.GetMethod("ConfigureServices", new[] { typeof(IServiceCollection) }))
                .Where(m => m != null)
                .Where(m => m.IsStatic || m.DeclaringType.GetConstructor(Type.EmptyTypes) != null)
                .ToArray();

            if (startup == null && configureServices.Length == 0)
            {
                throw new Exception($"Could not find ConfigureServices method, nor a IDotvvmStartup implementation.");
            }

            var config = DotvvmConfiguration.CreateDefault(
                services =>
            {
                if (viewStaticCompilerCompiler != null)
                {
                    services.AddSingleton <ViewStaticCompilerCompiler>(viewStaticCompilerCompiler);
                    services.AddSingleton <IControlResolver, OfflineCompilationControlResolver>();
                }
                registerServices?.Invoke(services);
                foreach (var cs in configureServices)
                {
                    cs.Invoke(cs.IsStatic ? null : Activator.CreateInstance(cs.DeclaringType), new object[] { services });
                }
            });

            config.ApplicationPhysicalPath = webSitePath;
            startup?.Configure(config, webSitePath);
            config.CompiledViewsAssemblies = null;

            var configurers = config.ServiceProvider.GetServices <IConfigureOptions <DotvvmConfiguration> >().ToArray();

            if (startup == null && configurers.Length == 0)
            {
                throw new Exception($"Could not find any IConfigureOptions<DotvvmConfiguration> nor a IDotvvmStartup implementation.");
            }
            foreach (var configurer in configurers)
            {
                configurer.Configure(config);
            }

            return(config);
        }
コード例 #6
0
ファイル: OwinInitializer.cs プロジェクト: fabbbiob/dotvvm
        public static DotvvmConfiguration InitDotVVM(Assembly webSiteAssembly, string webSitePath, ViewStaticCompilerCompiler viewStaticCompilerCompiler, Action <DotvvmConfiguration, IServiceCollection> registerServices)
        {
            var dotvvmStartups = webSiteAssembly.GetLoadableTypes()
                                 .Where(t => typeof(IDotvvmStartup).IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null).ToArray();

            if (dotvvmStartups.Length == 0)
            {
                throw new Exception("Could not find any implementation of IDotvvmStartup.");
            }
            if (dotvvmStartups.Length > 1)
            {
                throw new Exception($"Found more than one implementation of IDotvvmStartup ({string.Join(", ", dotvvmStartups.Select(s => s.Name)) }).");
            }

            var startup = (IDotvvmStartup)Activator.CreateInstance(dotvvmStartups[0]);
            IServiceCollection serviceCollection = null;
            var config = DotvvmConfiguration.CreateDefault(
                services =>
            {
                serviceCollection = services;
                services.AddSingleton <ViewStaticCompilerCompiler>(viewStaticCompilerCompiler);
                services.AddSingleton <IControlResolver, OfflineCompilationControlResolver>();
            });

            registerServices(config, serviceCollection);
            startup.Configure(config, webSitePath);
            config.CompiledViewsAssemblies = null;
            return(config);
        }
コード例 #7
0
 public OfflineCompilationControlResolver(DotvvmConfiguration config, ViewStaticCompilerCompiler compiler)
     : base(config)
 {
     this.compiler = compiler;
 }
コード例 #8
0
 public OfflineCompilationControlResolver(DotvvmConfiguration config, ViewStaticCompilerCompiler compiler)
     : base(config)
 {
     this.compiler = compiler;
 }
コード例 #9
0
        public static DotvvmConfiguration InitDotVVM(Assembly webSiteAssembly, string webSitePath, ViewStaticCompilerCompiler viewStaticCompilerCompiler, Action <IServiceCollection> registerServices)
        {
            var dotvvmStartups = webSiteAssembly.GetLoadableTypes()
                                 .Where(t => typeof(IDotvvmStartup).IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null).ToArray();

            if (dotvvmStartups.Length > 1)
            {
                throw new Exception($"Found more than one implementation of IDotvvmStartup ({string.Join(", ", dotvvmStartups.Select(s => s.Name)) }).");
            }
            var startup = dotvvmStartups.SingleOrDefault()?.Apply(Activator.CreateInstance).CastTo <IDotvvmStartup>();

            var configureServices =
                webSiteAssembly.GetLoadableTypes()
                .Where(t => t.Name == "Startup")

                .Select(t => t.GetMethod("ConfigureDotvvmServices", new[] { typeof(IServiceCollection) }) ?? t.GetMethod("ConfigureServices", new[] { typeof(IServiceCollection) }))
                .Where(m => m != null)
                .Where(m => m.IsStatic || m.DeclaringType.GetConstructor(Type.EmptyTypes) != null)
                .ToArray();

            // TODO: run startup class to get configuration from dotvvm middleware

            var startupClass = webSiteAssembly.CustomAttributes?.Where(s => s.AttributeType == typeof(Microsoft.Owin.OwinStartupAttribute)).FirstOrDefault()?.ConstructorArguments[0].Value as Type;

            //if (startupClass != null)
            //{

            //    var configureMethod = startupClass.GetRuntimeMethods().FirstOrDefault(s =>
            //        s.Name == "Configuration" && s.GetParameters().Length == 1 &&
            //        s.GetParameters()[0].ParameterType == typeof(IAppBuilder));
            //    var app = new CompilerAppBuilder();

            //    var startupClassInstance = Activator.CreateInstance(startupClass);

            //    var debug = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes())
            //        .Where(s => s.Name == "AppBuilderExtension").ToList();

            //    configureMethod.Invoke(startupClassInstance, new object[] { app });

            //    var config2 = (DotvvmConfiguration)app.args[0];
            //}



            if (startup == null && configureServices.Length == 0)
            {
                throw new Exception($"Could not find ConfigureServices method, nor a IDotvvmStartup implementation.");
            }

            var config = DotvvmConfiguration.CreateDefault(
                services => {
                if (viewStaticCompilerCompiler != null)
                {
                    services.AddSingleton <ViewStaticCompilerCompiler>(viewStaticCompilerCompiler);
                    services.AddSingleton <IControlResolver, OfflineCompilationControlResolver>();
                    services.TryAddSingleton <IViewModelProtector, FakeViewModelProtector>();
                }
                registerServices?.Invoke(services);
                foreach (var cs in configureServices)
                {
                    cs.Invoke(cs.IsStatic ? null : Activator.CreateInstance(cs.DeclaringType), new object[] { services });
                }
            });

            config.ApplicationPhysicalPath = webSitePath;
            startup?.Configure(config, webSitePath);
            config.CompiledViewsAssemblies = null;

            var configurers = config.ServiceProvider.GetServices <IConfigureOptions <DotvvmConfiguration> >().ToArray();

            if (startup == null && configurers.Length == 0)
            {
                throw new Exception($"Could not find any IConfigureOptions<DotvvmConfiguration> nor a IDotvvmStartup implementation.");
            }
            foreach (var configurer in configurers)
            {
                configurer.Configure(config);
            }

            return(config);
        }
コード例 #10
0
 public OfflineCompilationControlResolver(DotvvmMarkupConfiguration config, IControlBuilderFactory controlBuilderFactory, ViewStaticCompilerCompiler compiler)
     : base(config, controlBuilderFactory)
 {
     this.compiler = compiler;
 }