private static void PopulateWebPageObject(SourceWebPage pageObject, CSClass classObject)
		{
			pageObject.ClassFullName = classObject.ClassFullName;
			foreach (var fieldObject in classObject.FieldList)
			{
				switch (fieldObject.TypeFullName)
				{
					case "System.Web.UI.WebControls.Literal":
						{
							var control = new LiteralControl
							{
								FieldName = fieldObject.FieldName,
								ClassName = fieldObject.TypeName,
								NamespaceName = fieldObject.TypeNamespace
							};
							pageObject.Controls.Add(control);
						}
						break;
					default:
						{
							var control = new SourceWebControl()
							{
								FieldName = fieldObject.FieldName,
								ClassName = fieldObject.TypeName,
								NamespaceName = fieldObject.TypeNamespace
							};
							pageObject.Controls.Add(control);
						}
						break;
				}
			}
		}
Exemple #2
0
		public static SourceWebPage TryLoad(string sourceProjectPath, CSClass csClass)
		{
			throw new NotImplementedException();
			//SourceWebPage returnValue = null;
			//string aspxFile = csClass.DependentUponFilePathList.SingleOrDefault(i => i.EndsWith(".aspx", StringComparison.CurrentCultureIgnoreCase));
			//if (aspxFile != null)
			//{
			//    string aspxData;
			//    using (StreamReader reader = new StreamReader(Path.Combine(Path.GetDirectoryName(sourceProjectPath), aspxFile)))
			//    {
			//        aspxData = reader.ReadToEnd();
			//        ICSharpCode.NRefactory.CSharp.CSharpParser parser = new ICSharpCode.NRefactory.CSharp.CSharpParser();
			//        var unit = parser.Parse(reader, aspxFile);
			//    }
			//    Regex re = new Regex("<%@( )*Page .+ MasterPageFile=\\\"~/([\\w\\d/.]+)\\\"");
			//    var match = re.Match(aspxData);
			//    if (match.Groups.Count > 0)
			//    {
			//        returnValue = new SourceMasterContentPage()
			//        {
			//            ClassFullName = csClass.ClassFullName,
			//            MasterPageUrl = match.Groups[match.Groups.Count-1].Value
			//        };
			//    }
			//    else
			//    {
			//        returnValue = new SourceWebPage
			//        {
			//            ClassFullName = csClass.ClassFullName
			//        };
			//    }
			//}
			//return returnValue;
		}
Exemple #3
0
		public virtual List<CSClass> ParseString(string data, string filePath, string projectDirectory, IEnumerable<CSClass> existingClassList)
		{
			string relativeFilePath = filePath.Replace(projectDirectory,"");
			if(relativeFilePath.StartsWith("\\"))
			{
				relativeFilePath = relativeFilePath.Substring(1);
			}
			List<CSClass> returnValue = new List<CSClass>(existingClassList ?? new CSClass[]{} );
			var parser = new CSharpParser();
			var compilationUnit = parser.Parse(data, filePath);
			var namespaceNodeList = compilationUnit.Children.Where(i=>i is NamespaceDeclaration);
			foreach(NamespaceDeclaration namespaceNode in namespaceNodeList)
			{
				var typeDeclarationNodeList = namespaceNode.Children.Where(i=>i is TypeDeclaration);
				foreach(TypeDeclaration typeDeclarationNode in typeDeclarationNodeList)
				{
					var classObject = returnValue.SingleOrDefault(i=>i.ClassName == typeDeclarationNode.Name && i.NamespaceName == namespaceNode.FullName);
					if(classObject == null)
					{
						classObject = new CSClass
						{
							NamespaceName = namespaceNode.FullName,
							ClassName = typeDeclarationNode.Name
						};
						returnValue.Add(classObject);
					}
					ClassParser.BuildClass(classObject, typeDeclarationNode, relativeFilePath);
				}
			}
			return returnValue;
		}
