/// <summary> /// Adds item and its content (file or folder) to package. /// </summary> /// <param name="pPkg">Package being created.</param> /// <param name="item">Item to be added.</param> /// <returns>True is there was no error during the operation, false otherwise.</returns> private bool AddItemToPackage(TraceLab.Core.PackageSystem.Package pkg, PackageFileSourceInfo item) { bool noError = true; string targetPath = System.IO.Path.Combine(pkg.Location, item.GetPath()); PackageHeirarchyItem dir = item as PackageHeirarchyItem; if (dir != null) { if (item.Parent != null) { System.IO.Directory.CreateDirectory(targetPath); } foreach (PackageFileSourceInfo child in dir.Children) { noError = noError && AddItemToPackage(pkg, child); } if (dir.HasComponents) { pkg.SetDirectoryHasComponents(dir.GetPath(), true); } if (dir.HasTypes) { pkg.SetDirectoryHasTypes(dir.GetPath(), true); } } else { System.IO.File.Copy(item.SourceFilePath, targetPath); //Add reference to this created package to all experiments and composite components if (this.isExperimentPackage && targetPath.EndsWith(".teml") || targetPath.EndsWith(".tcml")) { noError = noError && AddPkgRefToExperiment(pkg, targetPath); } System.IO.File.SetAttributes(targetPath, System.IO.File.GetAttributes(targetPath) & ~System.IO.FileAttributes.ReadOnly); pkg.AddFile(targetPath); } return(noError); }
public void SetDirectoryHasTypes() { string packageName = "SetDirectoryHasTypesPackage"; string packageDirectory = System.IO.Path.Combine(PackageTestRoot, packageName); System.IO.Directory.CreateDirectory(packageDirectory); Package target = new Package(packageDirectory, false); string components = System.IO.Path.Combine(target.Location, "Components"); string types = System.IO.Path.Combine(target.Location, "Types"); string data = System.IO.Path.Combine(target.Location, "Files"); System.IO.Directory.CreateDirectory(components); System.IO.Directory.CreateDirectory(types); System.IO.Directory.CreateDirectory(data); WriteFile(System.IO.Path.Combine(components, "Importer.dll"), "TraceLab.Core.Test.PackageSystem.PackageSystemTestResources.Components.Importer.dll"); WriteFile(System.IO.Path.Combine(types, "DictionaryTermWeights.dll"), "TraceLab.Core.Test.PackageSystem.PackageSystemTestResources.Types.DictionaryTermWeights.dll"); target.AddFile(System.IO.Path.Combine(components, "Importer.dll")); target.AddFile(System.IO.Path.Combine(types, "DictionaryTermWeights.dll")); Assert.AreEqual(0, target.ComponentLocations.Count()); Assert.AreEqual(0, target.TypeLocations.Count()); target.SetDirectoryHasTypes(types, true); Assert.AreEqual(1, target.TypeLocations.Count()); Assert.AreEqual(types, target.TypeLocations.ElementAtOrDefault(0)); target.SetDirectoryHasTypes(types, false); Assert.AreEqual(0, target.TypeLocations.Count()); Assert.AreEqual(0, target.ComponentLocations.Count()); }
public void AddFileTest() { string packageName = "AddFileTestPackage"; string packageDirectory = System.IO.Path.Combine(PackageTestRoot, packageName); System.IO.Directory.CreateDirectory(packageDirectory); Package target = new Package(packageDirectory, false); string components = System.IO.Path.Combine(target.Location, "Components"); string types = System.IO.Path.Combine(target.Location, "Types"); string data = System.IO.Path.Combine(target.Location, "Files"); System.IO.Directory.CreateDirectory(components); System.IO.Directory.CreateDirectory(types); System.IO.Directory.CreateDirectory(data); WriteFile(System.IO.Path.Combine(data, "coest.xml"), "TraceLab.Core.Test.PackageSystem.PackageSystemTestResources.Data.coest.xml"); WriteFile(System.IO.Path.Combine(target.Location, "randomfile.something"), "TraceLab.Core.Test.PackageSystem.PackageSystemTestResources.Data.randomfile.something"); WriteFile(System.IO.Path.Combine(components, "Importer.dll"), "TraceLab.Core.Test.PackageSystem.PackageSystemTestResources.Components.Importer.dll"); WriteFile(System.IO.Path.Combine(types, "DictionaryTermWeights.dll"), "TraceLab.Core.Test.PackageSystem.PackageSystemTestResources.Types.DictionaryTermWeights.dll"); target.AddFile(System.IO.Path.Combine(data, "coest.xml")); target.AddFile(System.IO.Path.Combine(target.Location, "randomfile.something")); target.AddFile(System.IO.Path.Combine(components, "Importer.dll")); target.AddFile(System.IO.Path.Combine(types, "DictionaryTermWeights.dll")); // TODO: Verify that files are added correctly Assert.AreEqual(4, target.Files.Count()); }