private void CreateUserFile(TargetClassComparisonResult targetClass, string userFilePath) { string typeName; string typeNamespace; DotNetParserHelper.SplitType(targetClass.TargetClassFullName, out typeName, out typeNamespace); StringBuilder sb = new StringBuilder(); sb.AppendLine("using System;"); sb.AppendLine("using System.Collections.Generic;"); sb.AppendLine("using System.Linq;"); sb.AppendLine("using System.Text;"); sb.AppendLine("using MMDB.UITest.Core;"); sb.AppendLine("using WatiN.Core;"); sb.AppendLine(); sb.AppendLine(string.Format("namespace {0}", typeNamespace)); sb.AppendLine("{"); sb.AppendLine(string.Format("\tpublic partial class {0}", typeName)); sb.AppendLine("\t{"); sb.AppendLine(); sb.AppendLine("\t}"); sb.AppendLine("}"); CSharpParser parser = new CSharpParser(); var compilationUnit = parser.Parse(sb.ToString(), Path.GetFileName(userFilePath)); if (!Directory.Exists(Path.GetDirectoryName(userFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(userFilePath)); } using (StreamWriter writer = new StreamWriter(userFilePath)) { CSharpOutputVisitor outputVistor = new CSharpOutputVisitor(writer, new CSharpFormattingOptions()); compilationUnit.AcceptVisitor(outputVistor, null); } }
public static void ValidateTargetClassComparisonResult(TargetClassComparisonResult classResult, string designerFileRelativePath, string userFileRelativePath, string sourceClassFullName, string targetClassFullName, EnumSourceObjectType targetObjectType, string expectedUrl) { Assert.AreEqual(designerFileRelativePath, classResult.DesignerFileRelativePath); Assert.AreEqual(userFileRelativePath, classResult.UserFileRelativePath); Assert.AreEqual(sourceClassFullName, classResult.SourceClassFullName); Assert.AreEqual(targetClassFullName, classResult.TargetClassFullName); Assert.AreEqual(targetObjectType, classResult.SourceObjectType); Assert.AreEqual(expectedUrl, classResult.ExpectedUrl); }
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); }
private void CreateDesignerWebPageFile(TargetClassComparisonResult targetClass, string designerFilePath) { string typeName; string typeNamespace; DotNetParserHelper.SplitType(targetClass.TargetClassFullName, out typeName, out typeNamespace); StringBuilder sb = new StringBuilder(); sb.AppendLine("using System;"); sb.AppendLine("using System.Collections.Generic;"); sb.AppendLine("using System.Linq;"); sb.AppendLine("using System.Text;"); sb.AppendLine("using MMDB.UITest.Core;"); sb.AppendLine("using WatiN.Core;"); sb.AppendLine(); sb.AppendLine(string.Format("namespace {0}", typeNamespace)); sb.AppendLine("{"); //sb.AppendLine(string.Format("[{0}(sourceClassFullName:\"{1}\",expectedUrlList: new string[] {{\"{2}\"}})]", typeof(UIClientPageAttribute).FullName, targetClass.SourceClassFullName, targetClass.ExpectedUrl)); sb.AppendLine(string.Format("[{0}(sourceClassFullName:\"{1}\")]", typeof(UIClientPageAttribute).FullName, targetClass.SourceClassFullName)); sb.AppendLine(string.Format("partial class {0} : {1}", typeName, typeof(BasePageClient).FullName)); sb.AppendLine("{"); sb.AppendLine(); sb.AppendLine(string.Format("public {0} (Browser browser) : base(browser) {{}}", typeName)); sb.AppendLine(); sb.AppendLine(string.Format("protected override IEnumerable<string> ExpectedUrlList {{ get {{ return new string[] {{ \"{0}\" }}; }} }}", targetClass.ExpectedUrl)); sb.AppendLine("}"); sb.AppendLine("}"); CSharpParser parser = new CSharpParser(); var compilationUnit = parser.Parse(sb.ToString(), Path.GetFileName(designerFilePath)); if (!Directory.Exists(Path.GetDirectoryName(designerFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(designerFilePath)); } using (StreamWriter writer = new StreamWriter(designerFilePath)) { CSharpOutputVisitor outputVistor = new CSharpOutputVisitor(writer, new CSharpFormattingOptions()); compilationUnit.AcceptVisitor(outputVistor, null); } }
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); }
private void AddClass(TargetProject targetProject, TargetClassComparisonResult newClass) { throw new NotImplementedException(); }
//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; }
//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); }