public void TestAppend() { ParsedPath pp1 = new ParsedPath(@"c:\blah\blah", PathType.Directory); ParsedPath ppCombine = pp1.Append("file.txt", PathType.File); Assert.AreEqual(@"c:\blah\blah\file.txt", ppCombine); pp1 = new ParsedPath(@"c:\blah\blah", PathType.Directory); Assert.Throws(typeof(ArgumentException), delegate { ppCombine = pp1.Append(@"\blah\file.txt", PathType.File); }); pp1 = new ParsedPath(@"c:\blah\blah", PathType.Directory); ppCombine = pp1.Append(@"blah\file.txt", PathType.File); Assert.AreEqual(@"c:\blah\blah\blah\file.txt", ppCombine); }
public BuildContext(String properties, ParsedPath contentFilePath) { ContentFilePath = contentFilePath; ContentFile = new ContentFileV4(); ContentFile.Load(ContentFilePath); WriteMessage("Read content file '{0}'", ContentFilePath); Properties = new PropertyCollection(); // Start with the environment Properties.AddFromEnvironment(); // Set defaults for important locations Properties.Set("BuildContentDir", new ParsedPath(Assembly.GetExecutingAssembly().Location, PathType.File).VolumeAndDirectory.ToString()); Properties.Set("ContentFileDir", contentFilePath.VolumeAndDirectory); Properties.Set("InputDir", contentFilePath.VolumeAndDirectory); Properties.Set("OutputDir", contentFilePath.VolumeAndDirectory); // Now override with from content file Properties.AddFromList(ContentFile.Properties.Select(nv => new KeyValuePair<string, string>(nv.Name.Value, nv.Value.Value))); // Now override with command line Properties.AddFromString(properties); // Add content file hash location if not set already if (!Properties.Contains("ContentFileHashes")) { ParsedPath path = new ParsedPath(Properties.GetRequiredValue("OutputDir"), PathType.Directory); Properties.Set("ContentHashesFile", path.Append(ContentFilePath.FileAndExtension + ".hashes", PathType.File)); } ContentFileHashesPath = new ParsedPath(Properties.GetRequiredValue("ContentHashesFile"), PathType.File).MakeFullPath(); ContentFileWriteTime = File.GetLastWriteTime(this.ContentFilePath); // Create a hash of all the things than can affect the build SHA1 sha1 = SHA1.Create(); StringBuilder sb = new StringBuilder(); foreach (var rawAssembly in ContentFile.CompilerAssemblies) { sb.Append(rawAssembly.Value); } foreach (var rawProperty in ContentFile.Properties) { sb.Append(rawProperty.Name.Value); sb.Append(rawProperty.Value.Value); } foreach (var rawCompilerSettings in this.ContentFile.CompilerSettings) { sb.Append(rawCompilerSettings.Name); foreach (var extension in rawCompilerSettings.CompilerExtensions) { foreach (var input in extension.Inputs) sb.Append(input.Value); foreach (var output in extension.Outputs) sb.Append(output.Value); } foreach (var parameter in rawCompilerSettings.Parameters.KeyValues) { sb.Append(parameter.Key.Value); sb.Append(parameter.Value.ToString()); } } GlobalHash = BitConverter.ToString(sha1.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()))).Replace("-", ""); LoadCompilerClasses(); }