public void ToStringTest() { var pathItem = PathSplitter.SplitPath(ExpectedPath); var pathItemStr = pathItem.ToString(); Assert.AreEqual(ExpectedPath, pathItemStr); }
public void SplitAPathIntoNamesListNoNames() { var pathSplitter = new PathSplitter(); var result = pathSplitter.SplitPath("/"); Assert.Equal(new string[0], result); }
public void SplitAPathIntoNamesListTwoNames() { var pathSplitter = new PathSplitter(); var result = pathSplitter.SplitPath("/cam/jordan"); Assert.Equal(new string[] { "cam", "jordan" }, result); }
public void SplitAPathIntoNamesListOneName() { var pathSplitter = new PathSplitter(); var result = pathSplitter.SplitPath("/cam"); Assert.Equal(new string[] { "cam" }, result); }
public void ToArrayTest() { var pathItem = PathSplitter.SplitPath(ExpectedPath); var expectedArray = new string[] { "root", "dir", "subdir" }; var actArray = pathItem.ToArray(); CollectionAssert.AreEqual(expectedArray, actArray); }
public void GetPathItemFromTest1() { var pathItem = PathSplitter.SplitPath(ExpectedPath); var act = pathItem.GetPathItemFrom("root"); var expectedPathItem = PathSplitter.SplitPath("/dir/subdir"); Assert.AreEqual(expectedPathItem, act); }
public void GetLastTest() { var pathItem = PathSplitter.SplitPath(ExpectedPath); var expected = "subdir"; var act = pathItem.GetLast(); Assert.AreEqual(expected, act); }
public void PopTest() { var pathItem = PathSplitter.SplitPath(ExpectedPath); string act = pathItem.Pop(); var expected = "subdir"; Assert.AreEqual(expected, act); }
public static (PathItem parent, string fileName) GetFilenameAndParent(this string fullPath) { var pathItem = PathSplitter.SplitPath(fullPath); var fileName = pathItem.GetLast(); var parent = new PathItem(pathItem.ToArray(1)); return(parent, fileName); }
public void CreateFile(string fileName, string parent, string inFilePath) { if (!File.Exists(inFilePath)) { return; } var pId = GetDirectoryId(PathSplitter.SplitPath(parent)); if (jsonStructureManager.ExistedFile(pId, fileName)) { return; } var mimeType = MimeType.MimeTypeMap.GetMimeType(inFilePath); using (var stream = new FileStream(inFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { string hash = string.Empty; if (jsonStructureManager.IsCheckHash) { hash = Crypto.Sha256.GetSha256(stream); } if (stream.Length > fManager.SplitSize) { var(nextId, parentId) = ResolveTermParameters(fileName, parent); var start = fManager.Write(stream, (writeStream) => { while (true) { byte[] bs = new byte[fManager.SplitSize]; int readSize = stream.Read(bs, 0, bs.Length); if (readSize == 0) { break; } writeStream.Write(bs, 0, readSize); } }, LEN); jsonStructureManager.CreateFile(nextId, parentId, fileName, start, hash, new Dictionary <string, string> { { "MimeType", mimeType } }); } else { var data = ByteLoader.FromFile(stream); if (data != null) { CreateFile(fileName, parent, data, mimeType, hash); } } } }
public void WriteToDir(string filePath, string outFilePath) { var(parent, fileName) = filePath.GetFilenameAndParent(); int rootId = GetDirectoryId(parent); if (jsonStructureManager.ExistedDirectory(rootId, fileName)) { var dirId = GetDirectoryId(PathSplitter.SplitPath(filePath)); var dirs = jsonStructureManager.GetDirectoryAllStructuresFromParent(dirId); var files = jsonStructureManager.GetFileAllStructuresFromParent(dirId); if (!Directory.Exists(outFilePath)) { Directory.CreateDirectory(outFilePath); } //Array.Sort(dirs); foreach (var dir in dirs) { string path; var pathItem = PathSplitter.SplitPath(GetDirectoryPath(jsonStructureManager, dir.Id)); if (filePath.Equals("/")) { path = outFilePath + pathItem.ToString(); } else { path = outFilePath + pathItem.GetPathItemFrom(filePath).ToString(); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } foreach (var item in files.Select((value, index) => new { index, value })) { string path; var pathItem = PathSplitter.SplitPath(GetFilePath(jsonStructureManager, item.value.Id)); if (filePath.Equals("/")) { path = outFilePath + pathItem.ToString(); } else { path = outFilePath + pathItem.GetPathItemFrom(filePath).ToString(); } var isOk = WriteToFile(item.value, path); WriteToFilesProgress?.Invoke(this, new ReadWriteProgressEventArgs(item.index + 1, files.Length, item.value.Name, isOk)); } } }
public void AddPathTest() { var pathItem = new PathItem(); pathItem.AddPath("root"); pathItem.AddPath("dir"); pathItem.AddPath("subdir"); var expectPathItem = PathSplitter.SplitPath(ExpectedPath); var expected = "/root/dir/subdir"; var act = pathItem.ToString(); Assert.AreEqual(expected, act); Assert.AreEqual(expectPathItem, pathItem); }
public void GetPathTest() { var pathItem = PathSplitter.SplitPath(ExpectedPath); var act1 = pathItem.GetPath(0); var act2 = pathItem.GetPath(1); var act3 = pathItem.GetPath(2); var act4 = pathItem.GetPath(3); var exp1 = "root"; var exp2 = "dir"; var exp3 = "subdir"; string exp4 = null; Assert.AreEqual(exp1, act1); Assert.AreEqual(exp2, act2); Assert.AreEqual(exp3, act3); Assert.AreEqual(exp4, act4); }
protected (int nextId, int parentId) ResolveTermParameters(string fileName, string parent) { var pathItem = PathSplitter.SplitPath(parent); var fileArray = jsonStructureManager.GetFileStructures(); int dirCount = jsonStructureManager.NextFileId; //fileArray.Length > 0 ? fileArray[fileArray.Length - 1].Id + 1 : 1; int parentRootId = GetDirectoryId(pathItem); var dirs = jsonStructureManager.GetFileStructureFromParent(parentRootId, fileName); //var dirs = sqlite.GetValues(TABLE_FILES, "Parent = {0} and Name = '{1}'".FormatString(parentRootId, fileName)); if (dirs != null) { throw new FileExistedException("Existed {0} on {1}".FormatString(fileName, parent)); } if (parentRootId < 0) { throw new DirectoryNotFoundException("Not found {0}".FormatString(parent)); } return(dirCount, parentRootId); }