Пример #1
0
        /// <summary>
        /// Creates an empty folder inside the PackageHeirarchyItem provided.
        /// </summary>
        /// <param name="pParent">Parent node of the new folder.</param>
        /// <param name="pFolderName">Name of the folder.</param>
        /// <returns></returns>
        private PackageHeirarchyItem CreateFolder(PackageHeirarchyItem pParent, string pFolderName)
        {
            PackageHeirarchyItem newFolder = new PackageHeirarchyItem("");

            newFolder.Name   = pFolderName;
            newFolder.Parent = pParent;
            pParent.Children.Add(newFolder);

            return(newFolder);
        }
Пример #2
0
        static bool Contains(PackageHeirarchyItem info, string name)
        {
            bool contains = false;

            foreach (PackageFileSourceInfo item in info.Children)
            {
                if (string.Equals(name, item.Name))
                {
                    contains = true;
                    break;
                }
            }
            return(contains);
        }
Пример #3
0
        public PackageFileSourceInfo Add(PackageHeirarchyItem parent, string filePath)
        {
            PackageFileSourceInfo newItem = null;

            if (System.IO.File.Exists(filePath))
            {
                newItem = AddFile(parent, filePath);
            }
            else if (System.IO.Directory.Exists(filePath))
            {
                newItem = AddFolder(parent, filePath);
            }

            return(newItem);
        }
Пример #4
0
        private PackageFileSourceInfo AddFile(PackageHeirarchyItem parent, string filePath)
        {
            PackageFileSourceInfo newItem = null;

            var name = System.IO.Path.GetFileName(filePath);

            if (parent != null && !Contains(parent, name))
            {
                newItem        = new PackageFileSourceInfo(filePath);
                newItem.Name   = name;
                newItem.Parent = parent;

                parent.Children.Add(newItem);
            }

            return(newItem);
        }
Пример #5
0
        private PackageHeirarchyItem CreateRelativeFolders(PackageHeirarchyItem experimentFolder, PackageFileInfo file)
        {
            PackageHeirarchyItem lastFolder = experimentFolder;

            foreach (string folder in file.FoldersPath)
            {
                PackageHeirarchyItem folderInfo;
                if (ContainsFolder(lastFolder, folder, out folderInfo))
                {
                    lastFolder = folderInfo;
                }
                else
                {
                    lastFolder = CreateFolder(lastFolder, folder);
                }
            }
            return(lastFolder);
        }
Пример #6
0
        public string GetPath()
        {
            string path = Name;
            PackageHeirarchyItem parent = Parent;

            while (parent != null)
            {
                // Don't count the root
                if (parent.Parent != null)
                {
                    path = System.IO.Path.Combine(parent.Name, path);
                }
                parent = parent.Parent;
            }

            path = System.IO.Path.Combine(".", path);

            return(path);
        }
Пример #7
0
        /// <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>
        public static bool AddItemToPackage(TraceLab.Core.PackageSystem.Package pkg, PackageFileSourceInfo item, bool isExperimentPackage)
        {
            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, isExperimentPackage);
                }

                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 (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);
        }
Пример #8
0
        static bool ContainsFolder(PackageHeirarchyItem info, string name, out PackageHeirarchyItem resultFolder)
        {
            resultFolder = null;
            bool contains = false;

            foreach (PackageFileSourceInfo item in info.Children)
            {
                if (string.Equals(name, item.Name))
                {
                    resultFolder = item as PackageHeirarchyItem;
                    //if resultFolder now is different than null it means there is such folder in hierarchy,
                    //otherwise there is file of same name - so return false
                    if (resultFolder != null)
                    {
                        contains = true;
                    }
                    break;
                }
            }
            return(contains);
        }
