Inheritance: System.Web.Razor.RazorEngineHost, IRazorHost
コード例 #1
0
        public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
        {
            base.Initialize(razorHost, directives);

            var path = razorHost.EnableLinePragmas ? razorHost.File.RealPath : string.Empty;
            razorHost.CodeGenerator = new ServiceStackCSharpRazorCodeGenerator(razorHost.DefaultClassName, razorHost.DefaultNamespace, path, razorHost)
            {
                GenerateLinePragmas = razorHost.EnableLinePragmas
            };
        }
コード例 #2
0
        public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
        {
            base.Initialize(razorHost, directives);

            // Remove the extension and replace path separator slashes with underscores
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(razorHost.File.VirtualPath);

            // If its a PageStart page, set the base type to StartPage.
            if (fileNameWithoutExtension.Equals("_pagestart", StringComparison.OrdinalIgnoreCase))
            {
//                razorHost.DefaultBaseClass = typeof(System.Web.WebPages.StartPage).FullName;
            }
        }
コード例 #3
0
        public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
        {
            base.Initialize(razorHost, directives);
            //razorHost.DefaultBaseClass = typeof(System.Web.WebPages.HelperPage).FullName;

            //razorHost.GeneratedClassContext = new GeneratedClassContext(
            //        executeMethodName: GeneratedClassContext.DefaultExecuteMethodName,
            //        writeMethodName: GeneratedClassContext.DefaultWriteMethodName,
            //        writeLiteralMethodName: GeneratedClassContext.DefaultWriteLiteralMethodName,
            //        writeToMethodName: WriteToMethodName,
            //        writeLiteralToMethodName: WriteLiteralToMethodName,
            //        templateTypeName: typeof(System.Web.WebPages.HelperResult).FullName,
            //        defineSectionMethodName: "DefineSection"
            //);
        }
コード例 #4
0
        public override bool Execute()
        {
            if (!this.InputFiles.Any())
                return true;

            Instance = new RazorGeneratorBuildTask();

            if (AppConfigPath == null)
            {
                var configNames = new[] {
                    PathUtils.CombinePaths(ProjectDir, "Web.config"),
                    PathUtils.CombinePaths(ProjectDir, "App.config"),
                    PathUtils.CombinePaths(ProjectDir, "web.config"), //unix
                    PathUtils.CombinePaths(ProjectDir, "app.config"),
                };
                AppConfigPath = configNames.FirstOrDefault(File.Exists);
            }

            // Use the task's parent project's web/app configuration file
            using (AppConfigScope.Change(AppConfigPath))
            {
                var allowedConfigs = ConfigurationManager.AppSettings[ConfigurationAppKeyName] ?? this.AllowedConfigurations;

                // If specified, only generate source code if the Project Configuration matches the given Configuration from the user
                if (!ConfigurationMatches(this.ProjectConfiguration, allowedConfigs))
                    return true;

                var pageBaseTypeName = GetPageBaseTypeName();
                var pathProvider = new RazorBuildPathProvider(this.ProjectDir);
                var transformer = new RazorViewPageTransformer(pageBaseTypeName);

                for (int i = 0; i < this.InputFiles.Length; i++)
                {
                    var file = new RazorBuildTaskFile(this.InputFiles[i].ItemSpec, pathProvider);
                    var pageHost = new RazorPageHost(pathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>())
                    {
                        RootNamespace = this.ProjectRootNamespace
                    };

                    var fileName = this.OutputFiles[i].ItemSpec = ToUniqueFilePath(this.OutputFiles[i].ItemSpec, pageHost.DefaultNamespace);
                    var sourceCode = pageHost.GenerateSourceCode();

                    File.WriteAllText(fileName, sourceCode);
                }

                return true;
            }
        }
コード例 #5
0
        public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
        {
            base.Initialize(razorHost, directives);


            string baseClass = razorHost.DefaultBaseClass;
            _isSpecialPage = IsSpecialPage(razorHost.File.VirtualPath);

            // The CSharpRazorCodeGenerator decides to generate line pragmas based on if the file path is available. Set it to an empty string if we 
            // do not want to generate them.
            string path = razorHost.EnableLinePragmas ? razorHost.File.RealPath : String.Empty;
            razorHost.CodeGenerator = new CSharpRazorCodeGenerator(razorHost.DefaultClassName, razorHost.DefaultNamespace, path, razorHost)
            {
                GenerateLinePragmas = razorHost.EnableLinePragmas
            };
            //razorHost.Parser = new MvcCSharpRazorCodeParser();
        }