Ejemplo n.º 1
0
        public void EnsureFiles(string targetProjectPath)
        {
            string userFilePath = Path.Combine(Path.GetDirectoryName(targetProjectPath), this.UserFileRelativePath);

            if (!File.Exists(userFilePath))
            {
                this.CreateUserFile(userFilePath);
            }

            string designerFilePath = Path.Combine(Path.GetDirectoryName(targetProjectPath), this.DesignerFileRelativePath);

            if (!File.Exists(designerFilePath))
            {
                switch (this.SourceObjectType)
                {
                case EnumSourceObjectType.MasterPage:
                    this.CreateDesignerMasterPageFile(designerFilePath);
                    break;

                case EnumSourceObjectType.WebPage:
                    this.CreateWebPageFile(designerFilePath);
                    break;

                default:
                    throw new UnknownEnumValueException(this.SourceObjectType);
                }
            }

            ProjectParser parser = new ProjectParser();

            parser.EnsureFileInclude(targetProjectPath, this.UserFileRelativePath, null);
            parser.EnsureFileInclude(targetProjectPath, this.DesignerFileRelativePath, this.UserFileRelativePath);
        }
Ejemplo n.º 2
0
        public void ApplyChanges(TargetProjectComparisonResult comparison, string outputProjectPath)
        {
            foreach (var newClass in comparison.ClassesToAdd)
            {
                string userFilePath = Path.Combine(Path.GetDirectoryName(outputProjectPath), newClass.UserFileRelativePath);
                if (!File.Exists(userFilePath))
                {
                    this.CreateUserFile(newClass, userFilePath);
                }
                string designerFilePath = Path.Combine(Path.GetDirectoryName(outputProjectPath), newClass.DesignerFileRelativePath);
                //if (!File.Exists(designerFilePath))
                //{
                switch (newClass.SourceObjectType)
                {
                case EnumSourceObjectType.MasterPage:
                    this.CreateDesignerMasterPageFile(newClass, designerFilePath);
                    break;

                case EnumSourceObjectType.WebPage:
                    this.CreateDesignerWebPageFile(newClass, designerFilePath);
                    break;

                default:
                    throw new UnknownEnumValueException(newClass.SourceObjectType);
                }
                //}
                ProjectParser parser = new ProjectParser();
                parser.EnsureFileInclude(outputProjectPath, newClass.UserFileRelativePath, null);
                parser.EnsureFileInclude(outputProjectPath, newClass.DesignerFileRelativePath, newClass.UserFileRelativePath);
            }
            foreach (var updatedClass in comparison.ClassesToUpdate)
            {
                string designerFilePath = Path.Combine(Path.GetDirectoryName(outputProjectPath), updatedClass.DesignerFileRelativePath);
                //if (!File.Exists(designerFilePath))
                //{
                switch (updatedClass.SourceObjectType)
                {
                case EnumSourceObjectType.MasterPage:
                    this.CreateDesignerMasterPageFile(updatedClass, designerFilePath);
                    break;

                case EnumSourceObjectType.WebPage:
                    this.CreateDesignerWebPageFile(updatedClass, designerFilePath);
                    break;

                default:
                    throw new UnknownEnumValueException(updatedClass.SourceObjectType);
                }
                //}
                ProjectParser parser = new ProjectParser();
                parser.EnsureFileInclude(outputProjectPath, updatedClass.DesignerFileRelativePath, updatedClass.DesignerFileRelativePath);
            }
        }
Ejemplo n.º 3
0
            public void TestEnsureFileIncludeExistingDependentNode()
            {
                string data =
                    @"<?xml version=""1.0"" encoding=""utf-8""?>
					<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
						<ItemGroup>
							<Compile Include=""TestDirectory\TestClass1.aspx.cs"">
							  <DependentUpon>SomethingElse.aspx</DependentUpon>
							</Compile>
						</ItemGroup>
					</Project>
				"                ;
                ProjectParser parser = new ProjectParser();
                bool          anyChange;
                string        actualResult = parser.EnsureFileInclude(data, "C:\\Test\\TestProject.csproj", "C:\\Test\\TestDirectory\\TestClass1.aspx.cs", "C:\\Test\\TestDirectory\\TestClass1.aspx", out anyChange);

                Assert.IsTrue(anyChange);
                string expectedResult =
                    @"<?xml version=""1.0"" encoding=""utf-8""?>
					<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
						<ItemGroup>
							<Compile Include=""TestDirectory\TestClass1.aspx.cs"">
							  <DependentUpon>TestClass1.aspx</DependentUpon>
							</Compile>
						</ItemGroup>
					</Project>
				"                ;

                this.CompareXml(expectedResult, actualResult);
            }
Ejemplo n.º 4
0
            public void TestEnsureFileIncludeInvalidProjectFile()
            {
                var data =
                    @"<?xml version=""1.0"" encoding=""utf-8""?>
					<test>
					</test>
				"                ;

                ProjectParser parser = new ProjectParser();
                bool          anyChange;

                Assert.Throws(typeof(InvalidDataException), () => { parser.EnsureFileInclude(data, "C:\\Test\\Test.csproj", "C:\\Test\\TestFile.aspx", null, out anyChange); });
            }
Ejemplo n.º 5
0
			public void TestEnsureFileIncludeInvalidProjectFile()
			{
				var data =
				@"<?xml version=""1.0"" encoding=""utf-8""?>
					<test>
					</test>
				";

				ProjectParser parser = new ProjectParser();
				bool anyChange;
				Assert.Throws(typeof(InvalidDataException), ()=>{parser.EnsureFileInclude(data, "C:\\Test\\Test.csproj", "C:\\Test\\TestFile.aspx", null, out anyChange);});
			} 
Ejemplo n.º 6
0
			public void TestEnsureFileIncludeExistingDependentNode()
			{
				string data =
				@"<?xml version=""1.0"" encoding=""utf-8""?>
					<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
						<ItemGroup>
							<Compile Include=""TestDirectory\TestClass1.aspx.cs"">
							  <DependentUpon>SomethingElse.aspx</DependentUpon>
							</Compile>
						</ItemGroup>
					</Project>
				";
				ProjectParser parser = new ProjectParser();
				bool anyChange;
				string actualResult = parser.EnsureFileInclude(data, "C:\\Test\\TestProject.csproj", "C:\\Test\\TestDirectory\\TestClass1.aspx.cs", "C:\\Test\\TestDirectory\\TestClass1.aspx", out anyChange);
				Assert.IsTrue(anyChange);
				string expectedResult =
				@"<?xml version=""1.0"" encoding=""utf-8""?>
					<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
						<ItemGroup>
							<Compile Include=""TestDirectory\TestClass1.aspx.cs"">
							  <DependentUpon>TestClass1.aspx</DependentUpon>
							</Compile>
						</ItemGroup>
					</Project>
				";
				this.CompareXml(expectedResult, actualResult);
			}