コード例 #1
0
 public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
 {
     foreach (var transformer in CodeTransformers)
     {
         transformer.Initialize(razorHost, directives);
     }
 }
コード例 #2
0
        public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
        {
            //read the base type here from the web.config here
            HostContext.Config.RazorNamespaces.Each(ns => razorHost.NamespaceImports.Add(ns));

            base.Initialize(razorHost, directives);
        }
コード例 #3
0
        public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
        {
            //read the base type here from the web.config here
            HostContext.Config.RazorNamespaces.Each(ns => razorHost.NamespaceImports.Add(ns));

            base.Initialize(razorHost, directives);
        }
コード例 #4
0
 public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
 {
     foreach (var transformer in CodeTransformers)
     {
         transformer.Initialize(razorHost, directives);
     }
 }
コード例 #5
0
 public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
 {
     if (_replaceExisting)
     {
         razorHost.NamespaceImports.Clear();
     }
     foreach (var import in _imports)
     {
         razorHost.NamespaceImports.Add(import);
     }
 }
コード例 #6
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
            };
        }
コード例 #7
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);
            }
        }
コード例 #8
0
        /// <summary>Initializes this object.</summary>
        ///
        /// <param name="razorHost"> The razor host.</param>
        /// <param name="directives">The directives.</param>
        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;
            }
        }
コード例 #9
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"
            //);
        }
コード例 #10
0
        /// <summary>Initializes this object.</summary>
        ///
        /// <param name="razorHost"> The razor host.</param>
        /// <param name="directives">The directives.</param>
        public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
        {
            //string projectPath = GetProjectRoot(razorHost.ProjectRelativePath, razorHost.FullPath).TrimEnd(Path.DirectorySeparatorChar);
            //string currentPath = razorHost.FullPath;
            //string directoryVirtualPath = null;

            //var configFileMap = new WebConfigurationFileMap();

            //var virtualDirectories = configFileMap.VirtualDirectories;
            //while (!currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase))
            //{
            //    currentPath = Path.GetDirectoryName(currentPath);
            //    string relativePath = currentPath.Substring(projectPath.Length);
            //    bool isAppRoot = currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase);
            //    string virtualPath = relativePath.Replace('\\', '/');
            //    if (virtualPath.Length == 0)
            //    {
            //        virtualPath = "/";
            //    }

            //    directoryVirtualPath = directoryVirtualPath ?? virtualPath;

            //    virtualDirectories.Add(virtualPath, new VirtualDirectoryMapping(currentPath, isAppRoot: isAppRoot));
            //}

            //var config = WebConfigurationManager.OpenMappedWebConfiguration(configFileMap, directoryVirtualPath);

            //// We use dynamic here because we could be dealing both with a 1.0 or a 2.0 RazorPagesSection, which
            //// are not type compatible (http://razorgenerator.codeplex.com/workitem/26)
            //dynamic section = config.GetSection( RazorWebPagesSectionName );
            //if (section != null)
            //{
            //    string baseType = section.PageBaseType;
            //    if (!DefaultBaseType.Equals(baseType, StringComparison.OrdinalIgnoreCase))
            //    {
            //        _transformers.Add(new SetBaseType(baseType));
            //    }

            //    if (section != null)
            //    {
            //        foreach (NamespaceInfo n in section.Namespaces)
            //        {
            //            razorHost.NamespaceImports.Add(n.Namespace);
            //        }
            //    }
            //}
            //base.Initialize(razorHost, directives);
        }
コード例 #11
0
        /// <summary>Initializes this object.</summary>
        ///
        /// <param name="razorHost"> The razor host.</param>
        /// <param name="directives">The directives.</param>
        public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
        {
            //string projectPath = GetProjectRoot(razorHost.ProjectRelativePath, razorHost.FullPath).TrimEnd(Path.DirectorySeparatorChar);
            //string currentPath = razorHost.FullPath;
            //string directoryVirtualPath = null;

            //var configFileMap = new WebConfigurationFileMap();

            //var virtualDirectories = configFileMap.VirtualDirectories;
            //while (!currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase))
            //{
            //    currentPath = Path.GetDirectoryName(currentPath);
            //    string relativePath = currentPath.Substring(projectPath.Length);
            //    bool isAppRoot = currentPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase);
            //    string virtualPath = relativePath.Replace('\\', '/');
            //    if (virtualPath.Length == 0)
            //    {
            //        virtualPath = "/";
            //    }

            //    directoryVirtualPath = directoryVirtualPath ?? virtualPath;

            //    virtualDirectories.Add(virtualPath, new VirtualDirectoryMapping(currentPath, isAppRoot: isAppRoot));
            //}

            //var config = WebConfigurationManager.OpenMappedWebConfiguration(configFileMap, directoryVirtualPath);

            //// We use dynamic here because we could be dealing both with a 1.0 or a 2.0 RazorPagesSection, which
            //// are not type compatible (http://razorgenerator.codeplex.com/workitem/26)
            //dynamic section = config.GetSection( RazorWebPagesSectionName );
            //if (section != null)
            //{
            //    string baseType = section.PageBaseType;
            //    if (!DefaultBaseType.Equals(baseType, StringComparison.OrdinalIgnoreCase))
            //    {
            //        _transformers.Add(new SetBaseType(baseType));
            //    }

            //    if (section != null)
            //    {
            //        foreach (NamespaceInfo n in section.Namespaces)
            //        {
            //            razorHost.NamespaceImports.Add(n.Namespace);
            //        }
            //    }
            //}
            //base.Initialize(razorHost, directives);
        }
