/// <summary> /// /// Add a file to an IParallelEnv. /// Warnings: After calling this function, you should save the env to a file. /// /// </summary> /// <param name="env">To be added</param> /// <param name="filePath">The path for the file</param> /// <param name="settings">IParallelEnvsSettings</param> public static void AddFile(ref IParallelEnv env, string filePath, IParallelEnvsSettings settings) { // // If there were no file which is located at "filePath", it would be thrown an exception. // if (!File.Exists(filePath)) { throw new FileNotFoundException($"The file, {filePath} is not found."); } // // Generate a managed file path from GUID. // var file = new InternalParallelFile() as IParallelFile; file.OrdinaryFilePath = filePath; file.ManagedFilePath = Path.Combine(settings.ManagedDirectoryPath, Guid.NewGuid().ToString()); Directory.CreateDirectory(settings.ManagedDirectoryPath); // // Copy the file to the managed file path. // File.Copy(file.OrdinaryFilePath, file.ManagedFilePath); // // Add a file to the env. // env.Files.Add(file); }
/// <summary> /// /// Generate IParallelFile instances from the list of files. /// /// </summary> /// <param name="contents">The list of files</param> private IEnumerable <IParallelFile> ConvertToParallelFile(List <string> contents) { foreach (var content in contents) { var items = content.Split(CONTENTS_SEPARATOR); if (items.Length != 2) { throw new InvalidDataException(badFormatMessage); } var file = new InternalParallelFile(); file.OrdinaryFilePath = items[0]; file.ManagedFilePath = items[1]; yield return(file); } }