예제 #1
0
		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;
				}
			}
		}
예제 #2
0
		//internal static TargetClass TryLoad(CSClass csClass)
		//{
		//    TargetClass returnValue = null;
		//    var uiClientPageAttribute = csClass.AttributeList.SingleOrDefault(i => i.TypeName == typeof(UIClientPageAttribute).Name && i.TypeNamespace == typeof(UIClientPageAttribute).Namespace);
		//    if(uiClientPageAttribute != null)
		//    {
		//        returnValue = new TargetClass
		//        {
		//            SourceClassFullName = Convert.ToString(uiClientPageAttribute.GetAttributeParameter(0, "SourceClassFullName", true)),
		//            TargetClassFullName = csClass.ClassFullName
		//        };

		//        //If there is only one field, 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.FilePathList.Count == 1)
		//        {
		//            returnValue.DesignerFilePath = csClass.FilePathList[0];
		//            returnValue.UserFilePath = csClass.FilePathList[0];
		//        }
		//        else if (csClass.FilePathList.Count > 1)
		//        {
		//            returnValue.DesignerFilePath = csClass.FilePathList.FirstOrDefault(i=>i.EndsWith(".designer.cs", StringComparison.CurrentCultureIgnoreCase));
		//            if(string.IsNullOrEmpty(returnValue.DesignerFilePath))
		//            {
		//                returnValue.DesignerFilePath = csClass.FilePathList[0];
		//                returnValue.UserFilePath = csClass.FilePathList[0];
		//            }
		//            else 
		//            {
		//                returnValue.UserFilePath = csClass.FilePathList.FirstOrDefault(i=>i != returnValue.DesignerFilePath);
		//            }
		//        }

		//        foreach(var csProperty in csClass.PropertyList)
		//        {
		//            var targetField = TargetField.TryLoad(csProperty);
		//            if(targetField != null)
		//            {
		//                returnValue.TargetFieldList.Add(targetField);
		//            }
		//        }
		//    }
		//    return returnValue;
		//}

		public static TargetClass Create(TargetProject targetProject, SourceWebProject sourceProject, SourceWebPage sourcePage)
		{
			string sourceTypeName;
			string sourceTypeNamespace;
			DotNetParserHelper.SplitType(sourcePage.ClassFullName, out sourceTypeName, out sourceTypeNamespace);

			string relativeSourceNamespace;
			if(sourceTypeNamespace == sourceProject.RootNamespace)
			{
				relativeSourceNamespace = string.Empty;
			}
			else if(sourceTypeNamespace.StartsWith(sourceProject.RootNamespace))
			{
				relativeSourceNamespace = sourceTypeNamespace.Substring(sourceProject.RootNamespace.Length + 1);
			}
			else 
			{
				relativeSourceNamespace = sourceTypeNamespace;
			}
			string targetClassName = sourceTypeName + "PageClient";
			string targetNamespace = targetProject.RootNamespace + ".Client.Pages." + relativeSourceNamespace;
			TargetClass returnValue = new TargetClass()
			{
				SourceClassFullName = sourcePage.ClassFullName,
				TargetClassFullName = targetNamespace + "." + targetClassName,
				DesignerFileRelativePath = Path.Combine(targetNamespace.Replace('.', '\\'), targetClassName + ".designer.cs"),
				UserFileRelativePath = Path.Combine(targetNamespace.Replace('.', '\\'), targetClassName + ".cs"),
			};
			return returnValue;
		}
예제 #3
0
		private static string GenerateTargetFilePath(string basePath, SourceWebPage page)
		{
			string typeName;
			string typeNamespace;
			DotNetParserHelper.SplitType(page.ClassFullName, out typeName, out typeNamespace);
			if(!string.IsNullOrEmpty(typeName))
			{
				return Path.Combine(basePath, "Client", "Pages", typeNamespace, typeName + "Page.designer.cs");
			}
			else 
			{
				return Path.Combine(basePath, "Client", "Pages", typeName + "Page.designer.cs");
			}
		}
예제 #4
0
        private static string GenerateTargetFilePath(string basePath, SourceWebPage page)
        {
            string typeName;
            string typeNamespace;

            DotNetParserHelper.SplitType(page.ClassFullName, out typeName, out typeNamespace);
            if (!string.IsNullOrEmpty(typeName))
            {
                return(Path.Combine(basePath, "Client", "Pages", typeNamespace, typeName + "Page.designer.cs"));
            }
            else
            {
                return(Path.Combine(basePath, "Client", "Pages", typeName + "Page.designer.cs"));
            }
        }
