// Convert collection of `FileSystemTreeView.TreeNodeTag` to `RestorePlanSourceEntry`. public static List <Models.RestorePlanSourceEntry> ToRestorePlanSourceEntry( this Dictionary <string, BackupPlanTreeNodeData> dataDict, Models.RestorePlan plan, RestorePlanSourceEntryRepository dao) { List <Models.RestorePlanSourceEntry> sources = new List <Models.RestorePlanSourceEntry>(dataDict.Count); foreach (var entry in dataDict) { BackupPlanTreeNodeData data = entry.Value; Models.RestorePlanSourceEntry source = null; if (data.Id != null) { source = dao.Get(data.Id as long?); } else { source = new Models.RestorePlanSourceEntry(); } source.RestorePlan = plan; source.Type = data.ToEntryType(); source.Path = data.Path; source.PathNode = data.UserObject as Models.BackupPlanPathNode; if (source.Type == Models.EntryType.FILE_VERSION) { source.Version = data.Version.Version; } sources.Add(source); } return(sources); }
private string BuildNodeKey(BackupPlanTreeNodeData data, IFileVersion version) { switch (data.Type) { default: return(data.Path); case TypeEnum.FILE_VERSION: return(data.Path + (version == null ? string.Empty : "#" + version.Version)); } }
private void BuildTagDataDict(BackupPlanTreeNode node, Dictionary <string, BackupPlanTreeNodeData> dict) { // Skip over loading nodes and nodes without a tag. if (node == null || node.Data.Type == TypeEnum.LOADING) { return; } CheckState state = GetCheckState(node); switch (state) { case CheckState.Unchecked: // If it's unchecked, ignore it and its child nodes. return; case CheckState.Checked: // If it's checked, add it and ignore its child nodes. // This means the entire folder was checked - regardless of what it contains - or // the file itself was checked, and not a specific version. if (CheckedDataSource != null) { string path = node.Data.Path; BackupPlanTreeNodeData match; bool found = dict.TryGetValue(path, out match); match = found ? match : node.Data; match.State = CheckState.Checked; node.Data = match; if (!dict.ContainsKey(match.Path)) { dict.Add(match.Path, match); } } else { BackupPlanTreeNodeData tag = node.Data; tag.State = CheckState.Checked; if (!dict.ContainsKey(tag.Path)) { dict.Add(tag.Path, tag); } } break; case CheckState.Mixed: // Ignore it, but verify its child nodes. foreach (BackupPlanTreeNode child in node.Nodes) { BuildTagDataDict(child, dict); } break; } }
private void ExpandCheckedDataSourceAddParents(Dictionary <string, BackupPlanTreeNodeData> expandedDict, string path) { PathNodes nodes = new PathNodes(path); PathNode nodeParent = nodes.ParentNode; while (nodeParent != null) { EntryTreeNodeData newTag = null; switch (nodeParent.Type) { default: throw new ArgumentException("Unhandled TypeEnum", "nodeParent.Type"); case PathNode.TypeEnum.FILE: { EntryInfo info = new EntryInfo(TypeEnum.FILE, nodeParent.Name, nodeParent.Path); newTag = new BackupPlanTreeNodeData(StorageAccount, info); newTag.State = CheckState.Mixed; break; } case PathNode.TypeEnum.FOLDER: { EntryInfo info = new EntryInfo(TypeEnum.FOLDER, nodeParent.Name, nodeParent.Path); newTag = new BackupPlanTreeNodeData(StorageAccount, info); newTag.State = CheckState.Mixed; break; } case PathNode.TypeEnum.DRIVE: { EntryInfo info = new EntryInfo(TypeEnum.DRIVE, nodeParent.Name, nodeParent.Path); newTag = new BackupPlanTreeNodeData(StorageAccount, info); newTag.State = CheckState.Mixed; break; } } if (newTag != null) { if (!expandedDict.ContainsKey(nodeParent.Path)) { expandedDict.Add(nodeParent.Path, newTag as BackupPlanTreeNodeData); } } nodeParent = nodeParent.Parent; } }
private void ExpandCheckedDataSourceFileVersionNode(Dictionary <string, BackupPlanTreeNodeData> expandedDict, BackupPlanTreeNodeData nodeData) { Assert.AreEqual(TypeEnum.FILE_VERSION, nodeData.Type); nodeData.State = CheckState.Checked; EntryInfo info = new EntryInfo(TypeEnum.FILE, nodeData.Name, nodeData.Path, null); EntryTreeNodeData newTag = new BackupPlanTreeNodeData(StorageAccount, info); newTag.State = CheckState.Mixed; string nodeKey = BuildNodeKey(nodeData, info.Version); if (!expandedDict.ContainsKey(nodeKey)) { expandedDict.Add(nodeKey, newTag as BackupPlanTreeNodeData); } }
private Dictionary <string, BackupPlanTreeNodeData> ExpandCheckedDataSource( Dictionary <string, BackupPlanTreeNodeData> dict) { if (dict == null) { return(null); } Dictionary <string, BackupPlanTreeNodeData> expandedDict = new Dictionary <string, BackupPlanTreeNodeData>(dict.Count * 2); bool hasParents = false; // Expand paths into their respective parts. foreach (var obj in dict) { switch (obj.Value.Type) { default: throw new ArgumentException("Unhandled TypeEnum", "obj.Value.Type"); case TypeEnum.FILE_VERSION: case TypeEnum.FILE: case TypeEnum.FOLDER: hasParents = true; break; case TypeEnum.DRIVE: hasParents = false; break; } if (obj.Value.InfoObject == null) { obj.Value.InfoObject = new EntryInfo(obj.Value.Type, obj.Value.Name, obj.Value.Path, obj.Value.Version); } string nodeKey = BuildNodeKey(obj.Value, obj.Value.Version); if (!expandedDict.ContainsKey(nodeKey)) { expandedDict.Add(nodeKey, obj.Value); if (hasParents) { if (obj.Value.Type == TypeEnum.FILE_VERSION) { ExpandCheckedDataSourceFileVersionNode(expandedDict, obj.Value); } ExpandCheckedDataSourceAddParents(expandedDict, obj.Value.Path); } } } // Load all respective `BackupPlanPathNode`s. foreach (var obj in expandedDict) { BackupPlanTreeNodeData nodeData = obj.Value; if (nodeData.UserObject == null) { Models.EntryType nodeType = Models.EntryTypeExtensions.ToEntryType(nodeData.Type); if (nodeData.Type == TypeEnum.FILE_VERSION) { nodeType = Models.EntryType.FILE; } BackupPlanPathNodeRepository daoPathNode = new BackupPlanPathNodeRepository(); nodeData.UserObject = daoPathNode.GetByStorageAccountAndTypeAndPath(StorageAccount, nodeType, nodeData.Path); } } return(expandedDict); }