/// <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 SetDirectoryHasComponents() { string packageName = "SetDirectoryHasComponentsPackage"; 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.SetDirectoryHasComponents(components, true); Assert.AreEqual(1, target.ComponentLocations.Count()); Assert.AreEqual(components, target.ComponentLocations.ElementAtOrDefault(0)); // Now test that they turn off as well. target.SetDirectoryHasComponents(components, false); Assert.AreEqual(0, target.ComponentLocations.Count()); Assert.AreEqual(0, target.TypeLocations.Count()); }