public static SynchronizationTree ReadTree(string vaultName, string vaultURI, bool tryHarder = false) { var newTree = new SynchronizationTree(vaultName, vaultURI); string vaultId = GetVaultId(vaultName, vaultURI); VaultEagleConfig config = ReadConfig(vaultName, vaultURI); newTree.Config = config; var treeByVaultMap = config.Vaults; try { if (!treeByVaultMap.ContainsKey(vaultId)) { if (tryHarder) { vaultId = TryToFindMovedOrRenamedVaultId(vaultName, vaultURI, treeByVaultMap) ?? vaultId; } } } catch (Exception) { } if (treeByVaultMap.ContainsKey(vaultId)) { newTree.ExplicitPaths = treeByVaultMap[vaultId].ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase); } return(newTree); }
public static TreeNode ToTreeNode(this SynchronizationTree tree) { var set = new HashSet <string>(); foreach (var path in tree.ExplicitPaths.Keys.ToList()) { set.UnionWith(SynchronizationTree.SubPaths(path)); } set.Remove("$/"); // special List <string> allPaths = set.ToList().Sorted(); // sort, with folders last Dictionary <string, TreeNode> pathToNodeDict = new Dictionary <string, TreeNode>(); TreeNode root = CreateNode(tree, "$/", "$"); pathToNodeDict["$/"] = root; foreach (string subPath in allPaths) { string folder, filename; SynchronizationTree.TrySplitPathIntoFolderAndChild(subPath, out folder, out filename); filename = filename.ToLowerInvariant(); TreeNode node = CreateNode(tree, subPath, filename); pathToNodeDict[folder].Nodes.Add(node); pathToNodeDict[subPath] = node; } SortFilesBeforeFolders(root); return(root); }
public VaultEagleConfigV1_0 UpgradeToNext(ConfigConversionContext context) { return(new VaultEagleConfigV1_0 { Vaults = new[] { ExplicitPaths.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => new VaultEagleConfigV1_0.SyncInfoV1_0 { State = (VaultEagleConfigV1_0.SyncStateV1_0)kv.Value, Path = kv.Key }).ToSortedDictionary() }.ToDictionary(x => SynchronizationTree.GetVaultId(context.VaultName, context.VaultURI)) }); }
public ShowSubscriptionsForm(SynchronizationTree tree, Action <bool> startSyncThread, VaultCommunication vaultCom) { this.tree = tree; this.startSyncThread = startSyncThread; this.vaultCom = vaultCom; InitializeComponent(); SubscriptionTree.Nodes.Clear(); removeToolStripMenuItem.ShortcutKeys = Keys.Delete; RedrawTree(); SubscriptionTree.ExpandAll(); }
private static TreeNode CreateNode(SynchronizationTree tree, string path, string name) { name = name.TrimEnd('/'); int iconImageIndex = (int)tree.GetIconIndexForPath(path); // order matches that in ImageList TreeNode node = new TreeNode(name, iconImageIndex, iconImageIndex); node.Tag = path; if (tree.IsExcluded(path)) { node.ForeColor = System.Drawing.SystemColors.GrayText; } return(node); }
private void ShowSubscription(object s, CommandItemEventArgs e) { var connection = e.Context.Application.Connection; if (vaultCom.connection == null) { vaultCom.InitializeFromConnection(application.Connection); } string vaultName = connection.Vault, vaultUri = connection.Server; SynchronizationTree tree = new SynchronizationTree(vaultName, vaultUri); try { tree = SynchronizationTree.ReadTree(vaultName, vaultUri); if (tree.IsEmpty()) { var result = MessageBox.Show("No subscriptions found for this vault. Try harder?", "Try harder?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { tree = SynchronizationTree.ReadTree(vaultName, vaultUri, tryHarder: true); } } } catch (Exception ex) { var result = MessageBox.Show("[ERROR] " + ex.Message + "\r\nDo you want to continue?", "Error", MessageBoxButtons.OKCancel); if (result == DialogResult.Cancel) { return; } } ShowSubscriptionsForm form = new ShowSubscriptionsForm(tree, StartSyncThread, vaultCom); form.ShowDialog(); }
private void SubscribeOrUnsubscribe(IEnumerable <ISelection> selectionSet, bool subscribe) { try { if (vaultCom.connection == null) { vaultCom.InitializeFromConnection(application.Connection); } var selSet = selectionSet.ToArray(); var paths = GetPathsFromSelections(vaultCom, selSet); var connection = application.Connection; SynchronizationTree tree = SynchronizationTree.ReadTree(connection.Vault, connection.Server); foreach (var path in paths) { if (subscribe) { tree.Include(path); } else { tree.Exclude(path); } } bool didWrite = tree.WriteTree(); if (!didWrite) { var readOnly = new ReadOnlyForm(); readOnly.Show(); } } catch (Exception ex) { MessageBox.Show("[ERROR] " + ex.Message, "Error"); } }
public VaultEagleSynchronizer(Connection connection, SynchronizationTree syncTree) { this.connection = connection; this.syncTree = syncTree; }
public VaultEagleSynchronizer(Connection connection) : this(connection, SynchronizationTree.ReadTree(connection.Vault, connection.Server)) { }