Inheritance: IWebFormsParser
Ejemplo n.º 1
0
        public static IEnumerable<string> ConvertFiles(IEnumerable<string> filesToConvert)
        {
            var parser = new WebFormsParser(new WebFormsNodeFactory(),
                                            new WebFormsNodeFilterProvider(new WebFormsCodeGroupFactory()));
            var renderer = new RazorViewRenderer(new RazorNodeRendererProvider());
            var converter =
                new WebFormsToRazorConverter(new RazorNodeConverterProvider(new RazorDirectiveNodeFactory(),
                                                                            new RazorSectionNodeFactory(),
                                                                            new RazorCodeNodeFactory(),
                                                                            new RazorTextNodeFactory(),
                                                                            new RazorCommentNodeFactory(),
                                                                            new RazorExpressionNodeFactory(),
                                                                            new ContentTagConverterConfiguration()));
            var convertedFiles = new List<string>();

            foreach (var file in filesToConvert)
            {
                var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                var webFormsDocument = parser.Parse(webFormsPageSource);
                var razorDom = converter.Convert(webFormsDocument);
                var razorPage = renderer.Render(razorDom);
                var outputFileName = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".cshtml");
                File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);
                convertedFiles.Add(outputFileName);
            }
            return convertedFiles;
        }
 public WebFormsParserFilteringTests()
 {
     filterProviderMock = new Mock<IWebFormsNodeFilterProvider>();
     postprocessingFilters = new List<IWebFormsNodeFilter>();
     filterProviderMock.Setup(fp => fp.Filters).Returns(postprocessingFilters);
     filterMock = new Mock<IWebFormsNodeFilter>();
     postprocessingFilters.Add(filterMock.Object);
     parser = new WebFormsParser(new WebFormsNodeFactory(), filterProviderMock.Object);
 }
Ejemplo n.º 3
0
		public virtual WebFormContainer ParseString(string input, string filePath)
		{
			WebFormContainer returnValue;
			var nodeFactory = new WebFormsNodeFactory();
			var codeGroupNodeFactory = new WebFormsCodeGroupFactory();
			var nodeFilterProvider = new WebFormsNodeFilterProvider(codeGroupNodeFactory);
			WebFormsParser telerikParser = new WebFormsParser(nodeFactory, nodeFilterProvider);
			var document = telerikParser.Parse(input);
			
			var directiveNode = document.RootNode.Children.FirstOrDefault(i=>i is DirectiveNode && !i.Attributes.ContainsKey("Register"));
			if(directiveNode == null)
			{
				throw new ArgumentException("Failed to find directive node");
			}
			returnValue = new WebFormContainer
			{
				CodeBehindFile = directiveNode.Attributes["codebehind"],
				ClassFullName = directiveNode.Attributes["inherits"],
				FilePath = filePath
			};
			if (directiveNode.Attributes.ContainsKey("page"))
			{
				returnValue.ContainerType = EnumWebFormContainerType.WebPage;
			}
			else if (directiveNode.Attributes.ContainsKey("master"))
			{
				returnValue.ContainerType = EnumWebFormContainerType.MasterPage;
			}
			else if(directiveNode.Attributes.ContainsKey("control"))
			{
				returnValue.ContainerType = EnumWebFormContainerType.UserControl;
			}
			else
			{
				throw new Exception("Unrecognized directive");
			}
			var controlList = document.RootNode.Children.Where(i=>i is ServerControlNode);
			foreach (ServerControlNode control in controlList)
			{
				this.LoadControl(control, returnValue);
			}
			return returnValue;
		}
Ejemplo n.º 4
0
 public WebFormsParserTests()
 {
     filterProviderMock = new Mock<IWebFormsNodeFilterProvider>();
     filterProviderMock.Setup(fp => fp.Filters).Returns(new IWebFormsNodeFilter[] { });
     parser = new WebFormsParser(new WebFormsNodeFactory(), filterProviderMock.Object);
 }