// May throw System.SystemException private void PopuplateDirectory(BackupPlanPathNode pathNode) { //Assert.AreEqual(EntryType.FOLDER, pathNode.Type); if (pathNode.Type != EntryType.DRIVE && pathNode.Type != EntryType.FOLDER) { throw new ArgumentException("Unexpected EntryType", "pathNode.Type"); } foreach (var subNode in pathNode.SubNodes) { if (subNode.Type != EntryType.FOLDER) { continue; } BackupPlanTreeNode subFolderNode = AddFolderNode(subNode); } foreach (var subNode in pathNode.SubNodes) { if (subNode.Type != EntryType.FILE) { continue; } BackupPlanTreeNode subFolderNode = AddFileNode(subNode); } }
// May throw System.SystemException private void PopulateFile(BackupPlanPathNode pathNode) { Assert.AreEqual(EntryType.FILE, pathNode.Type); #if true BackupedFileRepository dao = new BackupedFileRepository(); IList <BackupedFile> backupedFiles = dao.GetCompletedByStorageAccountAndPath(pathNode.StorageAccount, pathNode.Path); IEnumerable <IFileVersion> versions = from f in backupedFiles select new FileVersion { Name = f.VersionName, Version = f.Version }; #else // *** DO NOT USE THIS APPROACH BECAUSE IT WILL NOT SHOW A BACKUP VERSION THAT HAS JUST BEEN CREATED! *** // I know it's a problem related to the NHibernate caching mechanism, but I don't want to deal with it right now. Sorry! :-) IList <BackupedFile> backupedFiles = pathNode.PlanFile.Versions; IEnumerable <IFileVersion> versions = from f in backupedFiles where f.TransferStatus == Storage.TransferStatus.COMPLETED select new FileVersion { Name = f.Backup.VersionName, Version = f.Backup.Version }; #endif foreach (IFileVersion version in versions) { BackupPlanTreeNode versionNode = AddFileVersionNode(pathNode, version); } }
// May throw System.SystemException public override void OnExpand() { RemoveLazyLoadingNode(); BackupPlanPathNode pathNode = Data.UserObject as BackupPlanPathNode; switch (Data.Type) { default: break; case TypeEnum.FOLDER: if (Nodes.Count == 0) { PopuplateDirectory(pathNode); } break; case TypeEnum.FILE: if (Nodes.Count == 0) { PopulateFile(pathNode); } break; case TypeEnum.DRIVE: if (Nodes.Count == 0) { PopulateDrive(pathNode); } break; } }
private void AddDirectory(BackupPlanPathNode node, IFileVersion version) { CancellationToken.ThrowIfCancellationRequested(); // Add all files from this directory. foreach (BackupPlanPathNode subNode in node.SubNodes) { if (subNode.Type != EntryType.FILE) { continue; } AddFile(subNode, version); } // Add all sub-directories recursively. foreach (BackupPlanPathNode subNode in node.SubNodes) { if (subNode.Type != EntryType.FOLDER) { continue; } AddDirectory(subNode, version); } }
private BackupPlanTreeNode AddFileVersionNode(BackupPlanPathNode pathNode, IFileVersion version) { Assert.AreEqual(EntryType.FILE, pathNode.Type); BackupPlanTreeNode node = BackupPlanTreeNode.CreateFileVersionNode(pathNode, version); Nodes.Add(node); return(node); }
private BackupPlanTreeNode AddFolderNode(BackupPlanPathNode pathNode) { Assert.AreEqual(EntryType.FOLDER, pathNode.Type); BackupPlanTreeNode node = BackupPlanTreeNode.CreateFolderNode(pathNode); Nodes.Add(node); return(node); }
private BackupPlanTreeNode AddDriveNode(TreeView view, BackupPlanPathNode pathNode) { Assert.AreEqual(EntryType.DRIVE, pathNode.Type); BackupPlanTreeNode node = BackupPlanTreeNode.CreateDriveNode(pathNode); view.Nodes.Add(node); return(node); }
public static BackupPlanTreeNode CreateFileVersionNode(BackupPlanPathNode pathNode, IFileVersion version) { Assert.AreEqual(EntryType.FILE, pathNode.Type); BackupPlanTreeNode node = new BackupPlanTreeNode(version.Name, 0, 0); node.ImageKey = "file_version"; EntryInfo info = new EntryInfo(TypeEnum.FILE_VERSION, pathNode.Name, pathNode.Path, version); node.Data.InfoObject = info; node.Data.UserObject = pathNode; return(node); }
public static BackupPlanTreeNode CreateFileNode(BackupPlanPathNode pathNode) { Assert.AreEqual(EntryType.FILE, pathNode.Type); BackupPlanTreeNode node = new BackupPlanTreeNode(pathNode.Name, 0, 0); node.ImageKey = "file"; EntryInfo info = new EntryInfo(TypeEnum.FILE, pathNode.Name, pathNode.Path); node.Data.InfoObject = info; node.Data.UserObject = pathNode; node.AddLazyLoadingNode(); return(node); }
private void AddFileVersion(BackupPlanPathNode node, IFileVersion version) { CancellationToken.ThrowIfCancellationRequested(); BackupedFile f = null; // If `version` is not not informed, then find the file's latest version // that has completed transfer. if (version == null) { f = node.PlanFile.Versions.LastOrDefault(v => v.TransferStatus == TransferStatus.COMPLETED); IFileVersion latestFileVersion = f != null && f.Id.HasValue ? new FileVersion { Name = f.VersionName, Version = f.Version } : null; version = latestFileVersion; } else { f = node.PlanFile.Versions.First( p => p.Version.Equals(version.Version, StringComparison.InvariantCulture)); } if (f == null || !f.Id.HasValue) { return; } var item = new CustomVersionedFile { Path = node.Path, Size = f.FileSize, LastWriteTimeUtc = f.FileLastWrittenAt, UserData = f, // Reference the original `BackupedFile`. Version = version, }; Results.Files.AddLast(item); if (FileAdded != null) { FileAdded(this, item); } }
// May throw System.SystemException private void PopulateDrive(BackupPlanPathNode pathNode) { Assert.AreEqual(EntryType.DRIVE, pathNode.Type); PopuplateDirectory(pathNode); }
private void AddFile(BackupPlanPathNode node, IFileVersion version) { AddFileVersion(node, version); }