Exemplo n.º 1
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;
		}
Exemplo n.º 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);
        }
			public void OneSourceClass_NewTargetProject_ShouldCreateTargetClass()
			{
				var sourceProject = new SourceWebProject 
				{
					WebPageList = new List<SourceWebPage>()
					{
						new SourceWebPage
						{
							ClassFullName = "TestSourceNamespace.Test1.TestItem",
							PageUrl = "TestWebPage.aspx"
						}
					},
					RootNamespace = "TestSourceNamespace"
				};

				var targetProject = new TargetProject
				{
					RootNamespace = "TestTargetNamespace"
				};
				var targetModelGenerator = new TargetModelGenerator();
				var projectResult = targetModelGenerator.CompareProject(targetProject, sourceProject);
				Assert.AreEqual(1, projectResult.ClassesToAdd.Count);
				Assert.AreEqual(0, projectResult.ClassesToUpdate.Count);
				TestValidators.ValidateTargetClassComparisonResult(projectResult.ClassesToAdd[0],
																	@"Client\Pages\Test1\TestItemPageClient.designer.cs",
																	@"Client\Pages\Test1\TestItemPageClient.cs",
																	@"TestSourceNamespace.Test1.TestItem",
																	@"TestTargetNamespace.Client.Pages.Test1.TestItemPageClient", 
																	EnumSourceObjectType.WebPage,
																	"TestWebPage.aspx");
			}
			public void MatchingSourceNamespace_CreatesTargetClassWithSameNamespace()
			{
				var sourceProject = new SourceWebProject
				{
					WebPageList = new List<SourceWebPage>()
					{
						new SourceWebPage
						{
							ClassFullName = "TestTargetNamespace.Test1.TestItem",
							PageUrl = "TestWebPage.aspx"
						}
					},
					RootNamespace = "TestSourceNamespace"
				};

				var targetProject = new TargetProject
				{
					RootNamespace = "TestTargetNamespace.Test1"
				};
				var targetModelGenerator = new TargetModelGenerator();
				var projectResult = targetModelGenerator.CompareProject(targetProject, sourceProject);
				Assert.AreEqual(1, projectResult.ClassesToAdd.Count);
				Assert.AreEqual(0, projectResult.ClassesToUpdate.Count);
				TestValidators.ValidateTargetClassComparisonResult(classResult:projectResult.ClassesToAdd[0],
																	designerFileRelativePath:@"Client\Pages\TestTargetNamespace\Test1\TestItemPageClient.designer.cs",
																	userFileRelativePath: @"Client\Pages\TestTargetNamespace\Test1\TestItemPageClient.cs",
																	sourceClassFullName: @"TestTargetNamespace.Test1.TestItem",
																	targetClassFullName: @"TestTargetNamespace.Test1.Client.Pages.TestTargetNamespace.Test1.TestItemPageClient", 
																	targetObjectType:EnumSourceObjectType.WebPage, 
																	expectedUrl:"TestWebPage.aspx");
			}
Exemplo n.º 5
0
        public static void UpdateProxyProject(string targetProjectPath, SourceWebProject sourceProject)
        {
            XDocument     xdoc = XDocument.Load(targetProjectPath);
            var           targetModelGenerator = new TargetModelGenerator();
            TargetProject targetProject        = targetModelGenerator.LoadFromProjectFile(targetProjectPath);
            var           projectComparison    = targetModelGenerator.CompareProject(targetProject, sourceProject);

            targetModelGenerator.UpdateProjectFile(targetProject, projectComparison);
        }
Exemplo n.º 6
0
 public void UpdateProjectFile(TargetProject targetProject, TargetProjectComparisonResult projectComparison)
 {
     foreach (var newClass in projectComparison.ClassesToAdd)
     {
         this.AddClass(targetProject, newClass);
     }
     foreach (var updateClass in projectComparison.ClassesToUpdate)
     {
         this.UpdateClass(targetProject, updateClass);
     }
 }
Exemplo n.º 7
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;
		}
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public TargetProjectComparisonResult CompareProject(TargetProject targetProject, SourceWebProject sourceProject)
        {
            TargetProjectComparisonResult result = new TargetProjectComparisonResult();

            //foreach (var masterPage in sourceProject.MasterPageList)
            //{
            //    //Find existing object
            //    var targetClass = targetProject.TargetClassList.SingleOrDefault(i => i.SourceClassFullName == masterPage.ClassFullName);
            //    if (targetClass == null)
            //    {
            //        TargetClassComparisonResult classResult = new TargetClassComparisonResult()
            //        {
            //            a
            //        }
            //        //If does not exist, create it
            //        targetClass = TargetClass.Create(targetProject, sourceProject, masterPage);
            //        result.ClassesToAdd.Add(targetClass);
            //    }
            //    targetClass.PageUrl = masterPage.PageUrl;
            //    targetClass.TargetObjectType = EnumTargetObjectType.MasterPage;
            //    this.TargetClassManager.UpdateTargetClass(masterPage, targetClass);
            //}
            foreach (var sourcePage in sourceProject.WebPageList)
            {
                var targetClass = targetProject.TargetClassList.SingleOrDefault(i => i.SourceClassFullName == sourcePage.ClassFullName);
                if (targetClass == null)
                {
                    TargetClassComparisonResult classResult = this.CompareClass(sourceProject, sourcePage, targetProject, null);
                    result.ClassesToAdd.Add(classResult);
                }
                else
                {
                    TargetClassComparisonResult classResult = this.CompareClass(sourceProject, sourcePage, targetProject, targetClass);
                    result.ClassesToUpdate.Add(classResult);
                }
            }
            return(result);
        }