예제 #5
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);
        }
예제 #6
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;
		}
		public static TargetClassComparisonResult Compare(SourceWebPage webPage, TargetClass targetClass)
		{
			TargetClassComparisonResult comparison = new TargetClassComparisonResult();
			foreach(var control in webPage.Controls)
			{
				var targetField = targetClass.TargetFieldList.FirstOrDefault(i=>i.SourceFieldName == control.FieldName
																		&& i.SourceClassFullName == control.ClassFullName);
				if(targetField == null)
				{
					targetField = new TargetField()
					{
						SourceFieldName = control.FieldName,
						SourceClassFullName = control.ClassFullName
					};
					comparison.FieldsToAdd.Add(targetField);
				}
			}
			return comparison;
		}
        public static TargetClassComparisonResult Compare(SourceWebPage webPage, TargetClass targetClass)
        {
            TargetClassComparisonResult comparison = new TargetClassComparisonResult();

            foreach (var control in webPage.Controls)
            {
                var targetField = targetClass.TargetFieldList.FirstOrDefault(i => i.SourceFieldName == control.FieldName &&
                                                                             i.SourceClassFullName == control.ClassFullName);
                if (targetField == null)
                {
                    targetField = new TargetField()
                    {
                        SourceFieldName     = control.FieldName,
                        SourceClassFullName = control.ClassFullName
                    };
                    comparison.FieldsToAdd.Add(targetField);
                }
            }
            return(comparison);
        }
