public void TestZip() { var temp = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/325/325859/325859_00.tiff"); var original = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/AB5/AB5678/AB5678_03.tiff"); Assert.True(File.Exists(original.FullName)); temp.cp(original); var zipFile = temp.Zip(); var t1 = DateTime.Now; Assert.True(File.Exists(zipFile.FullName)); var zipSize = new FileInfo(zipFile.FullName).Length; zipFile.rm(); temp.cp(original); var t2 = DateTime.Now; // var zip7 = temp.Zip7(); // var t3 = DateTime.Now; // Assert.True(zip7.Exists()); // var zip7Size = new FileInfo(zip7.FullName).Length; // zip7.rm(); temp.cp(original); var t4 = DateTime.Now; // var ultra = temp.ZipUltra(); // var t5 = DateTime.Now; // Assert.True(ultra.Exists()); // var ultraSize = new FileInfo(ultra.FullName).Length; // Debug.WriteLine("zip:/t/t" + (t1 - t0) + "/t" + zipSize); // Debug.WriteLine("7zip:/t" + (t3 - t2) + "/t" + zip7Size); // Debug.WriteLine("ultra:/t" + (t5 - t4) + "/t" + ultraSize); }
public void TestMoveToTree() { #region setup variables var testFileDir = new RaiFile("~/Foscam/test/raw_orig").FullName; var sourceDir = new RaiFile("~/Foscam/test/raw").FullName; var destDirRoot = testFileDir; foreach (var file in Directory.EnumerateFiles(testFileDir, "*.jpg")) { new RaiFile(file).CopyTo(new string[] { sourceDir }); } #endregion #region check preconditions Assert.True(Directory.EnumerateFiles(sourceDir).Count() > 0); int initialDirCount = Directory.EnumerateDirectories(testFileDir).Count(); int rawFileCount = Directory.EnumerateFiles(sourceDir).Count(); #endregion int count = ImageTreeFile.MoveToTree( fromDir: sourceDir, toDirRoot: destDirRoot, filter: "*.jpg", remove: "000DC5D78BAA(DLEXP)_0_"); #region check postconditions Assert.True(Directory.EnumerateFiles(sourceDir).Count() == 0); Assert.True(Directory.EnumerateDirectories(sourceDir).Count() == 0); Assert.True(Directory.EnumerateDirectories(testFileDir).Count() >= initialDirCount); #endregion #region clean up #endregion }
public void TestRaiFileEnsure() { // this test does not really challange the delay caused by massive parallel change operations in Dropbox var f0 = new RaiFile($"{TestDir}/Data/EnsureTests/kill.txt"); f0.mkdir(); var f = new TextFile($"{TestDir}/Data/EnsureTests/kill.txt"); for (int i = 0; i < 10000; i++) { f.Append("Test line " + i.ToString()); } f.Save(); var f2 = new RaiFile($"{TestDir}/Data/EnsureTests/kill2.txt"); var start = DateTimeOffset.UtcNow; var result1 = f2.cp(f); Assert.True(File.Exists(f2.FullName), "File is supposed to have materialized by now."); var cpDuration = DateTimeOffset.UtcNow - start; var f3 = new TmpFile(); var result2 = f3.mv(f2); Assert.True(File.Exists(f3.FullName), "File is supposed to have materialized by now."); Assert.False(File.Exists(f2.FullName), "File is supposed to have vanished by now."); Assert.Equal(0, result1 + result2); }
public TensorboardInfo(int port = 6006, string logDir = "~/HelloClass.Logs/") { Port = port; LogDir = logDir; Name = new RaiFile(LogDir.Length < 2 ? "" : LogDir.Substring(0, LogDir.Length - 1)).Name; Url = $"http://localhost:{Port}/"; }
/// <summary> /// constructor /// </summary> /// <param name="jo">port, logDir</param> public TensorboardInfo(JObject jo) { Port = (int)jo["port"]; LogDir = new RaiFile((string)jo["logDir"]).Path; Name = new RaiFile(LogDir.Length < 2 ? "" : LogDir.Substring(0, LogDir.Length - 1)).Name; Url = $"http://localhost:{Port}/"; }
public static Tensorboard Find(string search, bool refresh = true) { var name = new RaiFile(search).Name; if (refresh) { Refresh(); } var q = from _ in tensorboards where _.Key.Contains(name) || _.Value.Name.Contains(name) select _.Value; return(q.Count() > 0 ? new Tensorboard((TensorboardInfo)q.First()) : null); }
public int Convert(string options, string from, string to) { message = ""; int exitCode = 0; bool zip = to.EndsWith(".zip"); if (zip) { to = to.Substring(0, to.Length - 4); } callString = ImPath + ConvertCommand + " " + options + " " + Os.escapeParam(from) + " " + Os.escapeParam(to); call = new RaiSystem(callString); call.Exec(out message); exitCode = call.ExitCode; if (exitCode != 0 && message.Contains("Permission denied")) { try { FileInfo fiIntern = new FileInfo(Os.winInternal(from)); FileSecurity fsec = fiIntern.GetAccessControl(); IdentityReference currentIdentity = new NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent().Name); fsec.SetOwner(currentIdentity); FileSystemAccessRule permissions = new FileSystemAccessRule(currentIdentity, FileSystemRights.ReadAndExecute, AccessControlType.Allow); fsec.AddAccessRule(permissions); fiIntern.SetAccessControl(fsec); // try it again call.Exec(out message); exitCode = call.ExitCode; } catch (Exception) { } } if (zip) { var inFolder = new RaiFile(to); inFolder.Path = inFolder.Path + inFolder.Name; inFolder.mkdir(); inFolder.mv(new RaiFile(to)); File.Delete(inFolder.FullName + ".zip"); try { ZipFile.CreateFromDirectory(inFolder.Path, to + ".zip"); } catch (Exception) { } } return(exitCode); }
public void TestRaiFile1() { var temp = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/325/325859/325859_11.tiff"); var original = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/325/325859/325859_03.tiff"); Assert.True(File.Exists(original.FullName)); temp.rm(); Assert.False(File.Exists(temp.FullName)); temp.cp(original); Assert.True(File.Exists(temp.FullName)); var dest = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/325/325859/325859_01.tiff"); dest.rm(); dest.mv(temp); Assert.True(File.Exists(dest.FullName)); Assert.False(File.Exists(temp.FullName)); }
/// <summary> /// MoveToTree moves files in fromDir to a directory structure created in toDirRoot /// using the file's name as names for the folders in the directory structure /// </summary> /// <param name="fromDir">original directory</param> /// <param name="toDirRoot">root of the new directory structure </param> /// <param name="filter"></param> /// <param name="remove"></param> /// <returns></returns> public static int MoveToTree(string fromDir, string toDirRoot, string filter = "*.jpg", string remove = "") { ImageTreeFile dest; RaiFile source; int count = 0; foreach (var file in Directory.EnumerateFiles(new RaiFile(fromDir).FullName, filter)) { dest = new ImageTreeFile(file.Replace(remove, "")); dest.Path = new RaiFile(toDirRoot).FullName; source = new RaiFile(file); dest.mv(source); Console.WriteLine($"{source.FullName} moved to {dest.FullName}"); count++; } return(count); }
public static string EasyFileName(string pic, bool renameFile = false) { while (pic.EndsWith("_")) { pic = pic.Substring(0, pic.Length - 1); if (pic.Length == 0) { pic = "0"; } } var imgFile = new ImageFile(pic); //file.FullName); if (imgFile.ImageNumber == ImageFile.NoImageNumber) { imgFile.ImageNumber = 1; } if (string.IsNullOrEmpty(imgFile.Ext)) { imgFile.Ext = "jpg"; } if (imgFile.Sku.Length < 4) { if (imgFile.Sku.ToLower() == "img") { if (imgFile.ImageNumber > 100000) { imgFile.Sku = (imgFile.ImageNumber / 100000).ToString(); imgFile.ImageNumber = imgFile.ImageNumber % 100000; } else if (imgFile.ImageNumber > 10) { imgFile.Sku += (imgFile.ImageNumber / 10).ToString(); imgFile.ImageNumber = imgFile.ImageNumber % 10; } else { imgFile.Sku = nameof(Image); // "Image"; } } else if (string.IsNullOrWhiteSpace(imgFile.Sku)) { imgFile.Sku = "0"; } if (System.Text.RegularExpressions.Regex.IsMatch(imgFile.Sku, "^[0-9]+$")) // numerical only => extend in the front { while (imgFile.Sku.Length < 4) { imgFile.Sku = "0" + imgFile.Sku; } } else { // extend in the back while (imgFile.Sku.Length < 4) { imgFile.Sku += "0"; } } } if (renameFile) { var from = new RaiFile(pic); if (from.FullName != imgFile.FullName) { imgFile.mv(from); } } return(imgFile.FullName); // file.FullName; }