コード例 #12
0
        public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
        {
            base.Initialize(razorHost, directives);

            //string baseClass = razorHost.DefaultBaseClass;
            razorHost.DefaultBaseClass = _typeName;

            // 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.

            //var path = razorHost.EnableLinePragmas ? razorHost.File.RealPath : String.Empty;
            //razorHost.CodeGenerator = new CSharpRazorCodeGenerator(razorHost.DefaultClassName, razorHost.DefaultNamespace, path, razorHost)
            //{
            //    GenerateLinePragmas = razorHost.EnableLinePragmas
            //};
            //razorHost.Parser = new ServiceStackCSharpCodeParser();
        }
コード例 #13
0
        public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
        {
            string typeVisibility;

            if (directives.TryGetValue(TypeVisibilityKey, out typeVisibility))
            {
                _transformers.Add(new SetTypeVisibility(typeVisibility));
            }

            string typeNamespace;

            if (directives.TryGetValue(NamespaceKey, out typeNamespace))
            {
                _transformers.Add(new SetTypeNamespace(typeNamespace));
            }

            if (ReadSwitchValue(directives, DisableLinePragmasKey) == true)
            {
                razorHost.EnableLinePragmas = false;
            }
            else if (ReadSwitchValue(directives, GenerateAbsolutePathLinePragmas) != true)
            {
                // Rewrite line pragamas to generate bin relative paths instead of absolute paths.
                _transformers.Add(new RewriteLinePragmas());
            }

            if (ReadSwitchValue(directives, TrimLeadingUnderscoresKey) != false)
            {
                // This should in theory be a different transformer.
                razorHost.DefaultClassName = razorHost.DefaultClassName.TrimStart('_');
            }

            if (ReadSwitchValue(directives, ExcludeFromCodeCoverage) == true)
            {
                _transformers.Add(new ExcludeFromCodeCoverageTransformer());
            }

            string suffix;

            if (directives.TryGetValue(SuffixFileName, out suffix))
            {
                _transformers.Add(new SuffixFileNameTransformer(suffix));
            }

            base.Initialize(razorHost, directives);
        }
コード例 #14
0
        /// <summary>Initializes this object.</summary>
        ///
        /// <param name="razorHost"> The razor host.</param>
        /// <param name="directives">The directives.</param>
        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();
        }
コード例 #15
0
        public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
        {
            string typeVisibility;
            if (directives.TryGetValue(TypeVisibilityKey, out typeVisibility))
            {
                _transformers.Add(new SetTypeVisibility(typeVisibility));
            }

            string typeNamespace;
            if (directives.TryGetValue(NamespaceKey, out typeNamespace))
            {
                _transformers.Add(new SetTypeNamespace(typeNamespace));
            }

            if (ReadSwitchValue(directives, DisableLinePragmasKey) == true)
            {
                razorHost.EnableLinePragmas = false;
            }
            else if (ReadSwitchValue(directives, GenerateAbsolutePathLinePragmas) != true)
            {
                // Rewrite line pragamas to generate bin relative paths instead of absolute paths.
                _transformers.Add(new RewriteLinePragmas());
            }

            if (ReadSwitchValue(directives, TrimLeadingUnderscoresKey) != false)
            {
                // This should in theory be a different transformer.
                razorHost.DefaultClassName = razorHost.DefaultClassName.TrimStart('_');
            }

            if (ReadSwitchValue(directives, ExcludeFromCodeCoverage) == true)
            {
                _transformers.Add(new ExcludeFromCodeCoverageTransformer());
            }

            string suffix;
            if (directives.TryGetValue(SuffixFileName, out suffix))
            {
                _transformers.Add(new SuffixFileNameTransformer(suffix));
            }

            base.Initialize(razorHost, directives);
        }
コード例 #16
0
 public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
 {
     _projectRelativePath = razorHost.File.VirtualPath;
     directives.TryGetValue(VirtualPathDirectiveKey, out _overriddenVirtualPath);
 }
コード例 #17
0
 public override void Initialize(RazorPageHost razorHost, System.Collections.Generic.IDictionary<string, string> directives)
 {
     _binRelativePath = @"..\.." + razorHost.File.VirtualPath;
     _fullPath = razorHost.File.RealPath;
 }
コード例 #18
0
 public virtual void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
 {
     // do nothing
 }
コード例 #19
0
 /// <summary>Initializes this object.</summary>
 ///
 /// <param name="razorHost"> The razor host.</param>
 /// <param name="directives">The directives.</param>
 public override void Initialize(RazorPageHost razorHost, System.Collections.Generic.IDictionary <string, string> directives)
 {
     _binRelativePath = @"..\.." + razorHost.File.VirtualPath;
     _fullPath        = razorHost.File.RealPath;
 }
コード例 #20
0
 public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
 {
     razorHost.StaticHelpers = true;
 }
コード例 #21
0
 /// <summary>Initializes this object.</summary>
 ///
 /// <param name="razorHost"> The razor host.</param>
 /// <param name="directives">The directives.</param>
 public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
 {
     razorHost.DefaultNamespace = _namespace;
 }
コード例 #22
0
 public virtual void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
 {
     // do nothing
 }
コード例 #23
0
 /// <summary>Initializes this object.</summary>
 ///
 /// <param name="razorHost"> The razor host.</param>
 /// <param name="directives">The directives.</param>
 public override void Initialize(RazorPageHost razorHost, IDictionary <string, string> directives)
 {
     _projectRelativePath = razorHost.File.VirtualPath;
     directives.TryGetValue(VirtualPathDirectiveKey, out _overriddenVirtualPath);
 }
コード例 #24
0
 public override void Initialize(RazorPageHost razorHost, IDictionary<string, string> directives)
 {
     razorHost.DefaultNamespace = _namespace;
 }