public static void AddTree(DirNode dirNode, string dirPrefix, string filePrefix, int width, int depth, int fileSizeInKB, FileAttributes? fa = null, DateTime? lmt = null) { for (int i = 0; i < width; ++i) { string fileName = i == 0 ? filePrefix : filePrefix + "_" + i; FileNode fileNode = new FileNode(fileName) { SizeInByte = 1024L * fileSizeInKB, FileAttr = fa, LastModifiedTime = lmt, }; dirNode.AddFileNode(fileNode); } if (depth > 0) { for (int i = 0; i < width; ++i) { string dirName = i == 0 ? dirPrefix : dirPrefix + "_" + i; DirNode subDirNode = dirNode.GetDirNode(dirName); if (subDirNode == null) { subDirNode = new DirNode(dirName); dirNode.AddDirNode(subDirNode); } DMLibDataHelper.AddTree(subDirNode, dirPrefix, filePrefix, width, depth - 1, fileSizeInKB, fa, lmt: lmt); } } }
public static void AddOneFileInBytes(DirNode dirNode, string fileName, long fileSizeInB, FileAttributes? fa = null, DateTime? lmt = null) { FileNode fileNode = new FileNode(fileName) { SizeInByte = fileSizeInB, FileAttr = fa, LastModifiedTime = lmt, }; dirNode.AddFileNode(fileNode); }
public static void AddMultipleFilesDifferentSize(DirNode dirNode, string filePrefix, int[] fileSizes) { for (int i = 0; i < fileSizes.Length; ++i) { FileNode fileNode = new FileNode(filePrefix + "_" + i) { SizeInByte = fileSizes[i] * 1024 }; dirNode.AddFileNode(fileNode); } }
private void TestDelimiter(char delimiter) { Test.Info("Test delimiter: {0}", delimiter); DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); string fileName = DMLibTestBase.FolderName + delimiter + DMLibTestBase.FolderName + delimiter + DMLibTestBase.FileName; DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, fileName, 1); TransferContext context = new DirectoryTransferContext(); context.FileFailed += (sender, e) => { Test.Info(e.Exception.StackTrace); }; TestExecutionOptions <DMLibDataInfo> options = new TestExecutionOptions <DMLibDataInfo>() { IsDirectoryTransfer = true, TransferItemModifier = (node, item) => { dynamic dirOptions = DefaultTransferDirectoryOptions; dirOptions.Recursive = true; dirOptions.Delimiter = delimiter; item.Options = dirOptions; item.TransferContext = context; } }; TestResult <DMLibDataInfo> result = this.ExecuteTestCase(sourceDataInfo, options); DMLibDataInfo expectedDataInfo = new DMLibDataInfo(string.Empty); DirNode dirNode1 = new DirNode(FolderName); DirNode dirNode2 = new DirNode(FolderName); FileNode fileNode = sourceDataInfo.RootNode.GetFileNode(fileName).Clone(DMLibTestBase.FileName); dirNode2.AddFileNode(fileNode); dirNode1.AddDirNode(dirNode2); expectedDataInfo.RootNode.AddDirNode(dirNode1); VerificationHelper.VerifySingleTransferStatus(result, 1, 0, 0, null); VerificationHelper.VerifyTransferSucceed(result, expectedDataInfo); }
public bool GoUp() { var rootDirInfo = new DirectoryInfo(_root); if (rootDirInfo.Parent == null) { return(false); } _root = rootDirInfo.Parent.FullName; var prevRootNode = _rootNode; _rootNode = new DirNode(_root, new List <ITreeViewItem> { prevRootNode }); _rootNode.Data = prevRootNode.Data; _prevRoots.Add(rootDirInfo.FullName); return(true); }
FileNode [] PopulateNodes (bool need_dotdot, UnixFileSystemInfo [] root) { FileNode [] pnodes = new FileNode [root.Length + (need_dotdot ? 1 : 0)]; int i = 0; if (need_dotdot){ pnodes [0] = new DirNodeDotDot (new UnixDirectoryInfo ("..")); i++; } foreach (var info in root){ if (info.IsDirectory) pnodes [i++] = new DirNode (info); else pnodes [i++] = new FileNode (info); } Array.Sort<FileNode> (pnodes, compare); return pnodes; }
//返回父目录 private void Button_Click_Back(object sender, RoutedEventArgs e) { if (nowfile.filename != "root") { dirNodeManager.BackDir(); DirNode d = dirNodeManager.GetWorkDir(); string name = dirNodeManager.GetWorkDir().name; files.Clear(); dirNodeManager.LSNOW(d, name); files = dirNodeManager.GetNowFiles(); DirNode dn = dirNodeManager.GetWorkDir(); nowfile.filename = dn.name; nowfile.filetype = dn.type; nowfile.filesize = dn.size; nowfile.filepicture = "Assets/folder.png"; } else { ShowMessageDialog("当前在根目录"); } }
/// <summary> /// Creates the system report collection. /// </summary> /// <param name="store">Store object</param> /// <param name="domain">The domain to which this collection will belong.</param> /// <returns>A collection object that represents the report collection.</returns> internal static Collection CreateReportCollection(Store store, Domain domain) { // Check to see if the report has already been created. Collection report = store.GetSingleCollectionByType("Reports"); if (report == null) { // Create the new report. report = new Collection(store, reportCollectionName, domain.ID); // Set the type as an iFolder so it can be accessed and shared by iFolder. report.SetType(report, "iFolder"); report.SetType(report, "Reports"); // Add the admin user for the domain as the owner. Member member = new Member(domain.Owner.Name, domain.Owner.UserID, Access.Rights.Admin); member.IsOwner = true; // Add the directory node string dirPath = Path.Combine(report.UnmanagedPath, reportCollectionName); DirNode dirNode = new DirNode(report, dirPath); // Create the unmanaged directory for the reports. if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } // Commit the changes. report.Commit(new Node[] { report, member, dirNode }); } reportCollectionID = report.ID; return(report); }
//删除选中的文件(夹) private void MenuFlyoutItem_Click_Delete(object sender, RoutedEventArgs e) { //ShowMessageDialog("删除当前"); if (nowfile.filetype == 0) { dirNodeManager.RemoveDir(nowfile.filename); DirNode d = dirNodeManager.GetWorkDir(); string name = dirNodeManager.GetWorkDir().name; files.Clear(); dirNodeManager.LSNOW(d, name); files = dirNodeManager.GetNowFiles(); } else { dirNodeManager.DeleteFile(nowfile.filename, nowfile.filetype); DirNode d = dirNodeManager.GetWorkDir(); string name = dirNodeManager.GetWorkDir().name; files.Clear(); dirNodeManager.LSNOW(d, name); files = dirNodeManager.GetNowFiles(); ShowMessageDialog("已删除文件" + nowfile.filename + "\n\n文件大小:" + nowfile.filesize); } }
/// <summary> /// Create a proxy for a domain /// </summary> /// <param name="store">Cbject to refer to store</param> /// <param name="cinfo">Collection info object</param> /// <param name="DomainID">Id of the domain</param> /// <param name="iFolderID">iFolder ID</param> /// <param name="localPath">Local path of iFolder</param> public static void CreateProxy(Store store, CollectionInfo cinfo, string DomainID, string iFolderID, string localPath) { ArrayList commitList = new ArrayList(); // CollectionInfo cinfo = DiscoveryFramework.GetCollectionInfo (iFolderID); Collection c = new Collection(store, cinfo.Name, cinfo.CollectionID, DomainID); c.HostID = cinfo.HostID; commitList.Add(c); // Create proxy member node Domain domain = store.GetDomain(DomainID); Member m = domain.GetCurrentMember(); Member member = new Member(m.Name, cinfo.MemberNodeID, m.UserID, Simias.Storage.Access.Rights.Admin, null); member.IsOwner = true; member.Proxy = true; commitList.Add(member); DirNode dn = new DirNode(c, localPath, cinfo.DirNodeID); if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } dn.Proxy = true; commitList.Add(dn); c.Proxy = true; c.Commit((Node[])commitList.ToArray(typeof(Node))); }
private void Search(DirNode n, Int32 id, ref Node res) { if (n.id == id) { res = n; return; } else { for (Int32 i = 0; i < n.subNodes.Count; i++) { Node subNode = n.subNodes[i]; if (subNode.id == id) { res = subNode; return; } if (subNode is DirNode) { Search((DirNode)subNode, id, ref res); } } } }
public void TestDirectoryCheckContentMD5() { long fileSize = 5 * 1024 * 1024; long totalSize = fileSize * 4; string wrongMD5 = "wrongMD5"; string checkWrongMD5File = "checkWrongMD5File"; string checkCorrectMD5File = "checkCorrectMD5File"; string notCheckWrongMD5File = "notCheckWrongMD5File"; string notCheckCorrectMD5File = "notCheckCorrectMD5File"; DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); DirNode checkMD5Folder = new DirNode("checkMD5"); DMLibDataHelper.AddOneFileInBytes(checkMD5Folder, checkWrongMD5File, fileSize); DMLibDataHelper.AddOneFileInBytes(checkMD5Folder, checkCorrectMD5File, fileSize); sourceDataInfo.RootNode.AddDirNode(checkMD5Folder); DirNode notCheckMD5Folder = new DirNode("notCheckMD5"); DMLibDataHelper.AddOneFileInBytes(notCheckMD5Folder, notCheckWrongMD5File, fileSize); DMLibDataHelper.AddOneFileInBytes(notCheckMD5Folder, notCheckCorrectMD5File, fileSize); sourceDataInfo.RootNode.AddDirNode(notCheckMD5Folder); FileNode tmpFileNode = checkMD5Folder.GetFileNode(checkWrongMD5File); tmpFileNode.MD5 = wrongMD5; tmpFileNode = notCheckMD5Folder.GetFileNode(notCheckWrongMD5File); tmpFileNode.MD5 = wrongMD5; SourceAdaptor.GenerateData(sourceDataInfo); TransferEventChecker eventChecker = new TransferEventChecker(); TransferContext context = new TransferContext(); eventChecker.Apply(context); bool failureReported = false; context.FileFailed += (sender, args) => { if (args.Exception != null) { failureReported = args.Exception.Message.Contains(checkWrongMD5File); } }; ProgressChecker progressChecker = new ProgressChecker(4, totalSize, 3, 1, 0, totalSize); context.ProgressHandler = progressChecker.GetProgressHandler(); List <Exception> transferExceptions = new List <Exception>(); context.FileFailed += (eventSource, eventArgs) => { transferExceptions.Add(eventArgs.Exception); }; TransferItem checkMD5Item = new TransferItem() { SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), DestObject = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), IsDirectoryTransfer = true, SourceType = DMLibTestContext.SourceType, DestType = DMLibTestContext.DestType, IsServiceCopy = DMLibTestContext.IsAsync, TransferContext = context, Options = new DownloadDirectoryOptions() { DisableContentMD5Validation = false, Recursive = true, }, }; TransferItem notCheckMD5Item = new TransferItem() { SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, notCheckMD5Folder), DestObject = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, notCheckMD5Folder), IsDirectoryTransfer = true, SourceType = DMLibTestContext.SourceType, DestType = DMLibTestContext.DestType, IsServiceCopy = DMLibTestContext.IsAsync, TransferContext = context, Options = new DownloadDirectoryOptions() { DisableContentMD5Validation = true, Recursive = true, }, }; var testResult = this.RunTransferItems(new List <TransferItem>() { checkMD5Item, notCheckMD5Item }, new TestExecutionOptions <DMLibDataInfo>()); DMLibDataInfo expectedDataInfo = sourceDataInfo.Clone(); expectedDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode(checkWrongMD5File); expectedDataInfo.RootNode.GetDirNode(notCheckMD5Folder.Name).DeleteFileNode(notCheckWrongMD5File); DMLibDataInfo actualDataInfo = testResult.DataInfo; actualDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode(checkWrongMD5File); actualDataInfo.RootNode.GetDirNode(notCheckMD5Folder.Name).DeleteFileNode(notCheckWrongMD5File); Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, actualDataInfo), "Verify transfer result."); Test.Assert(failureReported, "Verify md5 check failure is reported."); VerificationHelper.VerifyFinalProgress(progressChecker, 3, 0, 1); if (testResult.Exceptions.Count != 0 || transferExceptions.Count != 1) { Test.Error("Expect one exception but actually no exception is thrown."); } else { VerificationHelper.VerifyExceptionErrorMessage(transferExceptions[0], new string[] { "The MD5 hash calculated from the downloaded data does not match the MD5 hash stored in the property of source" }); } }
/// <summary> /// Constructs a Conflict object. /// </summary> /// <param name="col">The collection containing the conflict.</param> /// <param name="node">The conflicting node.</param> public Conflict(Collection col, Node node) { iFolderID = col.ID; ConflictID = node.ID; Simias.Sync.Conflict conflict = new Simias.Sync.Conflict(col, node); if (conflict.IsFileNameConflict) { IsNameConflict = true; FileNode fileNode = node as FileNode; if (fileNode != null) { string name = Path.GetFileName(conflict.NonconflictedPath); if (name.Equals(Path.GetFileName(conflict.FileNameConflictPath))) { LocalName = name; LocalDate = fileNode.LastWriteTime.ToString(); LocalSize = formatFileSize(fileNode.Length); LocalFullPath = conflict.FileNameConflictPath; } else { ServerName = name; ServerDate = fileNode.LastWriteTime.ToString(); ServerSize = formatFileSize(fileNode.Length); ServerFullPath = conflict.NonconflictedPath; } } else { DirNode dn = node as DirNode; if (dn != null) { if (dn.Name.Equals(Path.GetFileName(conflict.FileNameConflictPath))) { LocalName = dn.Name; LocalDate = null; LocalSize = null; LocalFullPath = conflict.FileNameConflictPath; } else { ServerName = dn.Name; ServerDate = null; ServerSize = null; ServerFullPath = conflict.NonconflictedPath; } } } } else { IsNameConflict = false; FileNode localFileNode = new FileNode(node); Node serverNode = col.GetNodeFromCollision(node); FileNode serverFileNode = new FileNode(serverNode); LocalName = localFileNode.GetFileName(); LocalDate = localFileNode.LastWriteTime.ToString(); LocalSize = formatFileSize(localFileNode.Length); LocalFullPath = conflict.NonconflictedPath; ServerName = serverFileNode.GetFileName(); ServerDate = serverFileNode.LastWriteTime.ToString(); ServerSize = formatFileSize(serverFileNode.Length); ServerFullPath = conflict.UpdateConflictPath; } }
private void TestDirectoryCheckContentMD5StreamResume(bool checkMD5) { long fileSize = 5 * 1024; int fileCountMulti = 32; long totalSize = fileSize * 4 * fileCountMulti; string wrongMD5 = "wrongMD5"; string wrongMD5File = "wrongMD5File"; string correctMD5File = "correctMD5File"; // Prepare data for transfer items with checkMD5 DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); DirNode checkMD5Folder = new DirNode(checkMD5 ? "checkMD5" : "notCheckMD5"); for (int i = 0; i < fileCountMulti; ++i) { var wrongMD5FileNode = new FileNode($"{wrongMD5File}_{i}") { SizeInByte = fileSize, MD5 = wrongMD5 }; checkMD5Folder.AddFileNode(wrongMD5FileNode); DMLibDataHelper.AddOneFileInBytes(checkMD5Folder, $"{correctMD5File}_{i}", fileSize); } sourceDataInfo.RootNode.AddDirNode(checkMD5Folder); SourceAdaptor.GenerateData(sourceDataInfo); DestAdaptor.Cleanup(); TransferEventChecker eventChecker = new TransferEventChecker(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); using (var resumeStream = new MemoryStream()) { TransferContext context = new DirectoryTransferContext(resumeStream); eventChecker.Apply(context); ProgressChecker progressChecker = new ProgressChecker(2 * fileCountMulti, totalSize, checkMD5 ? fileCountMulti : 2 * fileCountMulti, null, 0, totalSize); context.ProgressHandler = progressChecker.GetProgressHandler(); List <Exception> transferExceptions = new List <Exception>(); TransferItem checkMD5Item = new TransferItem() { SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), DestObject = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), IsDirectoryTransfer = true, SourceType = DMLibTestContext.SourceType, DestType = DMLibTestContext.DestType, CopyMethod = DMLibTestContext.CopyMethod.ToCopyMethod(), TransferContext = context, Options = new DownloadDirectoryOptions() { DisableContentMD5Validation = !checkMD5, Recursive = true, }, CancellationToken = cancellationTokenSource.Token, }; var executionOption = new TestExecutionOptions <DMLibDataInfo>(); executionOption.AfterAllItemAdded = () => { // Wait until there are data transferred if (!progressChecker.DataTransferred.WaitOne(30000)) { Test.Error("No progress in 30s."); } // Cancel the transfer and store the second checkpoint cancellationTokenSource.Cancel(); }; executionOption.LimitSpeed = true; var testResult = this.RunTransferItems(new List <TransferItem>() { checkMD5Item }, executionOption); if (null != testResult.Exceptions) { foreach (var exception in testResult.Exceptions) { Test.Info("Got exception during transferring. {0}", exception); } } eventChecker = new TransferEventChecker(); resumeStream.Position = 0; context = new DirectoryTransferContext(resumeStream); eventChecker.Apply(context); bool failureReported = false; context.FileFailed += (sender, args) => { if (args.Exception != null) { failureReported = args.Exception.Message.Contains(wrongMD5File); } transferExceptions.Add(args.Exception); }; progressChecker.Reset(); context.ProgressHandler = progressChecker.GetProgressHandler(); checkMD5Item = checkMD5Item.Clone(); checkMD5Item.TransferContext = context; testResult = this.RunTransferItems(new List <TransferItem>() { checkMD5Item }, new TestExecutionOptions <DMLibDataInfo>()); DMLibDataInfo expectedDataInfo = sourceDataInfo.Clone(); DMLibDataInfo actualDataInfo = testResult.DataInfo; for (int i = 0; i < fileCountMulti; ++i) { expectedDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode($"{wrongMD5File}_{i}"); actualDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode($"{wrongMD5File}_{i}"); } Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, actualDataInfo), "Verify transfer result."); Test.Assert(checkMD5 ? failureReported : !failureReported, "Verify md5 check failure is expected."); VerificationHelper.VerifyFinalProgress(progressChecker, checkMD5 ? fileCountMulti : 2 * fileCountMulti, 0, checkMD5 ? fileCountMulti : 0); if (checkMD5) { if (testResult.Exceptions.Count != 0 || transferExceptions.Count != fileCountMulti) { Test.Error("Expect one exception but actually no exception is thrown."); } else { for (int i = 0; i < fileCountMulti; ++i) { VerificationHelper.VerifyExceptionErrorMessage(transferExceptions[i], new string[] { "The MD5 hash calculated from the downloaded data does not match the MD5 hash stored in the property of source" }); } } } else { Test.Assert(testResult.Exceptions.Count == 0, "Should no exception thrown out when disabling check md5"); } } }
public void TestDirectoryCheckContentMD5Resume() { long fileSize = 5 * 1024; int fileCountMulti = 32; long totalSize = fileSize * 4 * fileCountMulti; string wrongMD5 = "wrongMD5"; string checkWrongMD5File = "checkWrongMD5File"; string checkCorrectMD5File = "checkCorrectMD5File"; string notCheckWrongMD5File = "notCheckWrongMD5File"; string notCheckCorrectMD5File = "notCheckCorrectMD5File"; // Prepare data for transfer items with checkMD5 DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); DirNode checkMD5Folder = new DirNode("checkMD5"); for (int i = 0; i < fileCountMulti; ++i) { var wrongMD5FileNode = new FileNode($"{checkWrongMD5File}_{i}") { SizeInByte = fileSize, MD5 = wrongMD5 }; checkMD5Folder.AddFileNode(wrongMD5FileNode); DMLibDataHelper.AddOneFileInBytes(checkMD5Folder, $"{checkCorrectMD5File}_{i}", fileSize); } sourceDataInfo.RootNode.AddDirNode(checkMD5Folder); // Prepare data for transfer items with disabling MD5 check DirNode notCheckMD5Folder = new DirNode("notCheckMD5"); for (int i = 0; i < fileCountMulti; ++i) { var wrongMD5FileNode = new FileNode($"{notCheckWrongMD5File}_{i}") { SizeInByte = fileSize, MD5 = wrongMD5 }; notCheckMD5Folder.AddFileNode(wrongMD5FileNode); DMLibDataHelper.AddOneFileInBytes(notCheckMD5Folder, $"{notCheckCorrectMD5File}_{i}", fileSize); } sourceDataInfo.RootNode.AddDirNode(notCheckMD5Folder); SourceAdaptor.GenerateData(sourceDataInfo); TransferEventChecker eventChecker = new TransferEventChecker(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); TransferContext context = new DirectoryTransferContext(); eventChecker.Apply(context); ProgressChecker progressChecker = new ProgressChecker(4 * fileCountMulti, totalSize, 3 * fileCountMulti, null, 0, totalSize); context.ProgressHandler = progressChecker.GetProgressHandler(); List <Exception> transferExceptions = new List <Exception>(); TransferItem checkMD5Item = new TransferItem() { SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), DestObject = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), IsDirectoryTransfer = true, SourceType = DMLibTestContext.SourceType, DestType = DMLibTestContext.DestType, IsServiceCopy = DMLibTestContext.IsAsync, TransferContext = context, Options = new DownloadDirectoryOptions() { DisableContentMD5Validation = false, Recursive = true, }, CancellationToken = cancellationTokenSource.Token, }; TransferItem notCheckMD5Item = new TransferItem() { SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, notCheckMD5Folder), DestObject = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, notCheckMD5Folder), IsDirectoryTransfer = true, SourceType = DMLibTestContext.SourceType, DestType = DMLibTestContext.DestType, IsServiceCopy = DMLibTestContext.IsAsync, TransferContext = context, Options = new DownloadDirectoryOptions() { DisableContentMD5Validation = true, Recursive = true, }, CancellationToken = cancellationTokenSource.Token }; var executionOption = new TestExecutionOptions <DMLibDataInfo>(); executionOption.AfterAllItemAdded = () => { // Wait until there are data transferred progressChecker.DataTransferred.WaitOne(); // Cancel the transfer and store the second checkpoint cancellationTokenSource.Cancel(); }; executionOption.LimitSpeed = true; var testResult = this.RunTransferItems(new List <TransferItem>() { checkMD5Item, notCheckMD5Item }, executionOption); eventChecker = new TransferEventChecker(); context = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(context.LastCheckpoint)); eventChecker.Apply(context); bool failureReported = false; context.FileFailed += (sender, args) => { if (args.Exception != null) { failureReported = args.Exception.Message.Contains(checkWrongMD5File); } transferExceptions.Add(args.Exception); }; progressChecker.Reset(); context.ProgressHandler = progressChecker.GetProgressHandler(); checkMD5Item = checkMD5Item.Clone(); notCheckMD5Item = notCheckMD5Item.Clone(); checkMD5Item.TransferContext = context; notCheckMD5Item.TransferContext = context; testResult = this.RunTransferItems(new List <TransferItem>() { checkMD5Item, notCheckMD5Item }, new TestExecutionOptions <DMLibDataInfo>()); DMLibDataInfo expectedDataInfo = sourceDataInfo.Clone(); DMLibDataInfo actualDataInfo = testResult.DataInfo; for (int i = 0; i < fileCountMulti; ++i) { expectedDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode($"{checkWrongMD5File}_{i}"); expectedDataInfo.RootNode.GetDirNode(notCheckMD5Folder.Name).DeleteFileNode($"{notCheckWrongMD5File}_{i}"); actualDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode($"{checkWrongMD5File}_{i}"); actualDataInfo.RootNode.GetDirNode(notCheckMD5Folder.Name).DeleteFileNode($"{notCheckWrongMD5File}_{i}"); } Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, actualDataInfo), "Verify transfer result."); Test.Assert(failureReported, "Verify md5 check failure is reported."); VerificationHelper.VerifyFinalProgress(progressChecker, 3 * fileCountMulti, 0, fileCountMulti); if (testResult.Exceptions.Count != 0 || transferExceptions.Count != fileCountMulti) { Test.Error("Expect one exception but actually no exception is thrown."); } else { for (int i = 0; i < fileCountMulti; ++i) { VerificationHelper.VerifyExceptionErrorMessage(transferExceptions[i], new string[] { "The MD5 hash calculated from the downloaded data does not match the MD5 hash stored in the property of source" }); } } }
//名命比较重要的函数 private void Name_ReName(object sender, RoutedEventArgs e) { string name; if (nr == 1) { string newname = InPutName.Text; string oldname = nowfile.filename; int flags = 0; while (true) { if (files.Count() == 0) { break; } foreach (Model.File file in files) { if (file.filename == newname && file.filetype == nowfile.filetype) { ShowMessageDialog("文件(夹)名重复, 请重新输入"); } } dirNodeManager.ReName(oldname, newname); flags = 1; if (flags == 1) { break; } } } else if (nr == 2) { Random ra = new Random(); int n = ra.Next(100); name = InPutName.Text; if (name == "" || name == null) { ShowMessageDialog("请输入文件名"); return; } int flags = 0; int size = ra.Next(100); while (true) { if (files.Count() == 0) { dirNodeManager.MakeDir(name); break; } foreach (Model.File file in files) { if (file.filename == name && file.filetype == 0) { ShowMessageDialog("文件(夹)名重复"); flags = 1; return; } } dirNodeManager.MakeDir(name); flags = 1; if (flags == 1) { break; } } } else if (nr == 3) { Random ra = new Random(); int n = ra.Next(100); name = InPutName.Text; if (name == "" || name == null) { ShowMessageDialog("请输入文件名"); return; } int flags = 0; int size = ra.Next(100); int type = ra.Next(4); while (true) { if (files.Count() == 0) { dirNodeManager.CreateFile(name, size, type + 1); break; } foreach (Model.File file in files) { if (file.filename == name && file.filetype == type + 1) { ShowMessageDialog("文件名重复"); flags = 1; return; } } dirNodeManager.CreateFile(name, size, type + 1); flags = 1; if (flags == 1) { break; } } } DirNode d = dirNodeManager.GetWorkDir(); string name1 = dirNodeManager.GetWorkDir().name; files.Clear(); dirNodeManager.LSNOW(d, name1); files = dirNodeManager.GetNowFiles(); InPutDialog.Hide(); }
/// <summary> /// Constructor /// </summary> /// <param name="collection">Collcetion</param> public iFolderWeb(Collection collection, int infoToFetch) { Member tmpMember = null; //base information that is mandatory this.DomainID = collection.Domain; this.ID = collection.ID; this.CollectionID = collection.ID; this.LocalIncarnation = collection.LocalIncarnation; //infoToFetch is a bitmap, for now using it as a boolean if (infoToFetch > 0) { DirNode dirNode = collection.GetRootDirectory(); if (dirNode != null) { this.UnManagedPath = dirNode.GetFullPath(collection); } else { this.UnManagedPath = ""; } this.ManagedPath = collection.ManagedPath; this.MasterIncarnation = collection.MasterIncarnation; this.Name = collection.Name; DateTime lastSyncTime = Simias.Sync.SyncClient.GetLastSyncTime(collection.ID); if (collection.Role.Equals(SyncRoles.Master)) { this.LastSyncTime = string.Empty; this.State = "Local"; } else if (lastSyncTime.Equals(DateTime.MinValue)) { this.LastSyncTime = string.Empty; this.State = "WaitSync"; } else { this.LastSyncTime = lastSyncTime.ToString(); this.State = collection.IsProxy ? "WaitSync" : "Local"; } this.HasConflicts = collection.HasCollisions(); tmpMember = collection.GetCurrentMember(); this.CurrentUserID = tmpMember.UserID; this.CurrentUserRights = tmpMember.Rights.ToString(); this.Role = collection.Role.ToString(); this.ssl = collection.SSL; if (collection.EncryptionAlgorithm == null || collection.EncryptionAlgorithm == "") { this.encryptionAlgorithm = ""; } else { this.encryptionAlgorithm = collection.EncryptionAlgorithm; } this.MigratediFolder = collection.MigratediFolder; tmpMember = collection.Owner; if (tmpMember != null) { this.Owner = tmpMember.Name; this.OwnerID = tmpMember.UserID; this.EffectiveSyncInterval = tmpMember.EffectiveSyncPolicy(collection); } else { this.Owner = "Not available"; this.OwnerID = "0"; } ICSList memberList; memberList = collection.GetMemberList(); if (memberList.Count > 1) { this.shared = true; } else { this.shared = false; } this.iFolderSize = collection.StorageSize; } }
/// <summary> /// Constructor /// </summary> public iFolderWeb(Collection collection) { Member tmpMember = null; this.DomainID = collection.Domain; this.ID = collection.ID; this.CollectionID = collection.ID; this.LocalIncarnation = collection.LocalIncarnation; DirNode dirNode = collection.GetRootDirectory(); if (dirNode != null) { this.UnManagedPath = dirNode.GetFullPath(collection); } else { this.UnManagedPath = ""; } this.ManagedPath = collection.ManagedPath; this.MasterIncarnation = collection.MasterIncarnation; this.Name = collection.Name; tmpMember = collection.Owner; if (tmpMember != null) { this.OwnerID = tmpMember.UserID; Domain domain = Store.GetStore().GetDomain(this.DomainID); Member domainMember = domain.GetMemberByID(this.OwnerID); string fullName = domainMember.FN; this.Owner = (fullName != null) ? fullName : tmpMember.Name; this.EffectiveSyncInterval = tmpMember.EffectiveSyncPolicy(collection); } else { this.Owner = "Not available"; this.OwnerID = "0"; } this.SyncInterval = Simias.Policy.SyncInterval.GetInterval(collection); this.Synchronizable = collection.Synchronizable; this.Type = iFolderType; this.Description = ""; this.IsSubscription = false; this.EnumeratedState = -1; // There is no longer a WorkGroup domain ... for now return false. We // probably need to change this to return a type instead. this.IsWorkgroup = false; this.HasConflicts = collection.HasCollisions(); tmpMember = collection.GetCurrentMember(); this.CurrentUserID = tmpMember.UserID; this.CurrentUserRights = tmpMember.Rights.ToString(); int EffectiveSync = tmpMember.EffectiveSyncPolicy(collection); if (EffectiveSync > 0) { this.EffectiveSyncInterval = EffectiveSync; //Simias.Policy.SyncInterval.Set(collection, EffectiveSync); } DateTime lastSyncTime = Simias.Sync.SyncClient.GetLastSyncTime(collection.ID); if (collection.Role.Equals(SyncRoles.Master)) { this.LastSyncTime = string.Empty; this.State = "Local"; } else if (lastSyncTime.Equals(DateTime.MinValue)) { this.LastSyncTime = string.Empty; this.State = "WaitSync"; } else { this.LastSyncTime = lastSyncTime.ToString(); this.State = collection.IsProxy ? "WaitSync" : "Local"; } this.Role = collection.Role.ToString(); this.ssl = collection.SSL; if (collection.EncryptionAlgorithm == null || collection.EncryptionAlgorithm == "") { this.encryptionAlgorithm = ""; } else { this.encryptionAlgorithm = collection.EncryptionAlgorithm; } this.MigratediFolder = collection.MigratediFolder; ICSList memberList; memberList = collection.GetMemberList(); if (memberList.Count > 1) { this.shared = true; } else { this.shared = false; } this.iFolderSize = collection.StorageSize; }
public static void CheckiFolderConsistency(Store store, Domain domain, Member member) { ICSList ColList = store.GetCollectionsByOwner(member.UserID); // Now match the total number of files and dirs in the node and that on physical filesystem. string UnManagedPath = null; long missingFile = 0; string errorLine = ""; foreach (ShallowNode sn in ColList) { Collection c = store.GetCollectionByID(sn.ID); if (c != null) { DirNode rootNode = c.GetRootDirectory(); if (rootNode != null) { Simias.Storage.Property localPath = rootNode.Properties.GetSingleProperty(PropertyTags.Root); if (localPath != null) { UnManagedPath = localPath.Value as string; /* Iterate over all the file nodes */ ICSList FileList = c.GetNodesByType(NodeTypes.FileNodeType); errorLine += ("\n\niFolder Name: " + c.Name + "\n"); errorLine += (" Action If Any: "); foreach (ShallowNode sn2 in FileList) { try { Node fileNode = c.GetNodeByID(sn2.ID); Simias.Storage.Property property = fileNode.Properties.GetSingleProperty(PropertyTags.FileSystemPath); if (property != null) { string filePath = property.Value.ToString(); string fullPath = Path.Combine(UnManagedPath, filePath);; if (!File.Exists(fullPath)) { String fileName = fileNode.Name; //fileNode.Properties.GetSingleProperty( "name" ).Value as string; // File entry in nodelist is not present in actual path so this user cannot be moved. c.Commit(c.Delete(fileNode)); errorLine += (" File Node Deleted: " + fileName); missingFile++; } } } catch (Exception e) { Console.WriteLine("some exception while iteration of files."); } } /* Iterate over all the folder nodes. */ ICSList DirList = c.GetNodesByType(NodeTypes.DirNodeType); foreach (ShallowNode sn2 in DirList) { try { Node folNode = c.GetNodeByID(sn2.ID); Simias.Storage.Property property = folNode.Properties.GetSingleProperty(PropertyTags.FileSystemPath); if (property != null) { string filePath = property.Value.ToString(); string fullPath = Path.Combine(UnManagedPath, filePath);; if (!Directory.Exists(fullPath)) { String folderName = folNode.Name; // File entry in nodelist is not present in actual path so this user cannot be moved. c.Commit(c.Delete(folNode)); errorLine += (" Folder Node Deleted: " + folderName); missingFile++; } } } catch (Exception e) { Console.WriteLine("some exception while iteration of files."); } } } } } } Console.WriteLine(); Console.WriteLine(); if (missingFile == 0) { Console.WriteLine("*********************" + member.FN + " (" + member.Name + ") Passed *******************"); } else { Console.WriteLine("*********************" + member.FN + " (" + member.Name + ") " + missingFile + " inconsistent files or folders *******************"); Console.WriteLine(errorLine); } }
public abstract object GetTransferObject(DirNode dirNode);
/// <summary> /// 建立该节点的子节点 /// </summary> /// <param name="node">文件夹节点</param> public static void BuildChildrenNodes(DirNode node) { //获取对应节点下的文件夹列表 RecordBean[] oldBeans; if (node.OldIncidentId == 0) { oldBeans = new RecordBean[0]; } else { oldBeans = RecordMapper.GetBeansByPid(node.OldId, node.OldIncidentId); } RecordBean[] newBeans; if (node.NewIncidentId == 0) { newBeans = new RecordBean[0]; } else { newBeans = RecordMapper.GetBeansByPid(node.NewId, node.NewIncidentId); } List <DirNode> dirNodes = new List <DirNode>(); //遍历两个文件夹列表 foreach (RecordBean oldBean in oldBeans) { RecordBean newBean = null; //去除重复项 for (int i = 0; i < newBeans.Length; i++) { if (newBeans[i] == null) { continue; } if (oldBean.Path == newBeans[i].Path) { newBean = newBeans[i]; newBeans[i] = null; } } //建立node DirNode dirNode = new DirNode() { Name = oldBean.Name, Path = oldBean.Path, // 放入一个空数组,告知页面该节点可以展开 Children = oldBean.DirCount > 0 ? new DirNode[1] : null, }; SetOldId(ref dirNode, oldBean, node.OldIncidentId); //设置类型 if (newBean != null) { SetNewId(ref dirNode, newBean, node.NewIncidentId); if (oldBean.Equals(newBean)) { dirNode.Type = DirNodeType.Unchanged; } else { dirNode.Type = DirNodeType.Changed; } } else { dirNode.Type = DirNodeType.Deleted; } dirNodes.Add(dirNode); } //新纪录中新增的部分 foreach (RecordBean newBean in newBeans) { if (newBean == null) { continue; } DirNode dirNode = new DirNode() { Name = newBean.Name, Path = newBean.Path, Children = newBean.DirCount > 0 ? new DirNode[1] : null, //新增的节点 Type = DirNodeType.Added, }; SetNewId(ref dirNode, newBean, node.NewIncidentId); dirNodes.Add(dirNode); } //添加标签 TagBean nullTag = new TagBean() { Color = "#FFFFFF" }; foreach (DirNode dirNode in dirNodes) { TagBean tagBean = TagSupport.GetTagByPath(dirNode.Path, out bool isThis); if (tagBean == null) { dirNode.Tag = nullTag; continue; } dirNode.IsRootTag = isThis; dirNode.Tag = tagBean; } node.Children = dirNodes.ToArray(); }
/// <summary> /// 通过节点获取文件夹的比较信息 /// </summary> public static ComparisonInfo GetInfoByNode(DirNode node) { //获取bean RecordBean oldBean = null; if (node.OldId != 0) { oldBean = RecordMapper.GetOneById(node.OldId, node.OldIncidentId); } RecordBean newBean = null; if (node.NewId != 0) { newBean = RecordMapper.GetOneById(node.NewId, node.NewIncidentId); } //设置标签 ComparisonInfo info = new ComparisonInfo() { TagName = string.Concat("标签:", node.Tag.Name ?? "没有标签") }; //设置主要比较的数据 BigInteger oldSize, newSize, oldUsage, newUsage; if (oldBean != null) { info.Title = oldBean.Name; info.Location = oldBean.Location; info.CreateTime = "创建时间:" + oldBean.CerateTime.ToString("yy-MM-dd HH:mm:ss"); info.OldFileCount = Convert.ToInt32(oldBean.FileCount); info.OldDirCount = Convert.ToInt32(oldBean.DirCount); oldSize = oldBean.Size; oldUsage = oldBean.SpaceUsage; } else { oldSize = BigInteger.Zero; oldUsage = BigInteger.Zero; } if (newBean != null) { info.Title = newBean.Name; info.Location = newBean.Location; info.CreateTime = "创建时间:" + newBean.CerateTime.ToString("yy-MM-dd HH:mm:ss"); info.NewFileCount = Convert.ToInt32(newBean.FileCount); info.NewDirCount = Convert.ToInt32(newBean.DirCount); newSize = newBean.Size; newUsage = newBean.SpaceUsage; } else { newSize = BigInteger.Zero; newUsage = BigInteger.Zero; } //单位换算 info.OldSize = ConversionUtil.StorageFormate(oldSize, false); info.NewSize = ConversionUtil.StorageFormate(newSize, false); info.SizeChanged = ConversionUtil.StorageFormate(newSize - oldSize, true); info.OldUsage = ConversionUtil.StorageFormate(oldUsage, false); info.NewUsage = ConversionUtil.StorageFormate(newUsage, false); info.UsageChanged = ConversionUtil.StorageFormate(newUsage - oldUsage, true); //设置状态 switch (node.Type) { case DirNodeType.Unchanged: info.Action = "文件夹未发生变化"; break; case DirNodeType.Added: info.Action = "该文件夹是新增的文件夹"; break; case DirNodeType.Changed: info.Action = "该文件夹发生了变化"; break; case DirNodeType.Deleted: info.Action = "该文件夹已经被删除"; break; } return(info); }
public void AddObject(FsObject<RelPath> descriptor) { DirNode parent = GetParentDir(descriptor.Path); if (descriptor is FsFile<RelPath>) { var file = ((FsFile<RelPath>) descriptor).NewAsName(); parent.Files.Add(file.Path, file); } else { var dir = ((FsFolder<RelPath>)descriptor).NewAsName(); var node = new DirNode(dir, parent); parent.Directories.Add(dir.Path, node); } }
public DirNode EnsureDirNode(Name name) { DirNode node; if (!_directories.TryGetValue(name, out node)) { node = new DirNode(name, this); _directories.Add(name, node); } return node; }
public string CreateMaster(string collectionID, string collectionName, string rootDirID, string rootDirName, string userID, string memberName, string memberID, string memberRights) { Simias.Server.EnterpriseDomain enterpriseDomain = new Simias.Server.EnterpriseDomain(false); if (enterpriseDomain == null) { throw new SimiasException("Enterprise server domain does not exist."); } Store store = Store.GetStore(); Simias.Storage.Domain domain = store.GetDomain(enterpriseDomain.ID); if (domain == null) { throw new SimiasException("Enterprise server domain does not exist."); } ArrayList nodeList = new ArrayList(); Collection c = new Collection(store, collectionName, collectionID, domain.ID); c.Proxy = true; nodeList.Add(c); string existingUserID = Thread.CurrentPrincipal.Identity.Name; Member existingMember = domain.GetMemberByID(existingUserID); if (existingMember == null) { throw new SimiasException(String.Format("Impersonating user: {0} is not a member of the domain.", Thread.CurrentPrincipal.Identity.Name)); } // Make sure the creator and the owner are the same ID. if (existingUserID != userID) { throw new SimiasException(String.Format("Creator ID {0} is not the same as the caller ID {1}.", existingUserID, userID)); } // member node. Access.Rights rights = (Access.Rights)Enum.Parse(typeof(Access.Rights), memberRights); Member member = new Member(memberName, memberID, userID, rights, null); member.IsOwner = true; member.Proxy = true; nodeList.Add(member); // check for a root dir node if (((rootDirID != null) && (rootDirID.Length > 0)) && (rootDirName != null) && (rootDirName.Length > 0)) { // Get the collections Unmanaged Path string path = c.UnmanagedPath; path = Path.Combine(path, rootDirName); // create root directory node DirNode dn = new DirNode(c, path, rootDirID); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } dn.Proxy = true; nodeList.Add(dn); } // Create the collection. c.Commit(nodeList.ToArray(typeof(Node)) as Node[]); // get the collection master url Uri request = Context.Request.Url; UriBuilder uri = new UriBuilder(request.Scheme, request.Host, request.Port, Context.Request.ApplicationPath.TrimStart(new char[] { '/' })); return(uri.ToString()); }
public static void AddTreeTotalSize(DirNode dirNode, string dirPrefix, string filePrefix, int width, int depth, int totalSizeInKB, DateTime? lmt = null) { int fileNumber; if (width <= 1) { fileNumber = (depth + 1) * width; } else { int widthPowDepth = width; for (int i = 0; i < depth; ++i) { widthPowDepth *= width; } fileNumber = width * (widthPowDepth - 1) / (width - 1); } int fileSizeInKB = totalSizeInKB / fileNumber; fileSizeInKB = fileSizeInKB == 0 ? 1 : fileSizeInKB; DMLibDataHelper.AddTree(dirNode, dirPrefix, filePrefix, width, depth, fileSizeInKB, lmt: lmt); }
/// <summary> /// Delete An iFolder Entry /// </summary> /// <param name="ifolderID">The ID of the iFolder.</param> /// <param name="entryID">The ID of the Entry.</param> /// <param name="accessID">The Access User ID.</param> public static void DeleteEntry(string ifolderID, string entryID, string accessID) { Store store = Store.GetStore(); Collection c = store.GetCollectionByID(ifolderID); if (c == null) { throw new iFolderDoesNotExistException(ifolderID); } // impersonate iFolder.Impersonate(c, accessID); Node n = c.GetNodeByID(entryID); if (n == null) { throw new EntryDoesNotExistException(entryID); } // directory if (n.IsBaseType(NodeTypes.DirNodeType)) { DirNode dn = (DirNode)n; if (dn.IsRoot) { throw new DirectoryEntryRequiredException(entryID); } string path = dn.GetFullPath(c); if (Directory.Exists(path)) { Directory.Delete(path, true); } // delete recursivley c.Commit(c.Delete(dn, PropertyTags.Parent)); } // file else if (n.IsBaseType(NodeTypes.FileNodeType)) { FileNode fn = (FileNode)n; string path = fn.GetFullPath(c); if (File.Exists(path)) { File.Delete(path); } c.Commit(c.Delete(fn)); } // not an entry else { throw new EntryDoesNotExistException(entryID); } }
public static FileNode GetFileNode(DirNode dirNode, params string[] tokens) { DirNode currentDirNode = dirNode; for (int i = 0; i < tokens.Length; ++i) { if (i == tokens.Length - 1) { FileNode fileNode = currentDirNode.GetFileNode(tokens[i]); if (fileNode == null) { Test.Error("FileNode {0} doesn't exist.", tokens[i]); return null; } return fileNode; } else { currentDirNode = currentDirNode.GetDirNode(tokens[i]); if (currentDirNode == null) { Test.Error("DirNode {0} doesn't exist.", tokens[i]); return null; } } } return null; }
//--------------------------------------------------------------------------- /// <summary> /// resolve file name conflict and commit /// </summary> public void Resolve(string newNodeName) { if (!SyncFile.IsNameValid(newNodeName)) { throw new MalformedException(newNodeName); } FileNode fn = node as FileNode; if (fn != null) { DirNode parent = fn.GetParent(collection); if (newNodeName == node.Name) { Log.log.Debug("Resolving the name conflict >>>>> name: {0} newName: {1}", node.Name, newNodeName); // We are resolving to the same name. if (Path.GetDirectoryName(FileNameConflictPath) != Path.GetDirectoryName(NonconflictedPath)) { // This file is in the conflict bin and has been sync-ed from the server. We do not need // To push it back up. Set internal. node.Properties.State = PropertyList.PropertyListState.Internal; try { File.Move(FileNameConflictPath, NonconflictedPath); } catch (IOException) { // The file exists it must have been modified locally create a node conflict. File.Move(FileNameConflictPath, GetUpdateConflictPath(collection, fn)); fn = (FileNode)RemoveNameConflict(collection, fn); collection.Commit(fn); Node serverNode = collection.GetNodeByID(fn.ID); // Now commit the node to update the file (size and dates); fn.UpdateFileInfo(collection); collection.Commit(fn); // Create the node conflict. fn = (FileNode)collection.CreateCollision(serverNode, false); collection.Commit(fn); return; } } } else { Log.log.Debug("Resolving the name conflict >>>>> name: {0} newName: {1}", node.Name, newNodeName); if (SyncFile.DoesNodeExist(collection, parent, newNodeName)) { throw new ExistsException(newNodeName); } //TODO: what if move succeeds but node rename or commit fails? File.Move(FileNameConflictPath, Path.Combine(Path.GetDirectoryName(NonconflictedPath), newNodeName)); string relativePath = fn.GetRelativePath(); relativePath = relativePath.Remove(relativePath.Length - node.Name.Length, node.Name.Length) + newNodeName; node.Properties.ModifyNodeProperty(new Property(PropertyTags.FileSystemPath, Syntax.String, relativePath)); node.Name = newNodeName; } node = RemoveNameConflict(collection, node); collection.Commit(node); } else { DirNode dn = node as DirNode; if (dn != null) { DirNode parent = dn.GetParent(collection); string oldname, newname; oldname = FileNameConflictPath; newname = Path.Combine(Path.GetDirectoryName(dn.GetFullPath(collection)), newNodeName); if (newNodeName != node.Name) { if (SyncFile.DoesNodeExist(collection, parent, newNodeName)) { throw new ExistsException(newNodeName); } if (Directory.Exists(oldname)) { Directory.Move(oldname, newname); } else { Directory.CreateDirectory(newname); } string oldRelativePath = dn.GetRelativePath(); string relativePath = oldRelativePath.Remove(oldRelativePath.Length - node.Name.Length, node.Name.Length) + newNodeName; node.Properties.ModifyNodeProperty(new Property(PropertyTags.FileSystemPath, Syntax.String, relativePath)); node.Name = newNodeName; node = RemoveNameConflict(collection, node); collection.Commit(node); FileWatcher.RenameDirsChildren(collection, dn, oldRelativePath); } else { // The name did not change. if (Directory.Exists(oldname)) { Directory.Move(oldname, newname); } else { Directory.CreateDirectory(newname); } node = RemoveNameConflict(collection, node); collection.Commit(node); } } } }
public static void AddOneFile(DirNode dirNode, string fileName, long fileSizeInKB, FileAttributes? fa = null, DateTime? lmt = null) { AddOneFileInBytes(dirNode, fileName, 1024L * fileSizeInKB, fa, lmt); }
public void DirectoryShouldTransfer() { // Prepare data int totaFileNumber = DMLibTestConstants.FlatFileCount; int expectedTransferred = totaFileNumber, transferred = 0; int expectedSkipped = 0, skipped = 0; int expectedFailed = 0, failed = 0; DMLibDataInfo sourceDataInfo = this.GenerateSourceDataInfo(FileNumOption.FlatFolder, 1024); DirectoryTransferContext dirTransferContext = new DirectoryTransferContext(); List <String> notTransferredFileNames = new List <String>(); dirTransferContext.ShouldTransferCallbackAsync = async(source, dest) => { if (Helper.RandomBoolean()) { return(true); } else { Interlocked.Decrement(ref expectedTransferred); string fullName = DMLibTestHelper.TransferInstanceToString(source); string fileName = fullName.Substring(fullName.IndexOf(DMLibTestBase.FileName)); lock (notTransferredFileNames) { notTransferredFileNames.Add(fileName); } Test.Info("{0} is filterred in ShouldTransfer.", fileName); return(false); } }; dirTransferContext.FileTransferred += (object sender, TransferEventArgs args) => { Interlocked.Increment(ref transferred); }; dirTransferContext.FileSkipped += (object sender, TransferEventArgs args) => { Interlocked.Increment(ref skipped); }; dirTransferContext.FileFailed += (object sender, TransferEventArgs args) => { Interlocked.Increment(ref failed); }; var options = new TestExecutionOptions <DMLibDataInfo>(); options.IsDirectoryTransfer = true; options.TransferItemModifier = (fileNode, transferItem) => { transferItem.TransferContext = dirTransferContext; dynamic transferOptions = DefaultTransferDirectoryOptions; transferOptions.Recursive = true; transferItem.Options = transferOptions; }; // Execute test case var result = this.ExecuteTestCase(sourceDataInfo, options); // Verify result DMLibDataInfo expectedDataInfo = sourceDataInfo.Clone(); DirNode expectedRootNode = expectedDataInfo.RootNode; foreach (string fileNames in notTransferredFileNames) { expectedRootNode.DeleteFileNode(fileNames); } VerificationHelper.VerifyTransferSucceed(result, expectedDataInfo); Test.Assert(expectedTransferred == transferred, string.Format("Verify transferred number. Expected: {0}, Actual: {1}", expectedTransferred, transferred)); Test.Assert(expectedSkipped == skipped, string.Format("Verify skipped number. Expected: {0}, Actual: {1}", expectedSkipped, skipped)); Test.Assert(expectedFailed == failed, string.Format("Verify failed number. Expected: {0}, Actual: {1}", expectedFailed, failed)); }
public static void RemoveAllFileNodesExcept(DirNode rootNode, HashSet<FileNode> except) { List<FileNode> nodesToRemove = new List<FileNode>(); foreach (FileNode fileNode in rootNode.EnumerateFileNodesRecursively()) { if (!except.Contains(fileNode)) { nodesToRemove.Add(fileNode); } } foreach(FileNode nodeToRemove in nodesToRemove) { nodeToRemove.Parent.DeleteFileNode(nodeToRemove.Name); } }
public DirNode Clone(DirNode parent) { return new DirNode(_folderInfo, parent, new Dictionary<Name, FsFile<Name>>(_files)); }
public DirNode(FsFolder<Name> dirInfo, DirNode parent, Dictionary<Name, FsFile<Name>> files) { _folderInfo = dirInfo; _parent = parent; _directories = new Dictionary<Name, DirNode>(); _files = files; }
private void TestDirectorySetAttribute_Restart( int bigFileSizeInKB, int smallFileSizeInKB, int bigFileNum, int smallFileNum, Action <DirNode> bigFileDirAddFileAction, Action <DirNode> smallFileDirAddFileAction, SetAttributesCallbackAsync setAttributesCallback = null, Action <DMLibDataInfo> sourceDataInfoDecorator = null) { int totalFileNum = bigFileNum + smallFileNum; long totalSizeInBytes = ((bigFileSizeInKB * bigFileNum) + (smallFileSizeInKB * smallFileNum)) * 1024; DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); DirNode bigFileDirNode = new DirNode("big"); DirNode smallFileDirNode = new DirNode("small"); sourceDataInfo.RootNode.AddDirNode(bigFileDirNode); sourceDataInfo.RootNode.AddDirNode(smallFileDirNode); bigFileDirAddFileAction(bigFileDirNode); smallFileDirAddFileAction(smallFileDirNode); CancellationTokenSource tokenSource = new CancellationTokenSource(); TransferItem transferItem = null; var options = new TestExecutionOptions <DMLibDataInfo> { LimitSpeed = true, IsDirectoryTransfer = true }; using (Stream journalStream = new MemoryStream()) { bool isStreamJournal = random.Next(0, 2) == 0; var transferContext = isStreamJournal ? new DirectoryTransferContext(journalStream) : new DirectoryTransferContext(); transferContext.SetAttributesCallbackAsync = setAttributesCallback; var progressChecker = new ProgressChecker(totalFileNum, totalSizeInBytes, totalFileNum, null, 0, totalSizeInBytes); transferContext.ProgressHandler = progressChecker.GetProgressHandler(); var eventChecker = new TransferEventChecker(); eventChecker.Apply(transferContext); transferContext.FileFailed += (sender, e) => { Helper.VerifyCancelException(e.Exception); }; options.TransferItemModifier = (fileName, item) => { dynamic dirOptions = DefaultTransferDirectoryOptions; dirOptions.Recursive = true; item.Options = dirOptions; item.CancellationToken = tokenSource.Token; item.TransferContext = transferContext; transferItem = item; }; TransferCheckpoint firstCheckpoint = null, secondCheckpoint = null; options.AfterAllItemAdded = () => { // Wait until there are data transferred progressChecker.DataTransferred.WaitOne(); if (!isStreamJournal) { // Store the first checkpoint firstCheckpoint = transferContext.LastCheckpoint; } Thread.Sleep(1000); // Cancel the transfer and store the second checkpoint tokenSource.Cancel(); }; // Cancel and store checkpoint for resume var result = this.ExecuteTestCase(sourceDataInfo, options); if (progressChecker.FailedFilesNumber <= 0) { Test.Error("Verify file number in progress. Failed: {0}", progressChecker.FailedFilesNumber); } TransferCheckpoint firstResumeCheckpoint = null, secondResumeCheckpoint = null; if (!isStreamJournal) { secondCheckpoint = transferContext.LastCheckpoint; Test.Info("Resume with the second checkpoint first."); firstResumeCheckpoint = secondCheckpoint; secondResumeCheckpoint = firstCheckpoint; } // resume with firstResumeCheckpoint TransferItem resumeItem = transferItem.Clone(); progressChecker.Reset(); TransferContext resumeContext = null; if (isStreamJournal) { resumeContext = new DirectoryTransferContext(journalStream) { ProgressHandler = progressChecker.GetProgressHandler() }; } else { resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(firstResumeCheckpoint)) { ProgressHandler = progressChecker.GetProgressHandler() }; } resumeContext.SetAttributesCallbackAsync = setAttributesCallback; eventChecker.Reset(); eventChecker.Apply(resumeContext); resumeItem.TransferContext = resumeContext; result = this.RunTransferItems(new List <TransferItem>() { resumeItem }, new TestExecutionOptions <DMLibDataInfo>()); sourceDataInfoDecorator?.Invoke(sourceDataInfo); VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0); VerificationHelper.VerifySingleTransferStatus(result, totalFileNum, 0, 0, totalSizeInBytes); VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo); if (!isStreamJournal) { // resume with secondResumeCheckpoint resumeItem = transferItem.Clone(); progressChecker.Reset(); resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(secondResumeCheckpoint)) { ProgressHandler = progressChecker.GetProgressHandler(), // Need this overwrite callback since some files is already transferred to destination ShouldOverwriteCallbackAsync = DMLibInputHelper.GetDefaultOverwiteCallbackY(), SetAttributesCallbackAsync = setAttributesCallback }; eventChecker.Reset(); eventChecker.Apply(resumeContext); resumeItem.TransferContext = resumeContext; result = this.RunTransferItems(new List <TransferItem>() { resumeItem }, new TestExecutionOptions <DMLibDataInfo>()); VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0); VerificationHelper.VerifySingleTransferStatus(result, totalFileNum, 0, 0, totalSizeInBytes); VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo); } } }
public static bool Equals(DirNode dirNodeA, DirNode dirNodeB) { // The same node if (dirNodeA == dirNodeB) { return true; } // Empty node equals to null if ((dirNodeA == null || dirNodeA.IsEmpty) && (dirNodeB == null || dirNodeB.IsEmpty)) { return true; } // Compare two nodes if (null != dirNodeA && null != dirNodeB) { if (dirNodeA.FileNodeCount != dirNodeB.FileNodeCount || dirNodeA.NonEmptyDirNodeCount != dirNodeB.NonEmptyDirNodeCount) { return false; } foreach(FileNode fileNodeA in dirNodeA.FileNodes) { FileNode fileNodeB = dirNodeB.GetFileNode(fileNodeA.Name); if (!DMLibDataHelper.Equals(fileNodeA, fileNodeB)) { return false; } } foreach(DirNode subDirNodeA in dirNodeA.DirNodes) { DirNode subDirNodeB = dirNodeB.GetDirNode(subDirNodeA.Name); if (!DMLibDataHelper.Equals(subDirNodeA, subDirNodeB)) { return false; } } return true; } return false; }
private static void PrepareSourceData() { DMLibDataInfo sourceFileTree = new DMLibDataInfo(string.Empty); DirNode dirNode1 = new DirNode("folder1"); DirNode subDir1 = new DirNode("subfolder1"); subDir1.AddDirNode(new DirNode("subfolder3")); subDir1.AddFileNode(GenerateFileNode("testfile2")); subDir1.AddFileNode(GenerateFileNode("4testfile")); dirNode1.AddDirNode(subDir1); DirNode subDir2 = new DirNode("subfolder2"); DirNode subDir4 = new DirNode("subfolder4"); subDir4.AddFileNode(GenerateFileNode("test5")); subDir2.AddDirNode(subDir4); subDir2.AddFileNode(GenerateFileNode("TESTFILE345")); subDir2.AddFileNode(GenerateFileNode("testYfile")); subDir2.AddFileNode(GenerateFileNode("f_arbitrary.exe")); subDir2.AddFileNode(GenerateFileNode("测试x文件")); dirNode1.AddDirNode(subDir2); dirNode1.AddFileNode(GenerateFileNode("testfile1")); dirNode1.AddFileNode(GenerateFileNode("TestFile2")); dirNode1.AddFileNode(GenerateFileNode("测试文件2")); sourceFileTree.RootNode.AddDirNode(dirNode1); DirNode dirNode2 = new DirNode("folder2"); dirNode2.AddFileNode(GenerateFileNode("folder_file")); dirNode2.AddDirNode(new DirNode("testfile1")); dirNode2.AddFileNode(GenerateFileNode("测试文件三")); dirNode2.AddFileNode(GenerateFileNode("测试四文件")); sourceFileTree.RootNode.AddDirNode(dirNode2); DirNode dirNode3 = new DirNode("folder3"); sourceFileTree.RootNode.AddDirNode(dirNode3); sourceFileTree.RootNode.AddFileNode(GenerateFileNode("testfile")); sourceFileTree.RootNode.AddFileNode(GenerateFileNode("testfile1")); sourceFileTree.RootNode.AddFileNode(GenerateFileNode("testfile2")); sourceFileTree.RootNode.AddFileNode(GenerateFileNode("testXfile")); sourceFileTree.RootNode.AddFileNode(GenerateFileNode("testXXfile")); sourceFileTree.RootNode.AddFileNode(GenerateFileNode("测试文件")); sourceFileTree.RootNode.AddFileNode(GenerateFileNode("..a123")); DMLibDataInfo blobSourceFileTree = sourceFileTree.Clone(); blobSourceFileTree.RootNode.AddFileNode(GenerateFileNode("TeSTfIle")); Test.Info("Start to generate test data, will take a while..."); foreach (DMLibDataType dataType in sourceDataTypes) { if (IsCloudBlob(dataType)) { PrepareSourceData(dataType, blobSourceFileTree.Clone()); } else { PrepareSourceData(dataType, sourceFileTree.Clone()); } } Test.Info("Done"); }
public static FileNode RemoveOneFile(DirNode dirNode, string fileName) { return dirNode.DeleteFileNode(fileName); }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { //Find which direction to shoot the new bullet if (DirNode != null) { //get the direction continade in the node float newBulletDirection = (int)DirNode.GetValue(this) * (float)Math.PI / (float)180; switch (DirNode.NodeType) { case ENodeType.sequence: { bullet.GetFireData().srcDir += newBulletDirection; } break; case ENodeType.absolute: { bullet.GetFireData().srcDir = newBulletDirection; } break; case ENodeType.relative: { bullet.GetFireData().srcDir = newBulletDirection + bullet.Direction; } break; default: { bullet.GetFireData().srcDir = newBulletDirection + bullet.GetAimDir(); } break; } } else { //otherwise if no direction node, aim the bullet at the bad guy bullet.GetFireData().srcDir = bullet.GetAimDir(); } //Create the new bullet Bullet newBullet = bullet.MyBulletManager.CreateBullet(); if (newBullet == null) { //wtf did you do??? TaskFinished = true; return(ERunStatus.End); } //initialize the bullet from a reference node, or our bullet node if (RefNode != null) { //Add an empty task to the bullet and populate it with all the params BulletMLTask bulletBlankTask = newBullet.CreateTask(); //Add all the params to the new task we just added to that bullet for (int i = 0; i < RefNode.ChildNodes.Count; i++) { bulletBlankTask.ParamList.Add(RefNode.ChildNodes[i].GetValue(this)); } //init the bullet now that all our stuff is prepopulated BulletMLNode subNode = bullet.MyNode.GetRootNode().FindLabelNode(RefNode.Label, ENodeName.bullet); newBullet.Init(subNode); } else { //if there is no ref node, there has to be bullet node newBullet.Init(BulletNode); } //set the location of the new bullet newBullet.X = bullet.X; newBullet.Y = bullet.Y; //set the owner of the new bullet to this dude newBullet._tasks[0].Owner = this; //set the direction of the new bullet newBullet.Direction = bullet.GetFireData().srcDir; //Has the speed for new bullets been set in the source bullet yet? if (!bullet.GetFireData().speedInit&& newBullet.GetFireData().speedInit) { bullet.GetFireData().srcSpeed = newBullet.Velocity; bullet.GetFireData().speedInit = true; } else { //find the speed for new bullets and store it in the source bullet if (SpeedNode != null) { //Get the speed from a speed node float newBulletSpeed = SpeedNode.GetValue(this); if (SpeedNode.NodeType == ENodeType.sequence || SpeedNode.NodeType == ENodeType.relative) { bullet.GetFireData().srcSpeed += newBulletSpeed; } else { bullet.GetFireData().srcSpeed = newBulletSpeed; } } else { if (!newBullet.GetFireData().speedInit) { bullet.GetFireData().srcSpeed = 1; } else { bullet.GetFireData().srcSpeed = newBullet.Velocity; } } } newBullet.GetFireData().speedInit = false; newBullet.Velocity = bullet.GetFireData().srcSpeed; TaskFinished = true; return(ERunStatus.End); }
public static DirNode RemoveOneDir(DirNode parentNode, string dirNodeToDelete) { return parentNode.DeleteDirNode(dirNodeToDelete); }
public void TestDirectoryWithSpecialCharNamedBlobs() { #if DNXCORE50 // TODO: There's a known issue that signature for URI with '[' or ']' doesn't work. string specialChars = "~`!@#$%()-_+={};?.^&"; #else string specialChars = "~`!@#$%()-_+={}[];?.^&"; #endif DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); var subDirWithDot = new DirNode(DMLibTestBase.FolderName + "." + DMLibTestBase.FolderName); for (int i = 0; i < specialChars.Length; ++i) { string fileName = DMLibTestBase.FileName + specialChars[i] + DMLibTestBase.FileName; if (random.Next(2) == 0) { if ((specialChars[i] != '.') && (random.Next(2) == 0)) { string folderName = DMLibTestBase.FolderName + specialChars[i] + DMLibTestBase.FolderName; var subDir = new DirNode(folderName); DMLibDataHelper.AddOneFileInBytes(subDir, fileName, 1024); FileNode fileNode1 = subDir.GetFileNode(fileName); fileNode1.SnapshotsCount = 1; sourceDataInfo.RootNode.AddDirNode(subDir); } else { DMLibDataHelper.AddOneFileInBytes(subDirWithDot, fileName, 1024); FileNode fileNode1 = subDirWithDot.GetFileNode(fileName); fileNode1.SnapshotsCount = 1; } } else { DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, fileName, 1024); FileNode fileNode1 = sourceDataInfo.RootNode.GetFileNode(fileName); fileNode1.SnapshotsCount = 1; } } sourceDataInfo.RootNode.AddDirNode(subDirWithDot); var options = new TestExecutionOptions <DMLibDataInfo>(); options.IsDirectoryTransfer = true; // transfer with IncludeSnapshots = true options.TransferItemModifier = (fileNode, transferItem) => { dynamic dirOptions = DefaultTransferDirectoryOptions; dirOptions.Recursive = true; dirOptions.IncludeSnapshots = true; transferItem.Options = dirOptions; }; var result = this.ExecuteTestCase(sourceDataInfo, options); // verify that snapshots are transferred Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown."); Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result."); }
public static void AddMultipleFiles(DirNode dirNode, string filePrefix, int fileNumber, int fileSizeInKB, FileAttributes? fa = null, DateTime? lmt = null) { DMLibDataHelper.AddTree(dirNode, string.Empty, filePrefix, fileNumber, 0, fileSizeInKB, fa, lmt); }
/// <summary> /// Get iFolder Entries by Name /// </summary> /// <param name="ifolderID">The ID of the iFolder.</param> /// <param name="parentID">The ID of the Parent Entry.</param> /// <param name="operation">The Search Operation</param> /// <param name="pattern">The Search Pattern</param> /// <param name="index">The Search Start Index</param> /// <param name="max">The Search Max Count of Results</param> /// <param name="accessID">The Access User ID.</param> /// <returns>A Set of iFolderEntry Objects</returns> public static iFolderEntrySet GetEntriesByName(string ifolderID, string parentID, SearchOperation operation, string pattern, int index, int max, string accessID) { Store store = Store.GetStore(); Collection c = store.GetCollectionByID(ifolderID); if (c == null) { throw new iFolderDoesNotExistException(ifolderID); } // impersonate iFolder.Impersonate(c, accessID); // path string path; if ((parentID == null) || ifolderID.Equals(parentID)) { path = c.Name + "/"; } else { Node n = c.GetNodeByID(parentID); DirNode dirNode = (DirNode)DirNode.NodeFactory(c, n); path = dirNode.GetRelativePath() + "/"; } // match the pattern Regex regex = null; if ((pattern != null) && (pattern.Length > 0)) { switch (operation) { case SearchOperation.BeginsWith: pattern = "^" + pattern; break; case SearchOperation.EndsWith: pattern = pattern + "$"; break; case SearchOperation.Equals: pattern = "^" + pattern + "$"; break; case SearchOperation.Contains: default: break; } regex = new Regex(pattern, RegexOptions.IgnoreCase); } // find children deep ICSList children = c.Search(PropertyTags.FileSystemPath, path, SearchOp.Begins); // sort the list ArrayList sortList = new ArrayList(); foreach (ShallowNode sn in children) { if ((regex == null) || regex.Match(sn.Name).Success) { sortList.Add(sn); } } sortList.Sort(new EntryComparer()); // build the result list ArrayList list = new ArrayList(); int i = 0; foreach (ShallowNode sn in sortList) { if (sn.IsBaseType(NodeTypes.FileNodeType) || sn.IsBaseType(NodeTypes.DirNodeType)) { if ((i >= index) && (((max <= 0) || i < (max + index)))) { Node n = c.GetNodeByID(sn.ID); list.Add(iFolderEntry.GetEntry(c, n)); } ++i; } } return(new iFolderEntrySet((iFolderEntry[])list.ToArray(typeof(iFolderEntry)), i)); }
public void TestDirectoryResume() { int bigFileSizeInKB = 5 * 1024; // 5 MB int smallFileSizeInKB = 1; // 1 KB int bigFileNum = 5; int smallFileNum = 50; long totalSizeInBytes = (bigFileSizeInKB * bigFileNum + smallFileSizeInKB * smallFileNum) * 1024; int totalFileNum = bigFileNum + smallFileNum; DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); DirNode bigFileDirNode = new DirNode("big"); DirNode smallFileDirNode = new DirNode("small"); sourceDataInfo.RootNode.AddDirNode(bigFileDirNode); sourceDataInfo.RootNode.AddDirNode(smallFileDirNode); DMLibDataHelper.AddMultipleFiles(bigFileDirNode, FileName, bigFileNum, bigFileSizeInKB); DMLibDataHelper.AddMultipleFiles(smallFileDirNode, FileName, smallFileNum, smallFileSizeInKB); CancellationTokenSource tokenSource = new CancellationTokenSource(); TransferItem transferItem = null; var options = new TestExecutionOptions<DMLibDataInfo>(); options.LimitSpeed = true; options.IsDirectoryTransfer = true; var transferContext = new TransferContext(); var progressChecker = new ProgressChecker(totalFileNum, totalSizeInBytes, totalFileNum, null, 0, totalSizeInBytes); transferContext.ProgressHandler = progressChecker.GetProgressHandler(); var eventChecker = new TransferEventChecker(); eventChecker.Apply(transferContext); transferContext.FileFailed += (sender, e) => { Test.Assert(e.Exception.Message.Contains("cancel"), "Verify task is canceled: {0}", e.Exception.Message); }; options.TransferItemModifier = (fileName, item) => { dynamic dirOptions = DefaultTransferDirectoryOptions; dirOptions.Recursive = true; item.Options = dirOptions; item.CancellationToken = tokenSource.Token; item.TransferContext = transferContext; transferItem = item; }; TransferCheckpoint firstCheckpoint = null, secondCheckpoint = null; options.AfterAllItemAdded = () => { // Wait until there are data transferred progressChecker.DataTransferred.WaitOne(); // Store the first checkpoint firstCheckpoint = transferContext.LastCheckpoint; Thread.Sleep(1000); // Cancel the transfer and store the second checkpoint tokenSource.Cancel(); }; // Cancel and store checkpoint for resume var result = this.ExecuteTestCase(sourceDataInfo, options); secondCheckpoint = transferContext.LastCheckpoint; if (progressChecker.FailedFilesNumber <= 0) { Test.Error("Verify file number in progress. Failed: {0}", progressChecker.FailedFilesNumber); } TransferCheckpoint firstResumeCheckpoint = null, secondResumeCheckpoint = null; Test.Info("Resume with the second checkpoint first."); firstResumeCheckpoint = secondCheckpoint; secondResumeCheckpoint = firstCheckpoint; // resume with firstResumeCheckpoint TransferItem resumeItem = transferItem.Clone(); progressChecker.Reset(); TransferContext resumeContext = new TransferContext(DMLibTestHelper.RandomReloadCheckpoint(firstResumeCheckpoint)) { ProgressHandler = progressChecker.GetProgressHandler() }; eventChecker.Reset(); eventChecker.Apply(resumeContext); resumeItem.TransferContext = resumeContext; result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>()); VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0); VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo); // resume with secondResumeCheckpoint resumeItem = transferItem.Clone(); progressChecker.Reset(); resumeContext = new TransferContext(DMLibTestHelper.RandomReloadCheckpoint(secondResumeCheckpoint)) { ProgressHandler = progressChecker.GetProgressHandler(), // Need this overwrite callback since some files is already transferred to destination OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY(), }; eventChecker.Reset(); eventChecker.Apply(resumeContext); resumeItem.TransferContext = resumeContext; result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>()); VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0); VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo); }
/// <summary> /// process and send the reply for request /// </summary> /// <param name="Context">httpcontext object</param> public void Send(HttpContext Context) { ctx = Context; ctx.Response.Write("<item>"); FileNode fileNode = null; ctx.Response.Write("<title>"); if (node.IsType("Member") == true) { Member collectionMember = new Member(node); ctx.Response.Write(" - " + collectionMember.FN); } else if (node.IsType("FileNode") == true) { fileNode = new FileNode(node); ctx.Response.Write(fileNode.GetFileName()); } else { ctx.Response.Write(node.Name); } ctx.Response.Write("</title>"); ctx.Response.Write("<guid isPermaLink=\"false\">" + node.ID + "</guid>"); Simias.RssFeed.Util.SendPublishDate(ctx, published); if (node.IsType("Member") == true) { Member collectionMember = new Member(node); ctx.Response.Write("<description>"); ctx.Response.Write(" - " + collectionMember.FN); ctx.Response.Write("</description>"); ctx.Response.Write("<type>Member</type>"); } else if (node.IsType("FileNode") == true) { fileNode = new FileNode(node); ctx.Response.Write("<description>"); ctx.Response.Write(fileNode.GetRelativePath()); ctx.Response.Write("</description>"); /* * ctx.Response.Write( * String.Format( * "<link>{0}{1}:{2}{3}/sfile.ashx?fid={4}{5}</link>", * ctx.Request.IsSecureConnection ? "https://" : "http://", * ctx.Request.Url.Host, * ctx.Request.Url.Port.ToString(), * ctx.Request.ApplicationPath, * fileNode.ID, * HttpUtility.UrlEncode( "&name=" + fileNode.Name ) ) ); */ ctx.Response.Write( String.Format( "<link>{0}{1}:{2}{3}{4}?fid={5}</link>", ctx.Request.IsSecureConnection ? "https://" : "http://", ctx.Request.Url.Host, ctx.Request.Url.Port.ToString(), ctx.Request.ApplicationPath, (publicAccess == true) ? "/pubsfile.ashx" : "/sfile.ashx", fileNode.ID)); if (enclosures == true) { ctx.Response.Write( String.Format( "<enclosure url=\"{0}{1}:{2}{3}{4}?fid={5}\" length=\"{6}\" type=\"{7}\"/>", ctx.Request.IsSecureConnection ? "https://" : "http://", ctx.Request.Url.Host, ctx.Request.Url.Port.ToString(), ctx.Request.ApplicationPath, (publicAccess == true) ? "/pubsfile.ashx" : "/sfile.ashx", node.ID, fileNode.Length, Simias.HttpFile.Response.GetMimeType(fileNode.GetFileName()))); } } else if (node.IsType("DirNode") == true) { DirNode dirNode = new DirNode(node); ctx.Response.Write("<description>"); ctx.Response.Write(dirNode.GetRelativePath()); ctx.Response.Write("</description>"); } Domain domain = store.GetDomain(store.DefaultDomain); Member member = domain.GetMemberByID(node.Creator); if (member != null) { ctx.Response.Write("<author>"); if (member.FN != null && member.FN != "") { ctx.Response.Write(member.FN); } else { ctx.Response.Write(member.Name); } ctx.Response.Write("</author>"); } if (strict == false) { ctx.Response.Write("<authorID>" + member.UserID + "</authorID>"); ctx.Response.Write("<type>" + node.Type.ToString() + "</type>"); ctx.Response.Write("<id>" + node.ID + "</id>"); } // Category - use tags and types /* * if (slog.Generator != "") * { * ctx.Response.Write("<generator>"); * ctx.Response.Write(slog.Generator); * ctx.Response.Write("</generator>"); * } * * if (slog.Cloud != "") * { * ctx.Response.Write("<cloud>"); * ctx.Response.Write(slog.Cloud); * ctx.Response.Write("</cloud>"); * } */ ctx.Response.Write("</item>"); }
public static void AddMultipleFilesBigSize(DirNode dirNode, string filePrefix) { int[] fileSizes = new int[] { 32000, 64 * 1024 }; AddMultipleFilesDifferentSize(dirNode, filePrefix, fileSizes); }
/* * Recursively scans all subdirectories */ private List <Tree.TreeNode> fullScan(string dir, int level) { if (scanCanceled) { return(null); } List <Tree.TreeNode> json, res; Tree.TreeNode node; DirectoryInfo list; string pad; json = new List <Tree.TreeNode>(); list = new DirectoryInfo(dir); // get all dir/files list pad = getPadding(level); DirectoryInfo[] dirList = list.GetDirectories(); // only dirs if (level == 0) { rootDirCount = getDirCount(dirList.Length); } foreach (DirectoryInfo nextDir in dirList) // ||= loop directories =|| { string name = nextDir.Name; string currentDir = "[" + name + "]"; if (level == 0) { if (!filterDirectory(name)) { continue; } updateStatusBar("scanning", currentDir); } if (doExportText) { text += pad + currentDir + nl; // accumulate text structure } res = fullScan(nextDir.FullName, level + 1); // recursive point if (res == null) { return(null); } node = new DirNode(name, res); json.Add(node); // accumulate recursive tree structure if (level == 0) // update progress status for scanned top-level directories { dirCount++; int progress = (int)((float)dirCount / rootDirCount * 100); logStats(currentDir, progress); Functions.setProgress(progress); } } foreach (FileInfo nextFile in list.GetFiles()) // ||= loop files =|| { string name = nextFile.Name; if (!filterFile(name)) { continue; } string currentFile = name; if (doExportText) { text += pad + currentFile + nl; } node = new FileNode(name, getIcon(name)); json.Add(node); } return(json); }
public DirNode(Name name, DirNode parent) { _folderInfo = new FsFolder<Name>(name); _parent = parent; _directories = new Dictionary<Name, DirNode>(); _files = new Dictionary<Name, FsFile<Name>>(); }
private static void PrepareDirSourceData(long fileSizeInB) { foreach (DMLibTransferDirection direction in GetAllDirectoryValidDirections()) { string dirName = GetTransferDirName(direction); string fileName = dirName; string sourceDataInfoKey = GetSourceDataInfoKey(direction); DMLibDataInfo sourceDataInfo = GetSourceDataInfo(sourceDataInfoKey); DirNode subDirNode = new DirNode(dirName); DMLibDataHelper.AddOneFileInBytes(subDirNode, fileName, fileSizeInB); sourceDataInfo.RootNode.AddDirNode(subDirNode); directoryNodes.Add(dirName, subDirNode); expectedFileNodes.Add(fileName, subDirNode.GetFileNode(fileName)); } }
public static void AddMultipleFilesTotalSize(DirNode dirNode, string filePrefix, int fileNumber, int totalSizeInKB, DateTime? lmt = null) { int fileSizeInKB = totalSizeInKB / fileNumber; fileSizeInKB = fileSizeInKB == 0 ? 1 : fileSizeInKB; DMLibDataHelper.AddMultipleFiles(dirNode, filePrefix, fileNumber, fileSizeInKB, lmt: lmt); }
public abstract object GetTransferObject(string rootPath, DirNode dirNode);
public FileTree(IPath relativeTo) { _relativeTo = relativeTo; _rootDirectory = new DirNode(relativeTo.FileName(), null); }
public void TestDirectoryCheckContentMD5() { long fileSize = 5 * 1024 * 1024; long totalSize = fileSize * 4; string wrongMD5 = "wrongMD5"; string checkWrongMD5File = "checkWrongMD5File"; string checkCorrectMD5File = "checkCorrectMD5File"; string notCheckWrongMD5File = "notCheckWrongMD5File"; string notCheckCorrectMD5File = "notCheckCorrectMD5File"; DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); DirNode checkMD5Folder = new DirNode("checkMD5"); DMLibDataHelper.AddOneFileInBytes(checkMD5Folder, checkWrongMD5File, fileSize); DMLibDataHelper.AddOneFileInBytes(checkMD5Folder, checkCorrectMD5File, fileSize); sourceDataInfo.RootNode.AddDirNode(checkMD5Folder); DirNode notCheckMD5Folder = new DirNode("notCheckMD5"); DMLibDataHelper.AddOneFileInBytes(notCheckMD5Folder, notCheckWrongMD5File, fileSize); DMLibDataHelper.AddOneFileInBytes(notCheckMD5Folder, notCheckCorrectMD5File, fileSize); sourceDataInfo.RootNode.AddDirNode(notCheckMD5Folder); FileNode tmpFileNode = checkMD5Folder.GetFileNode(checkWrongMD5File); tmpFileNode.MD5 = wrongMD5; tmpFileNode = notCheckMD5Folder.GetFileNode(notCheckWrongMD5File); tmpFileNode.MD5 = wrongMD5; SourceAdaptor.GenerateData(sourceDataInfo); TransferEventChecker eventChecker = new TransferEventChecker(); TransferContext context = new TransferContext(); eventChecker.Apply(context); bool failureReported = false; context.FileFailed += (sender, args) => { if (args.Exception != null) { failureReported = args.Exception.Message.Contains(checkWrongMD5File); } }; ProgressChecker progressChecker = new ProgressChecker(4, totalSize, 3, 1, 0, totalSize); context.ProgressHandler = progressChecker.GetProgressHandler(); TransferItem checkMD5Item = new TransferItem() { SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), DestObject = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder), IsDirectoryTransfer = true, SourceType = DMLibTestContext.SourceType, DestType = DMLibTestContext.DestType, IsServiceCopy = DMLibTestContext.IsAsync, TransferContext = context, Options = new DownloadDirectoryOptions() { DisableContentMD5Validation = false, Recursive = true, }, }; TransferItem notCheckMD5Item = new TransferItem() { SourceObject = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, notCheckMD5Folder), DestObject = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, notCheckMD5Folder), IsDirectoryTransfer = true, SourceType = DMLibTestContext.SourceType, DestType = DMLibTestContext.DestType, IsServiceCopy = DMLibTestContext.IsAsync, TransferContext = context, Options = new DownloadDirectoryOptions() { DisableContentMD5Validation = true, Recursive = true, }, }; var testResult = this.RunTransferItems(new List<TransferItem>() { checkMD5Item, notCheckMD5Item }, new TestExecutionOptions<DMLibDataInfo>()); DMLibDataInfo expectedDataInfo = sourceDataInfo.Clone(); expectedDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode(checkWrongMD5File); expectedDataInfo.RootNode.GetDirNode(notCheckMD5Folder.Name).DeleteFileNode(notCheckWrongMD5File); DMLibDataInfo actualDataInfo = testResult.DataInfo; actualDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode(checkWrongMD5File); actualDataInfo.RootNode.GetDirNode(notCheckMD5Folder.Name).DeleteFileNode(notCheckWrongMD5File); Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, actualDataInfo), "Verify transfer result."); Test.Assert(failureReported, "Verify md5 check failure is reported."); VerificationHelper.VerifyFinalProgress(progressChecker, 3, 0, 1); if (testResult.Exceptions.Count != 1) { Test.Error("Expect one exception but actually no exception is thrown."); } else { VerificationHelper.VerifyTransferException(testResult.Exceptions[0], TransferErrorCode.SubTransferFails, "1 sub transfer(s) failed."); } }
public override object GetTransferObject(string rootPath, DirNode dirNode) { throw new InvalidOperationException("Can't get directory transfer object in URI data adaptor."); }
public static void AddMultipleFilesNormalSize(DirNode dirNode, string filePrefix) { int[] fileSizes = new int[] { 0, 1, 4000, 4 * 1024, 10000 }; AddMultipleFilesDifferentSize(dirNode, filePrefix, fileSizes); }
public void AddDirNode(Name newName, DirNode node) { node._folderInfo = node._folderInfo.WithNewPath(newName); node._parent = this; _directories.Add(newName, node); }