Exemplo n.º 1
0
        private CompilationResult GetCompilation(RazorProjectItem projectItem, RazorProjectFileSystem projectFileSystem)
        {
            using (IServiceScope scope = _serviceScopeFactory.CreateScope())
            {
                IServiceProvider serviceProvider = scope.ServiceProvider;

                // See RazorViewCompiler.CompileAndEmit()
                RazorProjectEngine  projectEngine  = serviceProvider.GetRequiredService <RazorProjectEngine>();
                RazorCodeDocument   codeDocument   = projectEngine.Process(projectItem);
                RazorCSharpDocument cSharpDocument = codeDocument.GetCSharpDocument();
                if (cSharpDocument.Diagnostics.Count > 0)
                {
                    throw (Exception)CreateCompilationFailedException.Invoke(
                              null,
                              new object[] { codeDocument, cSharpDocument.Diagnostics });
                }

                // Use the RazorViewCompiler to finish compiling the view for consistency with layouts
                IViewCompilerProvider viewCompilerProvider = serviceProvider.GetRequiredService <IViewCompilerProvider>();
                IViewCompiler         viewCompiler         = viewCompilerProvider.GetCompiler();
                Assembly assembly = (Assembly)CompileAndEmitMethod.Invoke(
                    viewCompiler,
                    new object[] { codeDocument, cSharpDocument.GeneratedCode });

                // Get the runtime item
                RazorCompiledItemLoader compiledItemLoader = new RazorCompiledItemLoader();
                RazorCompiledItem       compiledItem       = compiledItemLoader.LoadItems(assembly).SingleOrDefault();
                return(new CompilationResult(compiledItem));
            }
        }
Exemplo n.º 2
0
        private void Init()
        {
            // touch assembly
            SyntaxFactory.Token(SyntaxKind.NullKeyword);

            InitOptions();
            if (Options.FullCompile)
                if (!Directory.Exists(Options.OutputPath)) Directory.CreateDirectory(Options.OutputPath);
            var wsa = assemblyDictionary.GetOrAdd(Options.WebSiteAssembly, _ => Assembly.LoadFrom(Options.WebSiteAssembly));
            configuration = GetCachedConfiguration(wsa, Options.WebSitePath);
            bindingCompiler = new AssemblyBindingCompiler(Options.BindingsAssemblyName, Options.BindingClassName, Path.Combine(Options.OutputPath, Options.BindingsAssemblyName + ".dll"), configuration);
            configuration.ServiceLocator.RegisterSingleton<IBindingCompiler>(() => bindingCompiler);
            configuration.ServiceLocator.RegisterSingleton<IControlResolver>(() => new OfflineCompilationControlResolver(configuration, this));
            if (Options.DothtmlFiles == null) Options.DothtmlFiles = configuration.RouteTable.Select(r => r.VirtualPath).ToArray();
            controlTreeResolver = configuration.ServiceLocator.GetService<IControlTreeResolver>();
            fileLoader = configuration.ServiceLocator.GetService<IMarkupFileLoader>();
            if (Options.FullCompile)
            {
                compiler = configuration.ServiceLocator.GetService<IViewCompiler>();
                compilation = compiler.CreateCompilation(Options.AssemblyName);
            }

            if (Options.SerializeConfig)
            {
                result.Configuration = configuration;
            }

            // touch assemblies
        }
Exemplo n.º 3
0
        //*** JavaScript View ***//

        private Couchbase.Lite.View CompileView(Database db, string viewName, JObject viewProps)
        {
            JToken language;

            if (!viewProps.TryGetValue("language", out language))
            {
                language = "javascript";
            }
            JToken mapSource;

            if (!viewProps.TryGetValue("map", out mapSource))
            {
                return(null);
            }

            IViewCompiler viewCompiler = Couchbase.Lite.View.Compiler;
            IViewCompiler test         = new JSViewCompilerCopy();

            Couchbase.Lite.View.Compiler = test;
            MapDelegate mapBlock = Couchbase.Lite.View.Compiler.CompileMap(mapSource.Value <string>(), language.Value <string>());

            if (mapBlock == null)
            {
                return(null);
            }

            string mapID = db.Name + ":" + viewName + ":" + mapSource.Value <string>().GetHashCode();

            JToken         reduceSource = null;
            ReduceDelegate reduceBlock  = null;

            if (viewProps.TryGetValue("reduce", out reduceSource))
            {
                // Couchbase.Lite.View.compiler est null et Couchbase.Lite.Listener.JSViewCompiler est inaccessible (même avec la reflection)

                reduceBlock = Couchbase.Lite.View.Compiler.CompileReduce(reduceSource.Value <string>(), language.Value <string>());
                if (reduceBlock == null)
                {
                    return(null);
                }
                mapID += ":" + reduceSource.Value <string>().GetHashCode();
            }

            Couchbase.Lite.View view = db.GetView(viewName);
            view.SetMapReduce(mapBlock, reduceBlock, mapID);
            JToken collation = null;

            if (viewProps.TryGetValue("collation", out collation))
            {
                if ("raw".Equals((String)collation))
                {
                    // ???
                }
            }

            return(view);
        }