Exemplo n.º 10
0
		public TargetProjectComparisonResult CompareProject(TargetProject targetProject, SourceWebProject sourceProject)
		{
		    TargetProjectComparisonResult result = new TargetProjectComparisonResult();
			//foreach (var masterPage in sourceProject.MasterPageList)
			//{
			//    //Find existing object
			//    var targetClass = targetProject.TargetClassList.SingleOrDefault(i => i.SourceClassFullName == masterPage.ClassFullName);
			//    if (targetClass == null)
			//    {
			//        TargetClassComparisonResult classResult = new TargetClassComparisonResult()
			//        {
			//            a
			//        }
			//        //If does not exist, create it
			//        targetClass = TargetClass.Create(targetProject, sourceProject, masterPage);
			//        result.ClassesToAdd.Add(targetClass);
			//    }
			//    targetClass.PageUrl = masterPage.PageUrl;
			//    targetClass.TargetObjectType = EnumTargetObjectType.MasterPage;
			//    this.TargetClassManager.UpdateTargetClass(masterPage, targetClass);
			//}
		    foreach (var sourcePage in sourceProject.WebPageList)
		    {
		        var targetClass = targetProject.TargetClassList.SingleOrDefault(i => i.SourceClassFullName == sourcePage.ClassFullName);
		        if (targetClass == null)
		        {
					TargetClassComparisonResult classResult = this.CompareClass(sourceProject, sourcePage, targetProject, null);
		            result.ClassesToAdd.Add(classResult);
		        } 
				else
				{
					TargetClassComparisonResult classResult = this.CompareClass(sourceProject, sourcePage, targetProject, targetClass);
					result.ClassesToUpdate.Add(classResult);
				}
		    }
		    return result;
		}
			public void ExistingTargetClassWithDifferentName_ShouldUpdateExistingTargetClass()
			{
				var sourceProject = new SourceWebProject
				{
					WebPageList = new List<SourceWebPage>()
					{
						new SourceWebPage
						{
							ClassFullName = "TestSourceNamespace.Test1.TestItem",
							PageUrl = "TestWebPage.aspx"
						}
					},
					RootNamespace = "TestSourceNamespace"
				};

				var targetProject = new TargetProject
				{
					RootNamespace = "TestTargetNamespace",
					TargetClassList = new List<TargetClass>() 
					{
						new TargetClass
						{
							SourceClassFullName = "TestSourceNamespace.Test1.TestItem",
							DesignerFileRelativePath = @"SomeOtherLocation\SomeOtherClassName.designer.cs",
							UserFileRelativePath = @"SomeOtherLocation\SomeOtherClassName.cs",
							TargetClassFullName = "SomeOtherLocation.SomeOtherClassName",
							SourceObjectType = EnumSourceObjectType.WebPage,
							ExpectedUrl = "TestWebPage.aspx"
						}
					}
				};
				var targetModelGenerator = new TargetModelGenerator();
				var projectResult = targetModelGenerator.CompareProject(targetProject, sourceProject);
				Assert.AreEqual(0, projectResult.ClassesToAdd.Count);
				Assert.AreEqual(1, projectResult.ClassesToUpdate.Count);
				TestValidators.ValidateTargetClassComparisonResult(projectResult.ClassesToUpdate[0],
																	@"SomeOtherLocation\SomeOtherClassName.designer.cs", 
																	@"SomeOtherLocation\SomeOtherClassName.cs", 
																	"TestSourceNamespace.Test1.TestItem", 
																	"SomeOtherLocation.SomeOtherClassName", 
																	EnumSourceObjectType.WebPage,
																	"TestWebPage.aspx");
			}
			public void ExistingTargetClassWithExpectedNameAndLocation_ShouldUpdateExistingClass()
			{
				var sourceProject = new SourceWebProject
				{
					WebPageList = new List<SourceWebPage>()
					{
						new SourceWebPage
						{
							ClassFullName = "TestSourceNamespace.Test1.TestItem",
							PageUrl = "TestWebPage.aspx"
						}
					},
					RootNamespace = "TestSourceNamespace"
				};

				var targetProject = new TargetProject
				{
					RootNamespace = "TestTargetNamespace",
					TargetClassList = new List<TargetClass>() 
					{
						new TargetClass
						{
							SourceClassFullName = "TestSourceNamespace.Test1.TestItem",
							DesignerFileRelativePath = @"Client\Pages\Test1\TestItemPageClient.designer.cs",
							UserFileRelativePath = @"Client\Pages\Test1\TestItemPageClient.cs",
							TargetClassFullName = "TestTargetNamespace.Client.Pages.Test1.TestItemPageClient",
							SourceObjectType = EnumSourceObjectType.WebPage,
							ExpectedUrl = "TestWebPage.aspx"
						}
					}
				};
				var targetModelGenerator = new TargetModelGenerator();
				var projectResult = targetModelGenerator.CompareProject(targetProject, sourceProject);
				Assert.AreEqual(0, projectResult.ClassesToAdd.Count);
				Assert.AreEqual(1, projectResult.ClassesToUpdate.Count);
			}
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
		private void AddClass(TargetProject targetProject, TargetClassComparisonResult newClass)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 15
0
		public void UpdateProjectFile(TargetProject targetProject, TargetProjectComparisonResult projectComparison)
		{
			foreach(var newClass in projectComparison.ClassesToAdd)
			{
				this.AddClass(targetProject, newClass);
			}
			foreach(var updateClass in projectComparison.ClassesToUpdate)
			{
				this.UpdateClass(targetProject, updateClass);
			}
		}
Exemplo n.º 16
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;
		}
Exemplo n.º 17
0
 private void AddClass(TargetProject targetProject, TargetClassComparisonResult newClass)
 {
     throw new NotImplementedException();
 }