public void Connect_NavigateRootDir() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem("S3-1")) { using(var session = fs.StartSession(CONN_PARAMS)) { var dir = session[S3_ROOT_FS] as FileSystemDirectory; Assert.AreEqual("/", dir.ParentPath); Assert.AreEqual(S3_ROOT_FS, dir.Path); } } } }
public static void Connect_NavigateRootDir() { using(var fs = new S3V4FileSystem("S3-1")) { var session = fs.StartSession(CONN_PARAMS); var dir = session[DXW_ROOT] as FileSystemDirectory; //Assert.AreEqual(@"c:\", dir.ParentPath); //Assert.AreEqual(@"c:\NFX", dir.Path); } }
public static void ListBucket() { using(var fs = new S3V4FileSystem("S3-1")) { var session = fs.StartSession(CONN_PARAMS); FileSystemDirectory dir = session[DXW_ROOT] as FileSystemDirectory; Console.WriteLine("************* FOLDERS **********************"); foreach(string subdir in dir.SubDirectoryNames) { Console.WriteLine(subdir); } Console.WriteLine("************* FILES **********************"); foreach(string file in dir.FileNames) { Console.WriteLine(file); } } }
public void Parallel_CreateWriteReadFile() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { System.Threading.Tasks.Parallel.For(PARALLEL_FROM, PARALLEL_TO, (i) => { var fn = FN_PARALLEL_MASK.Args(i); var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; using (var file = dir.CreateFile(fn)) { file.WriteAllText("Hello, {0}".Args(i)); } using (var file = session[fs.CombinePaths(S3_ROOT_FS, fn)] as FileSystemFile) { Assert.AreEqual("Hello, {0}".Args(i), file.ReadAllText()); file.Delete(); } Assert.IsNull(session[fs.CombinePaths(S3_ROOT_FS, fn)]); });//Parallel.For } } }
private void cleanUp() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { deleteFile(FN2_FS_FULLPATH); using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; if (dir != null) dir.Delete(); } } }
public void CreateWriteReadFile_1() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; using (var file = dir.CreateFile(FN2_FS)) { var str = file.FileStream; var wri = new BinaryWriter(str); wri.Write("Hello!"); wri.Write(true); wri.Write(27.4d); wri.Close(); } using (var file = session[fs.CombinePaths(S3_ROOT_FS, FN2_FS)] as FileSystemFile) { var str = file.FileStream; var rdr = new BinaryReader(str); Assert.AreEqual("Hello!", rdr.ReadString()); Assert.AreEqual(true, rdr.ReadBoolean()); Assert.AreEqual(27.4d, rdr.ReadDouble()); } } } }
public void CreateWriteReadFile_3() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; using (var file = dir.CreateFile(FN4_FS)) { file.WriteAllText("Hello,"); file.WriteAllText("this will overwrite"); } using (var file = session[fs.CombinePaths(S3_ROOT_FS, FN4_FS)] as FileSystemFile) { Assert.AreEqual("this will overwrite", file.ReadAllText()); } } } }
public void CreateWriteCopyReadFile() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; using (Stream s = new FileStream(FN2_FS_FULLPATH, FileMode.Create, FileAccess.Write)) { var wri = new BinaryWriter(s); wri.Write("Hello!"); wri.Write(true); wri.Write(27.4d); wri.Close(); } //FN3 copied from FN2 and made readonly Assert.IsNotNull(dir.CreateFile(FN3_FS, Path.Combine(LOCAL_ROOT_FS, FN2_FS), true)); using (var file = session[fs.CombinePaths(S3_ROOT_FS, FN3_FS)] as FileSystemFile) { var str = file.FileStream; var rdr = new BinaryReader(str); Assert.AreEqual("Hello!", rdr.ReadString()); Assert.AreEqual(true, rdr.ReadBoolean()); Assert.AreEqual(27.4d, rdr.ReadDouble()); } } } }
public void CreateFile() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; var file = dir.CreateFile(FN1_FS, 1500); Assert.AreEqual(FN1_FS, file.Name); Assert.IsTrue(S3V4.FileExists(file.Path, S3_ACCESSKEY, S3_SECRETKEY, S3_BUCKET, S3_REGION, 0)); Assert.AreEqual(1500, S3V4.GetItemMetadata(file.Path, S3_ACCESSKEY, S3_SECRETKEY, S3_BUCKET, S3_REGION, 0)["Content-Length"].AsLong()); Assert.AreEqual(1500, file.FileStream.Length); } } }
public void CreateDirCreateFileDeleteDir() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; Assert.AreEqual(1, session.Items.Count());//checking item registation via .ctor/.dctor var dir2 = dir[DIR_1] as FileSystemDirectory; Assert.IsNull(dir2); Assert.AreEqual(1, session.Items.Count());//checking item registation via .ctor/.dctor dir2 = dir.CreateDirectory(DIR_1); Assert.AreEqual(2, session.Items.Count());//checking item registation via .ctor/.dctor Assert.IsTrue(folderExists(dir2)); Assert.AreEqual(DIR_1, dir2.Name); var f = dir2.CreateFile(S3_FN1, 237); Assert.AreEqual(3, session.Items.Count());//checking item registation via .ctor/.dctor Assert.IsTrue(fileExists(f)); Assert.AreEqual(237, dir2.Size); Assert.IsTrue(dir.SubDirectoryNames.Contains(DIR_1)); Assert.IsTrue(dir2.FileNames.Contains(S3_FN1)); dir2.Delete(); Assert.AreEqual(2, session.Items.Count());//checking item registation via .ctor/.dctor Assert.IsFalse(folderExists(dir2)); Assert.IsFalse(fileExists(f)); Assert.AreEqual(1, fs.Sessions.Count());//checking item registation via .ctor/.dctor session.Dispose(); Assert.AreEqual(0, fs.Sessions.Count());//checking item registation via .ctor/.dctor Assert.AreEqual(0, session.Items.Count());//checking item registation via .ctor/.dctor } } }
public void CreateDeleteFile() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; var file = dir.CreateFile(S3_FN1, 1500); Assert.AreEqual(S3_FN1, file.Name); IDictionary<string, string> headersFN1 = S3V4.GetItemMetadata(file.Path, S3_ACCESSKEY, S3_SECRETKEY, S3_BUCKET, S3_REGION, 0); Assert.AreEqual(1500, headersFN1["Content-Length"].AsInt()); Assert.AreEqual(1500, file.FileStream.Length); Assert.AreEqual(1500, file.Size); var file2 = session[fs.CombinePaths(S3_ROOT_FS, S3_FN1)]; Assert.IsNotNull(file2); Assert.IsTrue(file2 is FileSystemFile); Assert.AreEqual(S3_FN1, ((FileSystemFile)file2).Name); file.Dispose(); file2.Delete(); Assert.IsFalse(fileExists((FileSystemFile)file2)); } } }
public void CreateDeleteDir() { using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig())) { using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3))) { var session = fs.StartSession(); var dir = session[S3_ROOT_FS] as FileSystemDirectory; var dir2 = dir[DIR_1] as FileSystemDirectory; Assert.IsNull(dir2); dir2 = dir.CreateDirectory(DIR_1); Assert.AreEqual(DIR_1, ((FileSystemDirectory)dir[DIR_1]).Name); Assert.AreEqual(DIR_1, ((FileSystemDirectory)dir2[""]).Name); Assert.IsTrue(folderExists(dir2)); Assert.AreEqual(DIR_1, dir2.Name); dir2.Delete(); Assert.IsFalse(folderExists(dir2)); } } }