Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
		}