Exemple #4
0
		public void Merge(CSClass newClass)
		{
			if(newClass.ClassFullName != this.ClassFullName)
			{
				throw new ArgumentException(string.Format("Class names do not match, expected \"{0}\", found \"{1}\"", this.ClassFullName, newClass.ClassFullName));
			}
			this.AttributeList.AddRange(newClass.AttributeList);
			this.PropertyList.AddRange(newClass.PropertyList);
			this.FieldList.AddRange(newClass.FieldList);
			this.FileRelativePathList.AddRange(newClass.FileRelativePathList);
		}
		private static void PopulateMasterPageObject(SourceMasterPage pageObject, CSClass classObject)
		{
			pageObject.ClassFullName = classObject.ClassFullName;
			foreach (var fieldObject in classObject.FieldList)
			{
				switch(fieldObject.TypeFullName)
				{
					case "System.Web.UI.WebControls.ContentPlaceHolder":
						pageObject.ContentHolderIDs.Add(fieldObject.FieldName);
						break;
				}
			}
			PopulateWebPageObject(pageObject, classObject);
		}
		public TargetClass TryLoadTargetClass(CSClass csClass)
		{
			TargetClass returnValue = null;
			var uiClientPageAttribute = csClass.AttributeList.SingleOrDefault(i => i.TypeFullName == typeof(UIClientPageAttribute).FullName);
			if (uiClientPageAttribute != null)
			{
				returnValue = new TargetClass
				{
					SourceClassFullName = Convert.ToString(uiClientPageAttribute.GetAttributeParameter(0, "sourceClassFullName", true)),
					TargetClassFullName = csClass.ClassFullName,
					//ExpectedUrl = Convert.ToString(uiClientPageAttribute.GetAttributeParameter(1, "ExpectedUrl", false))
				};
				
				//If there is only one file, that is the user and designer file.
				//If there are two or more files and one ends with ".designer.cs", that is the designer file and the the first of the others is the user file
				//If there are two or more files and none ends with ".designer.cs", then the first one is the designer and user file
				if (csClass.FileRelativePathList.Count == 1)
				{
					returnValue.DesignerFileRelativePath = csClass.FileRelativePathList[0];
					returnValue.UserFileRelativePath = csClass.FileRelativePathList[0];
				}
				else if (csClass.FileRelativePathList.Count > 1)
				{
					returnValue.DesignerFileRelativePath = csClass.FileRelativePathList.FirstOrDefault(i => i.EndsWith(".designer.cs", StringComparison.CurrentCultureIgnoreCase));
					if (string.IsNullOrEmpty(returnValue.DesignerFileRelativePath))
					{
						returnValue.DesignerFileRelativePath = csClass.FileRelativePathList[0];
						returnValue.UserFileRelativePath = csClass.FileRelativePathList[0];
					}
					else
					{
						returnValue.UserFileRelativePath = csClass.FileRelativePathList.FirstOrDefault(i => i != returnValue.DesignerFileRelativePath);
					}
				}

				foreach (var csProperty in csClass.PropertyList)
				{
					var targetField = TryLoadField(csProperty);
					if (targetField != null)
					{
						returnValue.TargetFieldList.Add(targetField);
					}
				}
			}
			return returnValue;
		}
		private List<SourceWebControl> LoadControls(WebFormContainer webPage, CSClass csClass)
		{
			List<SourceWebControl> returnList = new List<SourceWebControl>();
			foreach(var serverControl in webPage.Controls)
			{
				var classField = csClass.FieldList.SingleOrDefault(i=>i.FieldName == serverControl.ControlID);
				if(classField != null)
				{
					SourceWebControl sourceWebControl = new SourceWebControl
					{
						ClassFullName = classField.TypeFullName,
						FieldName = (serverControl.Prefix??string.Empty) + classField.FieldName
					};
					returnList.Add(sourceWebControl);
				}
			}
			return returnList;
		}
