コード例 #1
0
		public TargetProject LoadFromProjectFile(CSProjectFile targetProjectFile, string targetProjectFileName)
		{
			TargetProject returnValue = new TargetProject()
			{
				Directory = Path.GetDirectoryName(targetProjectFileName),
				FileName = Path.GetFileName(targetProjectFileName),
				RootNamespace = targetProjectFile.RootNamespace
			};
			foreach(var csClass in targetProjectFile.ClassList)
			{
				var targetClass = this.TargetClassManager.TryLoadTargetClass(csClass);
				if(targetClass != null)
				{
					returnValue.TargetClassList.Add(targetClass);
				}
			}
			return returnValue;
		}
コード例 #2
0
		public SourceWebProject LoadFromProjectFile(CSProjectFile csProject, string projectFilePath)
		{
			SourceWebProject returnValue = new SourceWebProject()
			{
				RootNamespace = csProject.RootNamespace
			};
			var webPageList = csProject.WebFormContainers.Where(i => i.ContainerType == EnumWebFormContainerType.WebPage);
			foreach (var webPage in webPageList)
			{
				var csClass = csProject.ClassList.SingleOrDefault(i => i.ClassFullName == webPage.ClassFullName);
				if (csClass != null)
				{
					SourceWebPage sourceWebPage = new SourceWebPage()
					{
						ClassFullName = webPage.ClassFullName,
						PageUrl = ConvertToUrl(webPage.FilePath, projectFilePath),
						Controls = LoadControls(webPage, csClass)
					};
					returnValue.WebPageList.Add(sourceWebPage);
				}
			}
			var masterPageList = csProject.WebFormContainers.Where(i => i.ContainerType == EnumWebFormContainerType.MasterPage);
			foreach (var masterPage in masterPageList)
			{
				SourceMasterPage sourceMasterPage = new SourceMasterPage()
				{
					ClassFullName = masterPage.ClassFullName,
					PageUrl = ConvertToUrl(masterPage.FilePath, projectFilePath)
				};
				returnValue.MasterPageList.Add(sourceMasterPage);
			}
			var userControlList = csProject.WebFormContainers.Where(i => i.ContainerType == EnumWebFormContainerType.UserControl);
			foreach (var userControl in userControlList)
			{
				var csClass = csProject.ClassList.SingleOrDefault(i => i.ClassFullName == userControl.ClassFullName);
				SourceUserControl sourceUserControl = new SourceUserControl()
				{
					ClassFullName = userControl.ClassFullName,
					Controls = LoadControls(userControl, csClass)
				};
				returnValue.UserControlList.Add(sourceUserControl);
			}
			return returnValue;
		}
コード例 #3
0
			public void BasicTest()
			{
				CSProjectFile projectFile = new CSProjectFile()
				{
					RootNamespace = "Test.Namespace",
					ClassList = new List<CSClass>
					{
						new CSClass { ClassFullName="Test1.TestClass1", FileRelativePathList=new List<string> {"TestClass1.aspx"} },
						new CSClass { ClassFullName="Test1.TestMaster", FileRelativePathList=new List<string> {"TestMasterPage.Master"} },
						new CSClass { ClassFullName="Test1.TestUserControl", FileRelativePathList=new List<string> {"TestUserControl.ascx"} }
					},
					WebFormContainers = new List<WebFormContainer>()
					{
						new WebFormContainer { ClassFullName="Test1.TestClass1", CodeBehindFile="TestClass1.aspx.cs", ContainerType=EnumWebFormContainerType.WebPage, FilePath="C:\\Test\\TestClass1.aspx"},
						new WebFormContainer { ClassFullName="Test1.TestMasterPage", CodeBehindFile="TestMasterPage.Master.cs", ContainerType=EnumWebFormContainerType.MasterPage, FilePath="C:\\Test\\TestMasterPage.Master"},
						new WebFormContainer { ClassFullName="Test1.TestUserControl", CodeBehindFile="TestUserControl.ascx.cs", ContainerType=EnumWebFormContainerType.UserControl, FilePath="C:\\Test\\TestUserControl.ascx" }
					},
					ClassFileDependencyList = new List<ClassFileDependency>
					{
						new ClassFileDependency { ClassFullName="Test1.TestClass1", DependentUponFile="TestClass1.aspx" },
						new ClassFileDependency { ClassFullName="Test1.TestMasterPage", DependentUponFile="TestMasterPage.Master" },
						new ClassFileDependency { ClassFullName="Test1.TestUserControl", DependentUponFile="TestUserControl.ascx" }
					}
				};
				SourceWebModelParser parser = new SourceWebModelParser();
				SourceWebProject result = parser.LoadFromProjectFile(projectFile, "C:\\Test\\Test.csproj");
				Assert.IsNotNull(result);
				Assert.AreEqual(projectFile.RootNamespace, result.RootNamespace);
			
				Assert.AreEqual(1, result.WebPageList.Count);
				Assert.AreEqual("Test1.TestClass1", result.WebPageList[0].ClassFullName);
				Assert.AreEqual("/TestClass1.aspx", result.WebPageList[0].PageUrl);

				Assert.AreEqual(1, result.MasterPageList.Count);
				Assert.AreEqual("Test1.TestMasterPage", result.MasterPageList[0].ClassFullName);
				Assert.AreEqual("/TestMasterPage.Master", result.MasterPageList[0].PageUrl);

				Assert.AreEqual(1, result.UserControlList.Count);
				Assert.AreEqual("Test1.TestUserControl", result.UserControlList[0].ClassFullName);
			}
