public RazorViewComponentAssemblyCompilationResults CompileEmbeddedViews()
        {
            _compilationResultMessage = new RazorViewComponentAssemblyCompilationResults();

            Initialize();

            IEnumerable<string> embeddedRazorViewResourceNames =
                Assembly.GetManifestResourceNames().Where(ResourceIsRazorView).ToArray();

            if (!embeddedRazorViewResourceNames.Any())
            {
                Log.Debug("No embedded Razor views were found in this assembly.");
                return _compilationResultMessage;
            }

            Log.Debug(() => string.Format("Found the following embedded Razor views: {0}",
                                          string.Join("\r\n", embeddedRazorViewResourceNames)));

            IEnumerable<IGrouping<RazorCodeLanguage, string>> resourcesGroupedByLanguage =
                from resourceName in embeddedRazorViewResourceNames
                let resourceInfo = new FileInfo(resourceName)
                let language = RazorCodeLanguage.GetLanguageByExtension(resourceInfo.Extension)
                group resourceName by language into groupedResources
                select groupedResources;

            var compiledAssemblies = CompileResourcesByLanguage(resourcesGroupedByLanguage);

            bool everythingCompiledSuccessfully = compiledAssemblies.All(x => !x.Errors.HasErrors);

            if (!everythingCompiledSuccessfully)
            {
                throw new RazorViewComponentAssemblyCompilationException(compiledAssemblies);
            }

            Log.Debug("Done!");

            return _compilationResultMessage;
        }
Ejemplo n.º 2
0
        public RazorViewComponentAssemblyCompilationResults CompileEmbeddedViews()
        {
            _compilationResultMessage = new RazorViewComponentAssemblyCompilationResults();

            Initialize();

            IEnumerable <string> embeddedRazorViewResourceNames =
                Assembly.GetManifestResourceNames().Where(ResourceIsRazorView).ToArray();

            if (!embeddedRazorViewResourceNames.Any())
            {
                Log.Debug("No embedded Razor views were found in this assembly.");
                return(_compilationResultMessage);
            }

            Log.Debug(() => string.Format("Found the following embedded Razor views: {0}",
                                          string.Join("\r\n", embeddedRazorViewResourceNames)));

            IEnumerable <IGrouping <RazorCodeLanguage, string> > resourcesGroupedByLanguage =
                from resourceName in embeddedRazorViewResourceNames
                let resourceInfo = new FileInfo(resourceName)
                                   let language = RazorCodeLanguage.GetLanguageByExtension(resourceInfo.Extension)
                                                  group resourceName by language into groupedResources
                                                  select groupedResources;

            var compiledAssemblies = CompileResourcesByLanguage(resourcesGroupedByLanguage);

            bool everythingCompiledSuccessfully = compiledAssemblies.All(x => !x.Errors.HasErrors);

            if (!everythingCompiledSuccessfully)
            {
                throw new RazorViewComponentAssemblyCompilationException(compiledAssemblies);
            }

            Log.Debug("Done!");

            return(_compilationResultMessage);
        }