예제 #9
0
 public TargetClass UpdateClass(SourceWebPage sourceWebPage, TargetClass targetClass)
 {
     foreach (var sourceControl in sourceWebPage.Controls)
     {
         var targetField = targetClass.TargetFieldList.SingleOrDefault(i => i.SourceFieldName == sourceControl.FieldName);
         if (targetField == null)
         {
             targetField = new TargetField
             {
                 IsDirty             = true,
                 SourceNamespaceName = sourceControl.NamespaceName,
                 SourceClassName     = sourceControl.ClassName,
                 SourceFieldName     = sourceControl.FieldName,
                 TargetFieldName     = sourceControl.FieldName
             };
             EnumTargetControlType targetControlType;
             targetControlType             = GetTargetControlType(sourceControl);
             targetField.TargetControlType = targetControlType;
             targetClass.TargetFieldList.Add(targetField);
         }
         else
         {
             if (targetField.SourceClassFullName != sourceControl.ClassFullName)
             {
                 targetField.SourceClassName     = sourceControl.ClassName;
                 targetField.SourceNamespaceName = sourceControl.NamespaceName;
                 targetField.IsDirty             = true;
             }
             var targetControlType = GetTargetControlType(sourceControl);
             if (targetField.TargetControlType != targetControlType)
             {
                 targetField.TargetControlType = targetControlType;
                 targetField.IsDirty           = true;
             }
         }
     }
     return(targetClass);
 }
			public void ExistingClassChangedTargetFieldType_ShouldUpdateTargetFieldType()
			{
				SourceWebPage sourceWebPage = new SourceWebPage
				{
					ClassFullName = "Test1.TestSourceClass",
					PageUrl = "TestSourceClass.aspx",
					Controls = new List<SourceWebControl>()
				    {
				        new SourceWebControl
				        {
				            ClassFullName = typeof(System.Web.UI.WebControls.HyperLink).FullName,
				            FieldName = "TestTargetField"
				        }
				    }
				};
				var targetClass = new TargetClass()
				{
					TargetFieldList = new List<TargetField>() 
					{
						new TargetField
						{
							IsDirty = false,
							SourceClassFullName = typeof(System.Web.UI.WebControls.HyperLink).FullName,
							SourceFieldName = "TestTargetField",
							TargetControlType = EnumTargetControlType.TextBox,
							TargetFieldName = "TestTargetField"
						}
					}
				};
				var targetModelGenerator = new TargetModelGenerator();
				targetClass = targetModelGenerator.UpdateClass(sourceWebPage, targetClass);
				Assert.AreEqual(1, targetClass.TargetFieldList.Count);
				TestValidators.ValidateTargetField(targetClass.TargetFieldList[0],
											isDirty: true,
											sourceClassFullName: typeof(System.Web.UI.WebControls.HyperLink).FullName,
											sourceFieldName: "TestTargetField",
											targetControlType: EnumTargetControlType.Link,
											targetFieldName: "TestTargetField");
			}
			public void ExistingClassExistingIrrelevantFields() 
			{
				SourceWebPage sourceWebPage = new SourceWebPage
				{
					ClassFullName = "Test1.TestSourceClass",
					PageUrl = "TestSourceClass.aspx",
					Controls = new List<SourceWebControl>()
				    {
				        new SourceWebControl
				        {
				            ClassFullName = "System.Web.UI.WebControls.HyperLink",
				            FieldName = "NewTargetField"
				        }
				    }
				};
				var targetClass = new TargetClass()
				{
					TargetFieldList = new List<TargetField>() 
					{
						new TargetField
						{
							IsDirty = false,
							SourceClassFullName = "TestSourcenamespace.TestSourceClass",
							SourceFieldName = "ExistingTargetField",
							TargetControlType = EnumTargetControlType.Unknown,
							TargetFieldName = "ExistingTargetFieldName"
						}
					}
				};
				var targetModelGenerator = new TargetModelGenerator();
				targetClass = targetModelGenerator.UpdateClass(sourceWebPage, targetClass);
				Assert.AreEqual(2, targetClass.TargetFieldList.Count);

				TestValidators.ValidateTargetField(targetClass.TargetFieldList[0],
											isDirty:false,
											sourceClassFullName: "TestSourcenamespace.TestSourceClass",
											sourceFieldName: "ExistingTargetField",
											targetControlType: EnumTargetControlType.Unknown,
											targetFieldName: "ExistingTargetFieldName");

				TestValidators.ValidateTargetField(targetClass.TargetFieldList[1],
											isDirty:true,
											sourceClassFullName: "System.Web.UI.WebControls.HyperLink",
											sourceFieldName: "NewTargetField", 
											targetControlType: EnumTargetControlType.Link, 
											targetFieldName: "NewTargetField");
			}
			public void NewTargetClassWithLabel_ShouldCreateNewTargetClassWithLabel()
			{
				SourceWebPage sourceWebPage = new SourceWebPage
				{
					ClassFullName = "Test1.TestSourceClass",
					PageUrl = "TestSourceClass.aspx",
					Controls = new List<SourceWebControl>()
				    {
						new SourceWebControl
						{
				            ClassFullName = "System.Web.UI.WebControls.Label",
				            FieldName = "TestTargetField"
						}
				    }
				};
				TargetClass targetClass = new TargetClass();
				var targetModelGenerator = new TargetModelGenerator();
				targetClass = targetModelGenerator.UpdateClass(sourceWebPage, targetClass);
				Assert.AreEqual(1, targetClass.TargetFieldList.Count);
				TestValidators.ValidateTargetField(targetClass.TargetFieldList[0],
											isDirty:true,
											sourceClassFullName:"System.Web.UI.WebControls.Label",
											sourceFieldName:"TestTargetField",
											targetControlType: EnumTargetControlType.Label,
											targetFieldName:"TestTargetField");
			}
예제 #13
0
		public TargetClass UpdateClass(SourceWebPage sourceWebPage, TargetClass targetClass)
		{
			foreach(var sourceControl in sourceWebPage.Controls)
			{
				var targetField = targetClass.TargetFieldList.SingleOrDefault(i=>i.SourceFieldName == sourceControl.FieldName);
				if(targetField == null)
				{
					targetField = new TargetField
					{
						IsDirty = true,
						SourceNamespaceName = sourceControl.NamespaceName,
						SourceClassName = sourceControl.ClassName,
						SourceFieldName = sourceControl.FieldName,
						TargetFieldName = sourceControl.FieldName
					};
					EnumTargetControlType targetControlType;
					targetControlType = GetTargetControlType(sourceControl);
					targetField.TargetControlType = targetControlType;
					targetClass.TargetFieldList.Add(targetField);
				}
				else 
				{
					if(targetField.SourceClassFullName != sourceControl.ClassFullName)
					{
						targetField.SourceClassName = sourceControl.ClassName;
						targetField.SourceNamespaceName = sourceControl.NamespaceName;
						targetField.IsDirty = true;
					}
					var targetControlType = GetTargetControlType(sourceControl);
					if(targetField.TargetControlType != targetControlType)
					{
						targetField.TargetControlType = targetControlType;
						targetField.IsDirty = true;
					}
				}
			}
			return targetClass;
		}