コード例 #4
0
        public virtual CSProjectFile ParseString(string data, string projectFilePath)
        {
            string        workingProjectFilePath = Path.GetFullPath(projectFilePath);
            string        projectDirectory       = Path.GetDirectoryName(workingProjectFilePath);
            CSProjectFile returnValue            = new CSProjectFile();
            XDocument     xdoc = XDocument.Parse(data);
            var           rootNamespaceNode = xdoc.Descendants().FirstOrDefault(i => i.Name.LocalName == "RootNamespace");

            if (rootNamespaceNode != null)
            {
                returnValue.RootNamespace = rootNamespaceNode.Value;
            }
            else
            {
                returnValue.RootNamespace = Path.GetFileNameWithoutExtension(workingProjectFilePath);
            }
            var classFileList = GetFileList(xdoc, "Compile", ".cs");

            foreach (var classFile in classFileList)
            {
                string filePath = Path.Combine(Path.GetDirectoryName(workingProjectFilePath), classFile.FilePath);
                filePath = Path.GetFullPath(filePath);
                //ClassParser returns new class list
                var newClassList = this.ClassParser.ParseFile(filePath, projectDirectory, null);
                //Then cycle trough and try to merge them, while building dependency list
                foreach (var newClass in newClassList)
                {
                    var existingClass = returnValue.ClassList.SingleOrDefault(i => i.ClassFullName == newClass.ClassFullName);
                    if (existingClass != null)
                    {
                        existingClass.Merge(newClass);
                    }
                    else
                    {
                        returnValue.ClassList.Add(newClass);
                    }
                    if (!string.IsNullOrEmpty(classFile.DependentUponFilePath))
                    {
                        var anyDependency = returnValue.ClassFileDependencyList.Any(i => i.ClassFullName == newClass.ClassFullName &&
                                                                                    i.DependentUponFile.Equals(classFile.DependentUponFilePath, StringComparison.CurrentCultureIgnoreCase));
                        if (!anyDependency)
                        {
                            var newDepdendency = new ClassFileDependency()
                            {
                                ClassName         = newClass.ClassName,
                                NamespaceName     = newClass.NamespaceName,
                                DependentUponFile = classFile.DependentUponFilePath
                            };
                            returnValue.ClassFileDependencyList.Add(newDepdendency);
                        }
                    }
                }
            }
            var contentFileList = GetFileList(xdoc, "Content", new string[] { ".aspx", ".ascx", ".master" });

            foreach (var contentFile in contentFileList)
            {
                string filePath = Path.Combine(Path.GetDirectoryName(workingProjectFilePath), contentFile.FilePath);
                filePath = Path.GetFullPath(filePath);
                //ClassParser returns new class list
                var webFormContainer = this.WebFormParser.ParseFile(filePath);
                returnValue.WebFormContainers.Add(webFormContainer);
            }
            return(returnValue);
        }
