/// <summary> /// Sets the experiment location root, which all relative paths should be relative to. /// </summary> /// <param name="experimentLocationRoot">The experiment location root.</param> public void SetExperimentLocationRoot(string experimentLocationRoot, bool transformRelative) { TraceLabSDK.Component.Config.BasePath filePath = Value as TraceLabSDK.Component.Config.BasePath; TraceLabSDK.Component.Config.DirectoryPath dirPath = Value as TraceLabSDK.Component.Config.DirectoryPath; if (filePath != null) { filePath.SetDataRoot(experimentLocationRoot, transformRelative); } else if (dirPath != null) { dirPath.SetDataRoot(experimentLocationRoot, transformRelative); } }
public void SetExperimentLocationRoot(string experimentLocationRoot, string dataRoot, bool transformRelative) { TraceLabSDK.Component.Config.FilePath filePath = Value as TraceLabSDK.Component.Config.FilePath; TraceLabSDK.Component.Config.DirectoryPath dirPath = Value as TraceLabSDK.Component.Config.DirectoryPath; if (filePath != null) { if (filePath.relativeToDataRoot == true) { //transform Relative path to be relative to experiment location, and not to dataroot filePath.SetDataRoot(dataRoot, true); //set it first to data root (old relation) filePath.SetDataRoot(experimentLocationRoot, true); //and reset to new data root - it will transform relative path so that it is related to new location filePath.relativeToDataRoot = false; } else { filePath.SetDataRoot(experimentLocationRoot, transformRelative); } } else if (dirPath != null) { dirPath.SetDataRoot(experimentLocationRoot, transformRelative); } }
/// <summary> /// Extracts the components/types assemblies from the given vertex. /// </summary> /// <param name="pVertex">Vertex from the experiment graph.</param> private void ExtractFilesFromNode(ExperimentNode pVertex) { if (pVertex is ComponentNode) // Regular component { ComponentMetadata metaData = (ComponentMetadata)pVertex.Data.Metadata; if (metaData != null) { ComponentMetadataDefinition metaDataDef = metaData.ComponentMetadataDefinition; if (metaDataDef != null) { bool include; if (m_config.IncludeOtherPackagesAssemblies) { include = true; } else { //determine if component is independent or is coming from another package include = !IsAssemblyInAnotherPackage(metaDataDef.Assembly); } if (include) { // Component assembly this.m_componentAssemblies.Add(Path.GetFullPath(metaDataDef.Assembly)); // Extracting types from IOSpec ExtractTypesFromIOSpec(metaDataDef.IOSpecDefinition); } } ConfigWrapper config = metaData.ConfigWrapper; if (config != null) { // Extracting paths for files/directories from components' configuration foreach (ConfigPropertyObject configValue in config.ConfigValues.Values) { // Files if (configValue.Type == "TraceLabSDK.Component.Config.FilePath" && configValue.Value != null) { // Independent files if (configValue.Value is TraceLab.Core.Components.TraceLabFilePath == false) { if (this.m_config.IncludeIndependentFilesDirs) { var filePath = (TraceLabSDK.Component.Config.FilePath)configValue.Value; if (File.Exists(filePath.Absolute)) { PackageFileInfo packageFileInfo = new PackageFileInfo(filePath); m_files.Add(packageFileInfo); //Change config value relative path -> this path is saved within experiment (note, we operate on the experiment clone) //so that relative path is in the subfolder of Experiment folder filePath.Relative = packageFileInfo.RelativeLocation; } } } // Files contained in a package else { if (this.m_config.IncludeOtherPackagesFilesDirs) { //TraceLabFilePath represents the file reference located in the package var packageFilePath = (TraceLabFilePath)configValue.Value; if (File.Exists(packageFilePath.Absolute)) { PackageFileInfo packageFileInfo = new PackageFileInfo(packageFilePath); m_files.Add(packageFileInfo); //change the configValue to basic FilePath, (not TraceLabFilePath in the package), with updated Relative Path //so that relative path is in the subfolder of Experiment folder TraceLabSDK.Component.Config.FilePath basicFilePath = new TraceLabSDK.Component.Config.FilePath(); basicFilePath.Init(packageFilePath.Absolute, packageFilePath.DataRoot); basicFilePath.Relative = packageFileInfo.RelativeLocation; configValue.Value = basicFilePath; } } } } // Directories else if (configValue.Type == "TraceLabSDK.Component.Config.DirectoryPath" && configValue.Value != null) { // Independent directories if (configValue.Value is TraceLab.Core.Components.TraceLabDirectoryPath == false) { if (this.m_config.IncludeIndependentFilesDirs) { var dirPath = (TraceLabSDK.Component.Config.DirectoryPath)configValue.Value; if (Directory.Exists(dirPath.Absolute)) { PackageFileInfo packageDirectoryInfo = new PackageFileInfo(dirPath); m_directories.Add(packageDirectoryInfo); // HERZUM SPRINT 3.0: TLAB-82 if (dirPath.Relative!=null) // END HERZUM SPRINT 3.0: TLAB-82 //Change config value relative path -> this path is saved within experiment (note, we operate on the experiment clone) //so that relative path is in the subfolder of Experiment folder dirPath.Relative = packageDirectoryInfo.RelativeLocation; } } } // Directories contained in a package else { if (this.m_config.IncludeOtherPackagesFilesDirs) { var packageDirPath = (TraceLabDirectoryPath)configValue.Value; if (Directory.Exists(packageDirPath.Absolute)) { PackageFileInfo packageDirInfo = new PackageFileInfo(packageDirPath); m_directories.Add(packageDirInfo); //change the configValue to basic FilePath, (not TraceLabFilePath in the package), with updated Relative Path //so that relative path is in the subfolder of Experiment folder TraceLabSDK.Component.Config.DirectoryPath basicFilePath = new TraceLabSDK.Component.Config.DirectoryPath(); basicFilePath.Init(packageDirPath.Absolute, packageDirPath.DataRoot); basicFilePath.Relative = packageDirInfo.RelativeLocation; configValue.Value = basicFilePath; } } } } } } } } else if (pVertex is CompositeComponentNode) // Composite Components, Loops & Scopes { CompositeComponentBaseMetadata metaData = (CompositeComponentBaseMetadata)pVertex.Data.Metadata; if (metaData != null) { foreach (var vertex in metaData.ComponentGraph.Vertices) { ExtractFilesFromNode(vertex); } // Only composite components have MetadataDefinition if (pVertex.Data.Metadata is CompositeComponentMetadata) { CompositeComponentMetadataDefinition metaDataDefinition = ((CompositeComponentMetadata)pVertex.Data.Metadata).ComponentMetadataDefinition; this.m_componentAssemblies.Add(Path.GetFullPath(metaDataDefinition.Assembly)); // Extracting types from IOSpec ExtractTypesFromIOSpec(metaDataDefinition.IOSpecDefinition); } } } }
/// <summary> /// Extracts the components/types assemblies from the given vertex. /// </summary> /// <param name="pVertex">Vertex from the experiment graph.</param> private void ExtractFilesFromNode(ExperimentNode pVertex) { if (pVertex is ComponentNode) // Regular component { ComponentMetadata metaData = (ComponentMetadata)pVertex.Data.Metadata; if (metaData != null) { ComponentMetadataDefinition metaDataDef = metaData.ComponentMetadataDefinition; if (metaDataDef != null) { bool include; if (m_config.IncludeOtherPackagesAssemblies) { include = true; } else { //determine if component is independent or is coming from another package include = !IsAssemblyInAnotherPackage(metaDataDef.Assembly); } if (include) { // Component assembly this.m_componentAssemblies.Add(Path.GetFullPath(metaDataDef.Assembly)); // Extracting types from IOSpec ExtractTypesFromIOSpec(metaDataDef.IOSpecDefinition); } } ConfigWrapper config = metaData.ConfigWrapper; if (config != null) { // Extracting paths for files/directories from components' configuration foreach (ConfigPropertyObject configValue in config.ConfigValues.Values) { // Files if (configValue.Type == "TraceLabSDK.Component.Config.FilePath" && configValue.Value != null) { // Independent files if (configValue.Value is TraceLab.Core.Components.TraceLabFilePath == false) { if (this.m_config.IncludeIndependentFilesDirs) { var filePath = (TraceLabSDK.Component.Config.FilePath)configValue.Value; if (File.Exists(filePath.Absolute)) { PackageFileInfo packageFileInfo = new PackageFileInfo(filePath); m_files.Add(packageFileInfo); //Change config value relative path -> this path is saved within experiment (note, we operate on the experiment clone) //so that relative path is in the subfolder of Experiment folder filePath.Relative = packageFileInfo.RelativeLocation; } } } // Files contained in a package else { if (this.m_config.IncludeOtherPackagesFilesDirs) { //TraceLabFilePath represents the file reference located in the package var packageFilePath = (TraceLabFilePath)configValue.Value; if (File.Exists(packageFilePath.Absolute)) { PackageFileInfo packageFileInfo = new PackageFileInfo(packageFilePath); m_files.Add(packageFileInfo); //change the configValue to basic FilePath, (not TraceLabFilePath in the package), with updated Relative Path //so that relative path is in the subfolder of Experiment folder TraceLabSDK.Component.Config.FilePath basicFilePath = new TraceLabSDK.Component.Config.FilePath(); basicFilePath.Init(packageFilePath.Absolute, packageFilePath.DataRoot); basicFilePath.Relative = packageFileInfo.RelativeLocation; configValue.Value = basicFilePath; } } } } // Directories else if (configValue.Type == "TraceLabSDK.Component.Config.DirectoryPath" && configValue.Value != null) { // Independent directories if (configValue.Value is TraceLab.Core.Components.TraceLabDirectoryPath == false) { if (this.m_config.IncludeIndependentFilesDirs) { var dirPath = (TraceLabSDK.Component.Config.DirectoryPath)configValue.Value; if (Directory.Exists(dirPath.Absolute)) { PackageFileInfo packageDirectoryInfo = new PackageFileInfo(dirPath); m_directories.Add(packageDirectoryInfo); //Change config value relative path -> this path is saved within experiment (note, we operate on the experiment clone) //so that relative path is in the subfolder of Experiment folder dirPath.Relative = packageDirectoryInfo.RelativeLocation; } } } // Directories contained in a package else { if (this.m_config.IncludeOtherPackagesFilesDirs) { var packageDirPath = (TraceLabDirectoryPath)configValue.Value; if (Directory.Exists(packageDirPath.Absolute)) { PackageFileInfo packageDirInfo = new PackageFileInfo(packageDirPath); m_directories.Add(packageDirInfo); //change the configValue to basic FilePath, (not TraceLabFilePath in the package), with updated Relative Path //so that relative path is in the subfolder of Experiment folder TraceLabSDK.Component.Config.DirectoryPath basicFilePath = new TraceLabSDK.Component.Config.DirectoryPath(); basicFilePath.Init(packageDirPath.Absolute, packageDirPath.DataRoot); basicFilePath.Relative = packageDirInfo.RelativeLocation; configValue.Value = basicFilePath; } } } } } } } } else if (pVertex is CompositeComponentNode) // Composite Components, Loops & Scopes { CompositeComponentBaseMetadata metaData = (CompositeComponentBaseMetadata)pVertex.Data.Metadata; if (metaData != null) { foreach (var vertex in metaData.ComponentGraph.Vertices) { ExtractFilesFromNode(vertex); } // Only composite components have MetadataDefinition if (pVertex.Data.Metadata is CompositeComponentMetadata) { CompositeComponentMetadataDefinition metaDataDefinition = ((CompositeComponentMetadata)pVertex.Data.Metadata).ComponentMetadataDefinition; this.m_componentAssemblies.Add(Path.GetFullPath(metaDataDefinition.Assembly)); // Extracting types from IOSpec ExtractTypesFromIOSpec(metaDataDefinition.IOSpecDefinition); } } } }
/// <summary> /// Copies the referenced files by FilePath configs. /// Also it creates referenced directories, but don't copy files in the directories. /// Note, that method will update FilePaths and DirectoryPaths of config values. /// Relative properties won't change. /// Absolue properties will be updated to new location. /// Dataroot will be updated to new location. /// </summary> /// <param name="newExperimentLocation">The new experiment location.</param> /// <param name="oldExperimentLocation">The old experiment location.</param> /// <param name="overwrite">if set to <c>true</c> [overwrite] the method will attempt to overwrite files. If not successful it will report failure of copying, but will continue to copy rest of files.</param> /// <exception cref="TraceLab.Core.Exceptions.FilesCopyFailuresException">Throws exception if there were any errors during copying process. The exception contains all reported errors during copy process.</exception> internal void CopyReferencedFiles(string newExperimentLocation, string oldExperimentLocation, bool overwrite) { List <string> copyErrors = new List <string>(); foreach (KeyValuePair <string, ConfigPropertyObject> pair in m_configValues) { ConfigPropertyObject configObj = pair.Value; pair.Value.SetExperimentLocationRoot(newExperimentLocation, false); //change file path root and absolute path, but don't transform relative paths TraceLabSDK.Component.Config.FilePath filePath = configObj.Value as TraceLabSDK.Component.Config.FilePath; TraceLabSDK.Component.Config.DirectoryPath dirPath = configObj.Value as TraceLabSDK.Component.Config.DirectoryPath; if (filePath != null) { //if new directories do not exists create them if (System.IO.Directory.Exists(oldExperimentLocation) == false) { System.IO.Directory.CreateDirectory(oldExperimentLocation); } //old absolute path to the referenced file string oldAbsolute = System.IO.Path.GetFullPath(System.IO.Path.Combine(oldExperimentLocation, filePath.Relative)); //copy from old location to new location try { if (System.IO.File.Exists(filePath.Absolute)) { //don't copy file if overwrite is false and file at new location already exists if (overwrite) { System.IO.File.Copy(oldAbsolute, filePath.Absolute, overwrite); } } else { //if file at new location does not exists always copy System.IO.File.Copy(oldAbsolute, filePath.Absolute, overwrite); } } catch (System.UnauthorizedAccessException ex) { //if the file at the new location already existed and was readonly var message = string.Format("Unable to copy file '{0}' to the new location. {1}", oldAbsolute, ex.Message); copyErrors.Add(message); } catch (System.IO.IOException ex) { //for example if original file was locked (used by another process) var message = string.Format("Unable to copy file '{0}' to the new location. {1}", oldAbsolute, ex.Message); copyErrors.Add(message); } } else if (dirPath != null) { //if new directories do not exists create them if (System.IO.Directory.Exists(dirPath) == false) { System.IO.Directory.CreateDirectory(dirPath); } } } if (copyErrors.Count > 0) { throw new TraceLab.Core.Exceptions.FilesCopyFailuresException(Messages.FailedToCopyFiles, copyErrors); } }