예제 #14
0
		//public TargetProject UpdateProject(TargetProject targetProject, SourceWebProject sourceProject)
		//{
		//    //List<TargetClass> classesToAddToProject = new List<TargetClass>();
		//    //foreach (var masterPage in sourceProject.MasterPageList)
		//    //{
		//    //    //Find existing object
		//    //    var targetClass = targetProject.TargetClassList.SingleOrDefault(i => i.SourceClassFullName == masterPage.ClassFullName);
		//    //    if (targetClass == null)
		//    //    {
		//    //        //If does not exist, create it
		//    //        targetClass = TargetClass.Create(targetProject, sourceProject, masterPage);
		//    //        classesToAddToProject.Add(targetClass);
		//    //    }
		//    //    targetClass.ExpectedUrl = masterPage.PageUrl;
		//    //    targetClass.TargetObjectType = EnumTargetObjectType.MasterPage;
		//    //    //For each missing field, add it
		//    //    var comparison = TargetClassComparisonResult.Compare(masterPage, targetClass);
		//    //    targetClass.EnsureFiles(targetProjectPath);
		//    //    targetClass.AddFieldsToFile(targetProjectPath, targetClass.DesignerFilePath, comparison.FieldsToAdd);
		//    //}
		//    foreach (var sourcePage in sourceProject.WebPageList)
		//    {
		//        var targetClass = targetProject.TargetClassList.FirstOrDefault(i=>i.SourceClassFullName == sourcePage.ClassFullName);
		//        if(targetClass == null)
		//        {
		//            string relativeSourceNamespace;
		//            if(sourcePage.NamespaceName == sourceProject.RootNamespace)
		//            {
		//                relativeSourceNamespace = string.Empty;
		//            }
		//            else if(sourcePage.NamespaceName.StartsWith(sourceProject.RootNamespace))
		//            {
		//                relativeSourceNamespace = sourcePage.NamespaceName.Substring(sourceProject.RootNamespace.Length + 1);
		//            }
		//            else 
		//            {
		//                relativeSourceNamespace = sourcePage.NamespaceName;
		//            }
		//            string targetClassName = sourcePage.ClassName + "PageClient";
		//            string targetDirectory = @"Client\Pages\" + relativeSourceNamespace.Replace(".","\\");;
		//            string targetNamespace = targetProject.RootNamespace + ".Client.Pages." + relativeSourceNamespace;
		//            targetClass = new TargetClass
		//            {
		//                SourceClassFullName = sourcePage.ClassFullName,
		//                TargetClassFullName = targetNamespace + "." + targetClassName,
		//                DesignerFilePath = Path.Combine(targetDirectory, targetClassName + ".designer.cs"),
		//                UserFilePath = Path.Combine(targetDirectory, targetClassName + ".cs"),
		//                TargetObjectType = EnumTargetObjectType.WebPage,
		//                ExpectedUrl = sourcePage.PageUrl
		//            };
		//            targetProject.TargetClassList.Add(targetClass);
		//        }
		//    }
		//    return targetProject;
		//}

		public TargetClassComparisonResult CompareClass(SourceWebProject sourceProject, SourceWebPage sourceClass, TargetProject targetProject, TargetClass targetClass)
		{
			TargetClassComparisonResult result;
			if(targetClass == null)
			{
				string relativeSourceNamespace;
				if (sourceClass.NamespaceName == sourceProject.RootNamespace)
				{
					relativeSourceNamespace = string.Empty;
				}
				else if (sourceClass.NamespaceName.StartsWith(sourceProject.RootNamespace))
				{
					relativeSourceNamespace = sourceClass.NamespaceName.Substring(sourceProject.RootNamespace.Length + 1);
				}
				else
				{
					relativeSourceNamespace = sourceClass.NamespaceName;
				}
				string targetClassName = sourceClass.ClassName + "PageClient";
				string targetDirectory = @"Client\Pages";
				string targetNamespace = targetProject.RootNamespace + ".Client.Pages";
				if(!string.IsNullOrEmpty(relativeSourceNamespace))
				{
					targetDirectory += "\\" + relativeSourceNamespace.Replace(".", "\\");
					targetNamespace += "." + relativeSourceNamespace;
				}
				result = new TargetClassComparisonResult
				{
					SourceClassFullName = sourceClass.ClassFullName,
					TargetClassName = targetClassName,
					TargetNamespaceName = targetNamespace,
					DesignerFileRelativePath = Path.Combine(targetDirectory, targetClassName + ".designer.cs"),
					UserFileRelativePath = Path.Combine(targetDirectory, targetClassName + ".cs"),
					SourceObjectType = EnumSourceObjectType.WebPage,
					ExpectedUrl = sourceClass.PageUrl,
					IsDirty = true
				};
			}
			else 
			{
				result = new TargetClassComparisonResult
				{
					SourceClassFullName = targetClass.SourceClassFullName,
					TargetClassFullName = targetClass.TargetClassFullName,
					DesignerFileRelativePath = targetClass.DesignerFileRelativePath,
					UserFileRelativePath = targetClass.UserFileRelativePath,
					SourceObjectType = targetClass.SourceObjectType,
					ExpectedUrl = targetClass.ExpectedUrl
				};
				if(targetClass.ExpectedUrl != sourceClass.PageUrl)
				{
					result.ExpectedUrl = sourceClass.PageUrl;
					result.IsDirty = true;
				}
				if(targetClass.SourceObjectType != sourceClass.SourceObjectType)
				{
					result.SourceObjectType = sourceClass.SourceObjectType;
					result.IsDirty = true;
				}
			}
			foreach(var sourceControl in sourceClass.Controls)
			{
				TargetField targetControl = null;
				if(targetClass != null)
				{
					targetControl = targetClass.TargetFieldList.SingleOrDefault(i => i.SourceFieldName == sourceControl.FieldName);
				}
				if(targetControl == null)
				{
				    targetControl = new TargetField
				    {
				        SourceClassFullName = sourceControl.ClassFullName,
				        SourceFieldName = sourceControl.FieldName,
						TargetControlType = this.TargetClassManager.GetTargetControlType(sourceControl.ClassFullName),
				        IsDirty = true,
						TargetFieldName = sourceControl.FieldName
				    };
				    result.FieldsToAdd.Add(targetControl);
					result.IsDirty = true;
				}
				else if(targetControl.SourceClassFullName != sourceControl.ClassFullName)
				{
				    targetControl.SourceClassFullName = sourceControl.ClassFullName;
					result.FieldsToUpdate.Add(targetControl);
				    targetControl.IsDirty = true;
					result.IsDirty = true;
				}
			}
			return result;
		}