Exemplo n.º 4
0
    private IViewCompilerProvider GetCompilerProvider(IViewCompiler cache)
    {
        var compilerCacheProvider = new Mock <IViewCompilerProvider>();

        compilerCacheProvider
        .Setup(c => c.GetCompiler())
        .Returns(cache);

        return(compilerCacheProvider.Object);
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExecutionSIIntegrationTest"/> class
 /// </summary>
 /// <param name="roslynCompilationService">The compilation service needed (set in startup.cs)</param>
 /// <param name="repositorySettings">The repository setting service needed (set in startup.cs)</param>
 /// <param name="packageRepository">The service package repository</param>
 /// <param name="repository">The repository </param>
 public ExecutionSIIntegrationTest(
     IViewCompiler roslynCompilationService,
     IOptions <ServiceRepositorySettings> repositorySettings,
     IServicePackageRepository packageRepository,
     IRepository repository)
 {
     _packageRepository = packageRepository;
     _repository        = repository;
     _settings          = repositorySettings.Value;
     _compilation       = (CustomRoslynCompilationService)roslynCompilationService;
 }
Exemplo n.º 6
0
        public ViewEngineFixture()
        {
            this.templateLocator = A.Fake<IViewLocator>();
            this.viewCompiler = A.Fake<IViewCompiler>();
            this.view = A.Fake<IView>();
            this.viewLocationResult = new ViewLocationResult(@"c:\some\fake\path", null);

            A.CallTo(() => templateLocator.GetTemplateContents("test")).Returns(viewLocationResult);
            A.CallTo(() => viewCompiler.GetCompiledView<object>(null)).Returns(view);
            A.CallTo(() => viewCompiler.GetCompiledView<MemoryStream>(null)).Returns(view);

            this.engine = new ViewEngine(templateLocator, viewCompiler);
        }
Exemplo n.º 7
0
        private void Init()
        {
            if (Options.FullCompile)
            {
                // touch assembly
                SyntaxFactory.Token(SyntaxKind.NullKeyword);
                InitOptions();

                if (!Directory.Exists(Options.OutputPath))
                {
                    Directory.CreateDirectory(Options.OutputPath);
                }
            }

            var wsa = assemblyDictionary.GetOrAdd(Options.WebSiteAssembly, _ => Assembly.LoadFile(Options.WebSiteAssembly));

            configuration = GetCachedConfiguration(wsa, Options.WebSitePath,
                                                   (services) => {
                if (Options.FullCompile)
                {
                    throw new NotImplementedException();
                    //TODO: LAST PARAMETER | bindingCompiler = new AssemblyBindingCompiler(Options.BindingsAssemblyName, Options.BindingClassName, Path.Combine(Options.OutputPath, Options.BindingsAssemblyName + ".dll"), null);
                    services.AddSingleton <IBindingCompiler>(bindingCompiler);
                    services.AddSingleton <IExpressionToDelegateCompiler>(bindingCompiler.GetExpressionToDelegateCompiler());
                }
            });
            if (Options.SerializeConfig)
            {
                result.Configuration = configuration;
            }

            if (Options.DothtmlFiles == null)
            {
                Options.DothtmlFiles = configuration.RouteTable.Select(r => r.VirtualPath).Where(r => !string.IsNullOrWhiteSpace(r)).ToArray();
            }


            if (Options.FullCompile || Options.CheckBindingErrors)
            {
                compiledAssemblyCache = configuration.ServiceProvider.GetService <CompiledAssemblyCache>();
                controlTreeResolver   = configuration.ServiceProvider.GetService <IControlTreeResolver>();
                fileLoader            = configuration.ServiceProvider.GetService <IMarkupFileLoader>();
            }

            if (Options.FullCompile)
            {
                compiler    = configuration.ServiceProvider.GetService <IViewCompiler>();
                compilation = compiler.CreateCompilation(Options.AssemblyName);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompilationSI"/> class.
 /// </summary>
 /// <param name="configuration">The configuration</param>
 /// <param name="partManager">The part manager</param>
 /// <param name="compilationService">The compilation service</param>
 /// <param name="repositoryService">The service repository service</param>
 /// <param name="logger">The logger</param>
 public CompilationSI(
     IOptions <ServiceRepositorySettings> configuration,
     ApplicationPartManager partManager,
     IViewCompiler compilationService,
     IRepository repositoryService,
     ILogger <CompilationSI> logger,
     IHttpContextAccessor httpContextAccessor)
 {
     _repository          = repositoryService;
     _settings            = configuration.Value;
     _partManager         = partManager;
     _roslynCompilation   = (CustomRoslynCompilationService)compilationService;
     _logger              = logger;
     _httpContextAccessor = httpContextAccessor;
 }
Exemplo n.º 9
0
        private void Init()
        {
            if (Options.FullCompile)
            {
                // touch assembly
                SyntaxFactory.Token(SyntaxKind.NullKeyword);
                InitOptions();

                if (!Directory.Exists(Options.OutputPath))
                {
                    Directory.CreateDirectory(Options.OutputPath);
                }
            }

            var wsa = assemblyDictionary.GetOrAdd(Options.WebSiteAssembly, _ => Assembly.LoadFile(Options.WebSiteAssembly));

            AssemblyResolver.LoadReferences(wsa);


            configuration = GetCachedConfiguration(wsa, Options.WebSitePath,
                                                   (services) =>
            {
                if (Options.FullCompile)
                {
                    services.AddSingleton <IBindingCompiler>(s => bindingCompiler = new AssemblyBindingCompiler(Options.BindingsAssemblyName, Options.BindingClassName, Path.Combine(Options.OutputPath, Options.BindingsAssemblyName + ".dll"), s.GetRequiredService <DotvvmConfiguration>()));
                }
            });

            if (Options.DothtmlFiles == null || !Options.DothtmlFiles.Any())
            {
                Options.DothtmlFiles = configuration.RouteTable.Select(r => r.VirtualPath).ToArray();
            }

            if (Options.FullCompile)
            {
                controlTreeResolver = configuration.ServiceProvider.GetRequiredService <IControlTreeResolver>();
                fileLoader          = configuration.ServiceProvider.GetRequiredService <IMarkupFileLoader>();
                compiler            = configuration.ServiceProvider.GetRequiredService <IViewCompiler>();
                compilation         = compiler.CreateCompilation(Options.AssemblyName);
            }

            if (Options.SerializeConfig)
            {
                result.Configuration = configuration;
            }
        }
Exemplo n.º 10
0
        public IViewCompiler GetCompiler()
        {
            if (_compiler != null)
            {
                return(_compiler);
            }

            lock (_synLock)
            {
                _compiler = _services
                            .GetServices <IViewCompilerProvider>()
                            .FirstOrDefault()
                            .GetCompiler();
            }

            return(_compiler);
        }
Exemplo n.º 11
0
        private void Init()
        {
            // touch assembly
            SyntaxFactory.Token(SyntaxKind.NullKeyword);

            InitOptions();
            if (Options.FullCompile)
            {
                if (!Directory.Exists(Options.OutputPath))
                {
                    Directory.CreateDirectory(Options.OutputPath);
                }
            }
            var wsa = assemblyDictionary.GetOrAdd(Options.WebSiteAssembly, _ => Assembly.LoadFrom(Options.WebSiteAssembly));

            configuration   = GetCachedConfiguration(wsa, Options.WebSitePath);
            bindingCompiler = new AssemblyBindingCompiler(Options.BindingsAssemblyName, Options.BindingClassName, Path.Combine(Options.OutputPath, Options.BindingsAssemblyName + ".dll"), configuration);
            configuration.ServiceLocator.RegisterSingleton <IBindingCompiler>(() => bindingCompiler);
            configuration.ServiceLocator.RegisterSingleton <IControlResolver>(() => new OfflineCompilationControlResolver(configuration, this));
            if (Options.DothtmlFiles == null)
            {
                Options.DothtmlFiles = configuration.RouteTable.Select(r => r.VirtualPath).ToArray();
            }
            controlTreeResolver = configuration.ServiceLocator.GetService <IControlTreeResolver>();
            fileLoader          = configuration.ServiceLocator.GetService <IMarkupFileLoader>();
            if (Options.FullCompile)
            {
                compiler    = configuration.ServiceLocator.GetService <IViewCompiler>();
                compilation = compiler.CreateCompilation(Options.AssemblyName);
            }

            if (Options.SerializeConfig)
            {
                result.Configuration = configuration;
            }

            // touch assemblies
        }
Exemplo n.º 12
0
 public RazorViewEngine(IViewLocator viewTemplateLocator, IViewCompiler viewCompiler)
 {
     ViewTemplateLocator = viewTemplateLocator;
     ViewCompiler = viewCompiler;
 }
Exemplo n.º 13
0
 public RazorViewEngine(IViewLocator viewTemplateLocator, IViewCompiler viewCompiler)
 {
     ViewTemplateLocator = viewTemplateLocator;
     ViewCompiler        = viewCompiler;
 }