Пример #9
0
        private PackageFileSourceInfo AddFolder(PackageHeirarchyItem parent, string filePath)
        {
            PackageHeirarchyItem newItem = null;

            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(filePath);
            if (parent != null && !Contains(parent, dir.Name))
            {
                newItem        = new PackageHeirarchyItem(filePath);
                newItem.Name   = dir.Name;
                newItem.Parent = parent;

                parent.Children.Add(newItem);

                // EnumerateFiles is not working on mono for some reason, therefore use GetFiles instead,
                IEnumerable <System.IO.FileInfo> files;
                if (TraceLabSDK.RuntimeInfo.IsRunInMono)
                {
                    files = dir.GetFiles();
                }
                else
                {
                    files = dir.EnumerateFiles();
                }

                foreach (System.IO.FileInfo file in files)
                {
                    AddFile(newItem, file.FullName);
                }

                foreach (System.IO.DirectoryInfo subDir in dir.EnumerateDirectories())
                {
                    AddFolder(newItem, subDir.FullName);
                }
            }

            return(newItem);
        }
Пример #10
0
 static bool ContainsFolder(PackageHeirarchyItem info, string name, out PackageHeirarchyItem resultFolder)
 {
     resultFolder = null;
     bool contains = false;
     foreach (PackageFileSourceInfo item in info.Children)
     {
         if (string.Equals(name, item.Name))
         {
             resultFolder = item as PackageHeirarchyItem;
             //if resultFolder now is different than null it means there is such folder in hierarchy,
             //otherwise there is file of same name - so return false
             if (resultFolder != null)
             {
                 contains = true;
             }
             break;
         }
     }
     return contains;
 }
Пример #11
0
 static bool Contains(PackageHeirarchyItem info, string name)
 {
     bool contains = false;
     foreach (PackageFileSourceInfo item in info.Children)
     {
         if (string.Equals(name, item.Name))
         {
             contains = true;
             break;
         }
     }
     return contains;
 }
Пример #12
0
        private PackageFileSourceInfo AddFolder(PackageHeirarchyItem parent, string filePath)
        {
            PackageHeirarchyItem newItem = null;

            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(filePath);
            if (parent != null && !Contains(parent, dir.Name))
            {
                newItem = new PackageHeirarchyItem(filePath);
                newItem.Name = dir.Name;
                newItem.Parent = parent;

                parent.Children.Add(newItem);

                // EnumerateFiles is not working on mono for some reason, therefore use GetFiles instead,
                IEnumerable<System.IO.FileInfo> files;
                if(TraceLabSDK.RuntimeInfo.IsRunInMono) 
                {
                    files = dir.GetFiles();
                } 
                else 
                {
                    files = dir.EnumerateFiles();
                }

                foreach (System.IO.FileInfo file in files)
                {
                    AddFile(newItem, file.FullName);
                }

                foreach (System.IO.DirectoryInfo subDir in dir.EnumerateDirectories())
                {
                    AddFolder(newItem, subDir.FullName);
                }
            }

            return newItem;
        }
Пример #13
0
        private PackageFileSourceInfo AddFile(PackageHeirarchyItem parent, string filePath)
        {
            PackageFileSourceInfo newItem = null;

            var name = System.IO.Path.GetFileName(filePath);
            if (parent != null && !Contains(parent, name))
            {
                newItem = new PackageFileSourceInfo(filePath);
                newItem.Name = name;
                newItem.Parent = parent;

                parent.Children.Add(newItem);
            }

            return newItem;
        }
Пример #14
0
        public PackageFileSourceInfo Add(PackageHeirarchyItem parent, string filePath)
        {
            PackageFileSourceInfo newItem = null;

            if (System.IO.File.Exists(filePath))
            {
                newItem = AddFile(parent, filePath);
            }
            else if(System.IO.Directory.Exists(filePath))
            {
                newItem = AddFolder(parent, filePath);
            }

            return newItem;
        }
