public void CheckSortNatural() { var result = new List <string>(); FilePathUtility.Sort(source_paths, result); var sb = new StringBuilder(); sb.Append("sorted path = [\n"); foreach (var path in result) { sb.Append($" {path}\n"); } sb.Append("]\n"); Debug.Log(sb); Assert.IsTrue(CheckEquals(result, new string[] { "02file_4_sample_00.dat", "02file_10_sample_00.dat", "data777_pattern2.csv", "data00777_pattern2.csv", "data777_pattern2.csv2", "data777_pattern2.csvext", "file_008_sample_2.dat", "file_8_sample_011.dat", "file_012_sample_11.dat", "file_44_sample_11.dat" })); }
public override void MoveFile(string fileName, string sourcePath, string destinationPath) { if (sourcePath == destinationPath) { throw new ArgumentException("Source and Destination path cannot be the same."); } if (!FileExists(fileName, sourcePath)) { throw new InvalidOperationException("File: " + fileName + ", does not exist."); } if (FileInUse(fileName, sourcePath)) { throw new AccessViolationException("File: " + fileName + ", is in use."); } var sourceFullPath = FilePathUtility.SetFullFilePath(fileName, sourcePath); var destinationFullPath = FilePathUtility.SetFullFilePath(fileName, destinationPath); if (!DirectoryExists(destinationPath)) { CreateDirectory(destinationPath); } if (FileExists(fileName, destinationPath)) { DeleteFile(fileName, destinationPath); } m_container.MoveFile(sourceFullPath, destinationFullPath); }
public void GetAbsolutePath_HttpRelative() { string path; var basePathList = new string[] { "http://example.com", "http://example.com/", "http://example.com/index.html", }; foreach (var basePath in basePathList) { path = FilePathUtility.GetAbsolutePath("./path", basePath); Assert.AreEqual($"{httpUrl}/path", path); } basePathList = new string[] { "http://example.com/sub/", "http://example.com/sub/index.html", }; foreach (var basePath in basePathList) { path = FilePathUtility.GetAbsolutePath("./path", basePath); Assert.AreEqual($"{httpUrl}/sub/path", path); } }
public override bool FileInUse(string fileName, string path = "") { IsolatedStorageFileStream stream = null; var fullPath = FilePathUtility.SetFullFilePath(fileName, path); if (FileExists(fileName, path)) { try { stream = m_container.OpenFile(fullPath, FileMode.Open); } catch (IOException) { //the file is unavailable because it is: //still being written to //or being processed by another thread //or does not exist (has already been processed) return(true); } finally { if (stream != null) { stream.Close(); } } } return(false); }
public DataEntityStorageImpl() { this.entityDirPath = FilePathUtility.GetFullPath(entityDir); //this.entityDirPath = Path.Combine(Global.DriveLetter, entityDir); this.entityMetadataFilepath = Path.Combine(this.entityDirPath, filename); }
public override void MoveDirectory(string directoryName, string sourcePath, string destinationPath) { if (sourcePath == destinationPath) { throw new ArgumentException("Source and Destination path cannot be the same."); } if (!DirectoryExists(directoryName, sourcePath)) { throw new InvalidOperationException("Directory: " + directoryName + ", does not exist."); } var sourceFullPath = FilePathUtility.SetFullFilePath(directoryName, sourcePath); var destinationFullPath = FilePathUtility.SetFullFilePath(directoryName, destinationPath); if (!DirectoryExists(destinationPath)) { CreateDirectory(destinationPath); } if (DirectoryExists(directoryName, destinationPath)) { DeleteDirectory(directoryName, destinationPath); } m_container.MoveDirectory(sourceFullPath, destinationFullPath); }
public override void CreateDirectory(string directoryName, string path = "") { var fullPath = FilePathUtility.SetFullFilePath(directoryName, path); if (!DirectoryExists(directoryName, path)) { m_container.CreateDirectory(fullPath); } }
public override Stream CreateFileStream(string fileName, string path = "") { var fullPath = FilePathUtility.SetFullFilePath(fileName, path); var stream = m_container.CreateFile(fullPath); m_streams.Add(stream); return(stream); }
public override Stream OpenFile(string fileName, string path = "") { var fullPath = FilePathUtility.SetFullFilePath(fileName, path); var stream = m_container.OpenFile(fullPath, FileMode.OpenOrCreate); m_streams.Add(stream); return(stream); }
public bool LoadModelImage() { string filePath = this.ModelImagePath; if (!File.Exists(filePath)) { filePath = Path.Combine(FilePathUtility.GetAssemblyPath(), filePath); } return(this.LoadImage(filePath)); }
public override DirectoryInfo GetDirectory(string directoryName, string path = "") { DirectoryInfo dir = null; var fullPath = FilePathUtility.SetFullFilePath(directoryName, path); if (m_container.DirectoryExists(fullPath)) { dir = new DirectoryInfo(fullPath); } return(dir); }
private static void EnsurePreHostRunning() { Process[] p = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(preHostPath)); if (p.Length == 0) { Logger.LogInfo("Pre 32bit process was not found. Starting it..."); ProcessStartInfo psi = new ProcessStartInfo(FilePathUtility.GetFullPath(preHostPath)); Process dllHost = Process.Start(psi); Thread.Sleep(5000); // give process time to start } }
public override void DeleteDirectory(string directoryName, string path = "") { var fullPath = FilePathUtility.SetFullFilePath(directoryName, path); var files = m_container.GetFileNames(directoryName); if (files.Any(fileName => FileInUse(fileName, fullPath))) { throw new AccessViolationException("Directory: " + directoryName + ", is in use."); } m_container.DeleteDirectory(fullPath); }
public override FileInfo GetFile(string fileName, string path = "") { FileInfo file = null; var fullPath = FilePathUtility.SetFullFilePath(fileName, path); if (m_container.FileExists(fullPath)) { file = new FileInfo(fullPath); } return(file); }
public override void DeleteFile(string fileName, string path = "") { var fullPath = FilePathUtility.SetFullFilePath(fileName, path); if (!FileInUse(fileName, path)) { m_container.DeleteFile(fullPath); } else { throw new AccessViolationException("File: " + fileName + ", is in use."); } }
public void GetAbsolutePath_FileRelative() { string path; var basePath = @"C:\foo\bar\foobar.xml"; path = FilePathUtility.GetAbsolutePath("path", basePath); Assert.AreEqual(@"C:\foo\bar\path", path); path = FilePathUtility.GetAbsolutePath("C:\\path", basePath); Assert.AreEqual(@"C:\path", path); path = FilePathUtility.GetAbsolutePath("./path", basePath); Assert.AreEqual(@"C:\foo\bar\path", path); }
public override void CreateFile(string fileName, string path = "") { IsolatedStorageFileStream stream = null; var fullPath = FilePathUtility.SetFullFilePath(fileName, path); try { stream = m_container.CreateFile(fullPath); } finally { if (stream != null) { stream.Close(); stream.Dispose(); } } }
private void CheckSortWithFilter(string filter, string[] reference) { var result = new List <string>(); FilePathUtility.Sort(source_paths, filter, result); var sb = new StringBuilder(); sb.Append($"filter = {filter}\n"); sb.Append("sorted path = [\n"); foreach (var path in result) { sb.Append($" {path}\n"); } sb.Append("]\n"); Debug.Log(sb); Assert.IsTrue(CheckEquals(result, reference)); }
public override void CopyFile(string fileName, string sourcePath, string destinationPath, bool overwrite = false) { if (!FileExists(fileName, sourcePath)) { throw new InvalidOperationException("File: " + fileName + ", does not exist."); } if (FileInUse(fileName, sourcePath)) { throw new AccessViolationException("File: " + fileName + ", is in use."); } var sourceFullPath = FilePathUtility.SetFullFilePath(fileName, sourcePath); var destinationFullPath = FilePathUtility.SetFullFilePath(fileName, destinationPath); if (!DirectoryExists(destinationPath)) { CreateDirectory(destinationPath); } m_container.CopyFile(sourceFullPath, destinationFullPath, overwrite); }
public UserMetadataStorageImpl() { this.path = FilePathUtility.GetFullPath(filename); //this.path = Path.Combine(Global.DriveLetter, filename); }
public override bool FileExists(string fileName, string path = "") { var fullPath = FilePathUtility.SetFullFilePath(fileName, path); return(m_container.FileExists(fullPath)); }
public Storage() { this.entityDirPath = FilePathUtility.GetFullPath(entityDir); this.metadataFilepath = Path.Combine(this.entityDirPath, filename); }
public override bool DirectoryExists(string directoryName, string path = "") { var fullPath = FilePathUtility.SetFullFilePath(directoryName, path); return(m_container.DirectoryExists(fullPath)); }