Exemple #8
0
		internal static void BuildClass(CSClass classObject, TypeDeclaration typeDefinitionNode, string relativeFilePath)
		{
			var fieldList = typeDefinitionNode.Children.Where(i => i is FieldDeclaration);
			if ((typeDefinitionNode.Modifiers & Modifiers.Public) == Modifiers.Public)
			{
				classObject.ProtectionLevel = EnumProtectionLevel.Public;
			}
			else if ((typeDefinitionNode.Modifiers & Modifiers.Private) == Modifiers.Private)
			{
				classObject.ProtectionLevel = EnumProtectionLevel.Private;
			}
			else if ((typeDefinitionNode.Modifiers & Modifiers.Protected) == Modifiers.Protected)
			{
				classObject.ProtectionLevel = EnumProtectionLevel.Protected;
			}
			else if ((typeDefinitionNode.Modifiers & Modifiers.Internal) == Modifiers.Internal)
			{
				classObject.ProtectionLevel = EnumProtectionLevel.Internal;
			}
			foreach (FieldDeclaration fieldNode in fieldList)
			{
				var fieldObjectList = CSField.Parse(fieldNode);
				classObject.FieldList.AddRange(fieldObjectList);
			}
			var propertyList = typeDefinitionNode.Children.Where(i => i is PropertyDeclaration);
			foreach (PropertyDeclaration propertyNode in propertyList)
			{
				var propertyObject = CSProperty.Parse(propertyNode);
				classObject.PropertyList.Add(propertyObject);
			}
			var attributeSectionList = typeDefinitionNode.Children.Where(i => i is AttributeSection);
			foreach (AttributeSection attributeSectionNode in attributeSectionList)
			{
				foreach (var attributeNode in attributeSectionNode.Attributes)
				{
					var attribute = CSAttribute.Parse(attributeNode);
					classObject.AttributeList.Add(attribute);
				}
			}
			if (!classObject.FileRelativePathList.Contains(relativeFilePath, StringComparer.CurrentCultureIgnoreCase))
			{
				classObject.FileRelativePathList.Add(relativeFilePath);
			}
		}
			public void BasicTargetClassTest()
			{
				CSClass csClass = new CSClass()
				{
					ClassFullName = "Test.Target.TargetClassName",
					AttributeList = new List<CSAttribute>() 
					{
						new CSAttribute
						{
							TypeFullName = typeof(UIClientPageAttribute).FullName,
							ArgumentList = new List<CSAttribute.CSAttributeArgument>()
							{
								new CSAttribute.CSAttributeArgument { ArgumentName = "sourceClassFullName", ArguementValue = "Test.Test1.SourceClassFullNameValue" }//,
								//new CSAttribute.CSAttributeArgument { ArgumentName = "ExpectedUrl", ArguementValue = "SourceClassFullName.aspx" }
							}
						}
					},
					FileRelativePathList = new List<string>()
					{
						"TargetClassName.aspx.designer.cs",
						"TargetClassName.aspx.cs"
					},
					PropertyList = new List<CSProperty>()
					{
						new CSProperty()
						{
							TypeFullName = typeof(WatiN.Core.Link).FullName,
							PropertyName = "TestLink",
							ProtectionLevel = EnumProtectionLevel.Public,
							AttributeList = new List<CSAttribute>() 
							{
								new CSAttribute() 
								{
									TypeFullName = typeof(UIClientPropertyAttribute).FullName,
									ArgumentList = new List<CSAttribute.CSAttributeArgument>()
									{
										new CSAttribute.CSAttributeArgument() { ArgumentName="sourceFieldTypeFullName", ArguementValue=typeof(System.Web.UI.WebControls.HyperLink).FullName },
										new CSAttribute.CSAttributeArgument() { ArgumentName="sourceFieldName", ArguementValue="TestLink" }
									}
								}
							}
						},
						new CSProperty()
						{
							TypeFullName = typeof(WatiN.Core.TextField).FullName,
							PropertyName = "TestTextBox",
							ProtectionLevel = EnumProtectionLevel.Public,					
							AttributeList = new List<CSAttribute>() 
							{
								new CSAttribute() 
								{
									TypeFullName = typeof(UIClientPropertyAttribute).FullName,
									ArgumentList = new List<CSAttribute.CSAttributeArgument>()
									{
										new CSAttribute.CSAttributeArgument() { ArgumentName="sourceFieldTypeFullName", ArguementValue=typeof(System.Web.UI.WebControls.TextBox).FullName },
										new CSAttribute.CSAttributeArgument() { ArgumentName="sourceFieldName", ArguementValue="TestTextBox" }
									}
								}
							}
						},
					}
				};
				var targetClassManager = new TargetClassManager();
				var targetClass = targetClassManager.TryLoadTargetClass(csClass);
				Assert.IsNotNull(targetClass);
				Assert.AreEqual("Test.Test1.SourceClassFullNameValue", targetClass.SourceClassFullName);
				Assert.AreEqual("Test.Target.TargetClassName", targetClass.TargetClassFullName);
				Assert.AreEqual(2, targetClass.TargetFieldList.Count);
				TestValidators.ValidateTargetField(targetField: targetClass.TargetFieldList[0],
											isDirty: false,
											sourceClassFullName: "System.Web.UI.WebControls.HyperLink",
											sourceFieldName: "TestLink",
											targetControlType: EnumTargetControlType.Link,
											targetFieldName: "TestLink");
				TestValidators.ValidateTargetField(targetField: targetClass.TargetFieldList[1],
											isDirty: false,
											sourceClassFullName: "System.Web.UI.WebControls.TextBox",
											sourceFieldName: "TestTextBox",
											targetControlType: EnumTargetControlType.TextBox,
											targetFieldName: "TestTextBox");
				//Assert.AreEqual("SourceClassFullName.aspx", targetClass.ExpectedUrl);
			}
Exemple #10
0
		public static bool IsTargetClass(CSClass csClass)
		{
			return csClass.AttributeList.Any(i=>i.TypeName == typeof(UIClientPageAttribute).Name && i.TypeNamespace  ==  typeof(UIClientPageAttribute).Namespace);
		}