Пример #15
0
        /// <summary>
        /// Creates an empty folder inside the PackageHeirarchyItem provided.
        /// </summary>
        /// <param name="pParent">Parent node of the new folder.</param>
        /// <param name="pFolderName">Name of the folder.</param>
        /// <returns></returns>
        private PackageHeirarchyItem CreateFolder(PackageHeirarchyItem pParent, string pFolderName)
        {
            PackageHeirarchyItem newFolder = new PackageHeirarchyItem("");
            newFolder.Name = pFolderName;
            newFolder.Parent = pParent;
            pParent.Children.Add(newFolder);

            return newFolder;
        }
Пример #16
0
 private PackageHeirarchyItem CreateRelativeFolders(PackageHeirarchyItem experimentFolder, PackageFileInfo file)
 {
     PackageHeirarchyItem lastFolder = experimentFolder;
     foreach (string folder in file.FoldersPath)
     {
         PackageHeirarchyItem folderInfo;
         if (ContainsFolder(lastFolder, folder, out folderInfo))
         {
             lastFolder = folderInfo;
         }
         else
         {
             lastFolder = CreateFolder(lastFolder, folder);
         }
     }
     return lastFolder;
 }
Пример #17
0
 public PackageSourceInfo()
 {
     Root = new PackageHeirarchyItem("");
     Name = DefaultName;
 }
Пример #18
0
        /// <summary>
        /// Sets the contents of the package from the given experiment, types and components.
        /// </summary>
        /// <param name="pInfo">Experiment info.</param>
        /// <param name="pTypes">Collection of type assembly files.</param>
        /// <param name="pComponents">Collection of component assembly files.</param>
        /// <returns></returns>
        public void GeneratePackageContent()
        {
            //firstly pack experiment
            ExperimentPackagingHelper ePkgHelper = new ExperimentPackagingHelper(this.ExperimentPackageConfig, m_supportedTypes);

            ExperimentPackagingResults pResults = ePkgHelper.PackExperiment(m_experiment);

            var info = new PackageSourceInfo();

            // Adding components
            if (pResults.ComponentAssemblies.Count > 0)
            {
                PackageHeirarchyItem componentsFolder = CreateFolder(info.Root, "Components");
                componentsFolder.HasComponents = true;
                foreach (string component in pResults.ComponentAssemblies)
                {
                    AddFile(componentsFolder, component);
                }
            }

            // Adding experiment
            PackageHeirarchyItem experimentFolder = CreateFolder(info.Root, "Experiment");

            AddFile(experimentFolder, pResults.Experiment.ExperimentInfo.FilePath);

            // HERZUM SPRINT 4.2: TLAB-215
            // info.Name = pResults.Experiment.ExperimentInfo.Name + " Package";
            info.Name = pResults.Experiment.ExperimentInfo.Name + "_package";
            // END HERZUM SPRINT 4.2: TLAB-215

            // Adding refered types into subfolder of Experiment
            if (pResults.Files.Count > 0)
            {
                foreach (PackageFileInfo file in pResults.Files)
                {
                    PackageHeirarchyItem lastFolder = CreateRelativeFolders(experimentFolder, file);
                    AddFile(lastFolder, file.AbsoluteLocation);
                }
            }

            //Adding refered directories into subfolder of Experiment
            if (pResults.Directories.Count > 0)
            {
                foreach (PackageFileInfo dir in pResults.Directories)
                {
                    PackageHeirarchyItem lastFolder = CreateRelativeFolders(experimentFolder, dir);
                    AddFolder(lastFolder, dir.AbsoluteLocation);
                }
            }

            // Adding types
            if (pResults.TypeAssemblies.Count > 0)
            {
                PackageHeirarchyItem typesFolder = CreateFolder(info.Root, "Types");
                typesFolder.HasTypes = true;
                foreach (string type in pResults.TypeAssemblies)
                {
                    AddFile(typesFolder, type);
                }
            }

            this.PackageSourceInfo = info;
        }
Пример #19
0
 public PackageSourceInfo()
 {
     Root = new PackageHeirarchyItem("");
     Name = DefaultName;
 }