예제 #15
0
        //public TargetProject UpdateProject(TargetProject targetProject, SourceWebProject sourceProject)
        //{
        //    //List<TargetClass> classesToAddToProject = new List<TargetClass>();
        //    //foreach (var masterPage in sourceProject.MasterPageList)
        //    //{
        //    //    //Find existing object
        //    //    var targetClass = targetProject.TargetClassList.SingleOrDefault(i => i.SourceClassFullName == masterPage.ClassFullName);
        //    //    if (targetClass == null)
        //    //    {
        //    //        //If does not exist, create it
        //    //        targetClass = TargetClass.Create(targetProject, sourceProject, masterPage);
        //    //        classesToAddToProject.Add(targetClass);
        //    //    }
        //    //    targetClass.ExpectedUrl = masterPage.PageUrl;
        //    //    targetClass.TargetObjectType = EnumTargetObjectType.MasterPage;
        //    //    //For each missing field, add it
        //    //    var comparison = TargetClassComparisonResult.Compare(masterPage, targetClass);
        //    //    targetClass.EnsureFiles(targetProjectPath);
        //    //    targetClass.AddFieldsToFile(targetProjectPath, targetClass.DesignerFilePath, comparison.FieldsToAdd);
        //    //}
        //    foreach (var sourcePage in sourceProject.WebPageList)
        //    {
        //        var targetClass = targetProject.TargetClassList.FirstOrDefault(i=>i.SourceClassFullName == sourcePage.ClassFullName);
        //        if(targetClass == null)
        //        {
        //            string relativeSourceNamespace;
        //            if(sourcePage.NamespaceName == sourceProject.RootNamespace)
        //            {
        //                relativeSourceNamespace = string.Empty;
        //            }
        //            else if(sourcePage.NamespaceName.StartsWith(sourceProject.RootNamespace))
        //            {
        //                relativeSourceNamespace = sourcePage.NamespaceName.Substring(sourceProject.RootNamespace.Length + 1);
        //            }
        //            else
        //            {
        //                relativeSourceNamespace = sourcePage.NamespaceName;
        //            }
        //            string targetClassName = sourcePage.ClassName + "PageClient";
        //            string targetDirectory = @"Client\Pages\" + relativeSourceNamespace.Replace(".","\\");;
        //            string targetNamespace = targetProject.RootNamespace + ".Client.Pages." + relativeSourceNamespace;
        //            targetClass = new TargetClass
        //            {
        //                SourceClassFullName = sourcePage.ClassFullName,
        //                TargetClassFullName = targetNamespace + "." + targetClassName,
        //                DesignerFilePath = Path.Combine(targetDirectory, targetClassName + ".designer.cs"),
        //                UserFilePath = Path.Combine(targetDirectory, targetClassName + ".cs"),
        //                TargetObjectType = EnumTargetObjectType.WebPage,
        //                ExpectedUrl = sourcePage.PageUrl
        //            };
        //            targetProject.TargetClassList.Add(targetClass);
        //        }
        //    }
        //    return targetProject;
        //}

        public TargetClassComparisonResult CompareClass(SourceWebProject sourceProject, SourceWebPage sourceClass, TargetProject targetProject, TargetClass targetClass)
        {
            TargetClassComparisonResult result;

            if (targetClass == null)
            {
                string relativeSourceNamespace;
                if (sourceClass.NamespaceName == sourceProject.RootNamespace)
                {
                    relativeSourceNamespace = string.Empty;
                }
                else if (sourceClass.NamespaceName.StartsWith(sourceProject.RootNamespace))
                {
                    relativeSourceNamespace = sourceClass.NamespaceName.Substring(sourceProject.RootNamespace.Length + 1);
                }
                else
                {
                    relativeSourceNamespace = sourceClass.NamespaceName;
                }
                string targetClassName = sourceClass.ClassName + "PageClient";
                string targetDirectory = @"Client\Pages";
                string targetNamespace = targetProject.RootNamespace + ".Client.Pages";
                if (!string.IsNullOrEmpty(relativeSourceNamespace))
                {
                    targetDirectory += "\\" + relativeSourceNamespace.Replace(".", "\\");
                    targetNamespace += "." + relativeSourceNamespace;
                }
                result = new TargetClassComparisonResult
                {
                    SourceClassFullName      = sourceClass.ClassFullName,
                    TargetClassName          = targetClassName,
                    TargetNamespaceName      = targetNamespace,
                    DesignerFileRelativePath = Path.Combine(targetDirectory, targetClassName + ".designer.cs"),
                    UserFileRelativePath     = Path.Combine(targetDirectory, targetClassName + ".cs"),
                    SourceObjectType         = EnumSourceObjectType.WebPage,
                    ExpectedUrl = sourceClass.PageUrl,
                    IsDirty     = true
                };
            }
            else
            {
                result = new TargetClassComparisonResult
                {
                    SourceClassFullName      = targetClass.SourceClassFullName,
                    TargetClassFullName      = targetClass.TargetClassFullName,
                    DesignerFileRelativePath = targetClass.DesignerFileRelativePath,
                    UserFileRelativePath     = targetClass.UserFileRelativePath,
                    SourceObjectType         = targetClass.SourceObjectType,
                    ExpectedUrl = targetClass.ExpectedUrl
                };
                if (targetClass.ExpectedUrl != sourceClass.PageUrl)
                {
                    result.ExpectedUrl = sourceClass.PageUrl;
                    result.IsDirty     = true;
                }
                if (targetClass.SourceObjectType != sourceClass.SourceObjectType)
                {
                    result.SourceObjectType = sourceClass.SourceObjectType;
                    result.IsDirty          = true;
                }
            }
            foreach (var sourceControl in sourceClass.Controls)
            {
                TargetField targetControl = null;
                if (targetClass != null)
                {
                    targetControl = targetClass.TargetFieldList.SingleOrDefault(i => i.SourceFieldName == sourceControl.FieldName);
                }
                if (targetControl == null)
                {
                    targetControl = new TargetField
                    {
                        SourceClassFullName = sourceControl.ClassFullName,
                        SourceFieldName     = sourceControl.FieldName,
                        TargetControlType   = this.TargetClassManager.GetTargetControlType(sourceControl.ClassFullName),
                        IsDirty             = true,
                        TargetFieldName     = sourceControl.FieldName
                    };
                    result.FieldsToAdd.Add(targetControl);
                    result.IsDirty = true;
                }
                else if (targetControl.SourceClassFullName != sourceControl.ClassFullName)
                {
                    targetControl.SourceClassFullName = sourceControl.ClassFullName;
                    result.FieldsToUpdate.Add(targetControl);
                    targetControl.IsDirty = true;
                    result.IsDirty        = true;
                }
            }
            return(result);
        }