コード例 #5
0
			public void BasicPageControls()
			{
				CSProjectFile projectFile = new CSProjectFile()
				{
					ClassList = new List<CSClass>()
					{
						new CSClass 
						{
							ClassFullName = "Test1.TestClass1",
							FieldList = new List<CSField>()
							{
								new CSField { FieldName="form1", ProtectionLevel=EnumProtectionLevel.Protected, TypeFullName="global::System.Web.UI.HtmlControls.HtmlForm"},
								new CSField { FieldName="_lblTest", ProtectionLevel=EnumProtectionLevel.Protected, TypeFullName="global::System.Web.UI.WebControls.Label" }
							}
						}
					},
					WebFormContainers = new List<WebFormContainer>()
					{
						new WebFormContainer 
						{
							ClassFullName="Test1.TestClass1", 
							CodeBehindFile="TestClass.aspx.cs", 
							FilePath="C:\\Test\\TestClass.aspx", 
							ContainerType= EnumWebFormContainerType.WebPage,
							Controls = new List<WebFormServerControl>()
							{
								new WebFormServerControl { TagName="form", ControlID="form1" },
								new WebFormServerControl { TagName="asp:label", ControlID="_lblTest" }
							}
						}
					},
					ClassFileDependencyList = new List<ClassFileDependency>()
					{
						new ClassFileDependency { ClassFullName="Test1.TestClass1", DependentUponFile="TestClass.aspx"}
					}
				};
				var parser = new SourceWebModelParser();
				var result = parser.LoadFromProjectFile(projectFile, "C:\\Test\\Test.csproj");

				Assert.AreEqual(1, result.WebPageList.Count);
				Assert.AreEqual("/TestClass.aspx", result.WebPageList[0].PageUrl);
				Assert.AreEqual("Test1.TestClass1", result.WebPageList[0].ClassFullName);

				Assert.AreEqual(2, result.WebPageList[0].Controls.Count);
				Assert.AreEqual("System.Web.UI.HtmlControls.HtmlForm", result.WebPageList[0].Controls[0].ClassFullName);
				Assert.AreEqual("form1", result.WebPageList[0].Controls[0].FieldName);
				Assert.AreEqual("System.Web.UI.WebControls.Label", result.WebPageList[0].Controls[1].ClassFullName);
				Assert.AreEqual("_lblTest", result.WebPageList[0].Controls[1].FieldName);
			}
コード例 #6
0
ファイル: ProjectParser.cs プロジェクト: mmooney/MMDB.UITest
		public virtual CSProjectFile ParseString(string data, string projectFilePath)
		{
			string workingProjectFilePath = Path.GetFullPath(projectFilePath);
			string projectDirectory = Path.GetDirectoryName(workingProjectFilePath);
			CSProjectFile returnValue = new CSProjectFile();
			XDocument xdoc = XDocument.Parse(data);
			var rootNamespaceNode = xdoc.Descendants().FirstOrDefault(i => i.Name.LocalName == "RootNamespace");
			if (rootNamespaceNode != null)
			{
				returnValue.RootNamespace = rootNamespaceNode.Value;
			}
			else
			{
				returnValue.RootNamespace = Path.GetFileNameWithoutExtension(workingProjectFilePath);
			}
			var classFileList = GetFileList(xdoc, "Compile", ".cs");
			foreach (var classFile in classFileList)
			{
				string filePath = Path.Combine(Path.GetDirectoryName(workingProjectFilePath), classFile.FilePath);
				filePath = Path.GetFullPath(filePath);
				//ClassParser returns new class list
				var newClassList = this.ClassParser.ParseFile(filePath, projectDirectory, null);
				//Then cycle trough and try to merge them, while building dependency list
				foreach(var newClass in newClassList)
				{
					var existingClass = returnValue.ClassList.SingleOrDefault(i=>i.ClassFullName == newClass.ClassFullName);
					if(existingClass != null)
					{
						existingClass.Merge(newClass);
					}
					else 
					{
						returnValue.ClassList.Add(newClass);
					}
					if(!string.IsNullOrEmpty(classFile.DependentUponFilePath))
					{
						var anyDependency = returnValue.ClassFileDependencyList.Any(i=>i.ClassFullName == newClass.ClassFullName
																						&& i.DependentUponFile.Equals(classFile.DependentUponFilePath, StringComparison.CurrentCultureIgnoreCase));
						if(!anyDependency)
						{
							var newDepdendency = new ClassFileDependency()
							{
								ClassName = newClass.ClassName,
								NamespaceName = newClass.NamespaceName,
								DependentUponFile = classFile.DependentUponFilePath
							};
							returnValue.ClassFileDependencyList.Add(newDepdendency);
						}
					}
				}
			}
			var contentFileList = GetFileList(xdoc, "Content", new string[] {".aspx", ".ascx", ".master" });
			foreach(var contentFile in contentFileList)
			{
				string filePath = Path.Combine(Path.GetDirectoryName(workingProjectFilePath), contentFile.FilePath);
				filePath = Path.GetFullPath(filePath);
				//ClassParser returns new class list
				var webFormContainer = this.WebFormParser.ParseFile(filePath);
				returnValue.WebFormContainers.Add(webFormContainer);
			}
			return returnValue;
		}