예제 #16
0
        //internal static TargetClass TryLoad(CSClass csClass)
        //{
        //    TargetClass returnValue = null;
        //    var uiClientPageAttribute = csClass.AttributeList.SingleOrDefault(i => i.TypeName == typeof(UIClientPageAttribute).Name && i.TypeNamespace == typeof(UIClientPageAttribute).Namespace);
        //    if(uiClientPageAttribute != null)
        //    {
        //        returnValue = new TargetClass
        //        {
        //            SourceClassFullName = Convert.ToString(uiClientPageAttribute.GetAttributeParameter(0, "SourceClassFullName", true)),
        //            TargetClassFullName = csClass.ClassFullName
        //        };

        //        //If there is only one field, 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.FilePathList.Count == 1)
        //        {
        //            returnValue.DesignerFilePath = csClass.FilePathList[0];
        //            returnValue.UserFilePath = csClass.FilePathList[0];
        //        }
        //        else if (csClass.FilePathList.Count > 1)
        //        {
        //            returnValue.DesignerFilePath = csClass.FilePathList.FirstOrDefault(i=>i.EndsWith(".designer.cs", StringComparison.CurrentCultureIgnoreCase));
        //            if(string.IsNullOrEmpty(returnValue.DesignerFilePath))
        //            {
        //                returnValue.DesignerFilePath = csClass.FilePathList[0];
        //                returnValue.UserFilePath = csClass.FilePathList[0];
        //            }
        //            else
        //            {
        //                returnValue.UserFilePath = csClass.FilePathList.FirstOrDefault(i=>i != returnValue.DesignerFilePath);
        //            }
        //        }

        //        foreach(var csProperty in csClass.PropertyList)
        //        {
        //            var targetField = TargetField.TryLoad(csProperty);
        //            if(targetField != null)
        //            {
        //                returnValue.TargetFieldList.Add(targetField);
        //            }
        //        }
        //    }
        //    return returnValue;
        //}

        public static TargetClass Create(TargetProject targetProject, SourceWebProject sourceProject, SourceWebPage sourcePage)
        {
            string sourceTypeName;
            string sourceTypeNamespace;

            DotNetParserHelper.SplitType(sourcePage.ClassFullName, out sourceTypeName, out sourceTypeNamespace);

            string relativeSourceNamespace;

            if (sourceTypeNamespace == sourceProject.RootNamespace)
            {
                relativeSourceNamespace = string.Empty;
            }
            else if (sourceTypeNamespace.StartsWith(sourceProject.RootNamespace))
            {
                relativeSourceNamespace = sourceTypeNamespace.Substring(sourceProject.RootNamespace.Length + 1);
            }
            else
            {
                relativeSourceNamespace = sourceTypeNamespace;
            }
            string      targetClassName = sourceTypeName + "PageClient";
            string      targetNamespace = targetProject.RootNamespace + ".Client.Pages." + relativeSourceNamespace;
            TargetClass returnValue     = new TargetClass()
            {
                SourceClassFullName      = sourcePage.ClassFullName,
                TargetClassFullName      = targetNamespace + "." + targetClassName,
                DesignerFileRelativePath = Path.Combine(targetNamespace.Replace('.', '\\'), targetClassName + ".designer.cs"),
                UserFileRelativePath     = Path.Combine(targetNamespace.Replace('.', '\\'), targetClassName + ".cs"),
            };

            return(returnValue);
        }