public HistoryWindow(MainForm.ConnectionDelegate connectionDelegate, Favorites favoritesWindow, SecureString password) { _connectionDelegate = connectionDelegate; _favoritesWindow = favoritesWindow; _password = password; InitializeComponent(); if (File.Exists(_historyFileName)) { XmlDocument history = new XmlDocument(); history.Load(_historyFileName); foreach (XmlNode node in history.SelectNodes("/history/connection")) { HistoricalConnection historyEntry = new HistoricalConnection(node, _password); TreeNode newTreeNode = new TreeNode((String.IsNullOrEmpty(historyEntry.Name) ? historyEntry.Host : historyEntry.Name), 2, 2); if (historyEntry.LastConnection.DayOfYear == DateTime.Now.DayOfYear && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[0].Nodes, newTreeNode); else if (historyEntry.LastConnection.DayOfYear == DateTime.Now.DayOfYear - 1 && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[1].Nodes, newTreeNode); else if (historyEntry.LastConnection.DayOfYear >= DateTime.Now.DayOfYear - (int)DateTime.Now.DayOfWeek && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[2].Nodes, newTreeNode); else if (historyEntry.LastConnection.Month == DateTime.Now.Month && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[3].Nodes, newTreeNode); else if (historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[4].Nodes, newTreeNode); else continue; _connections[newTreeNode] = historyEntry; } } }
/// <summary> /// Adds <paramref name="historyEntry"/> to <see cref="_historyListView"/> under the proper group. /// </summary> /// <param name="historyEntry">Connection that we're adding to the history.</param> protected void AddToHistory(HistoricalConnection historyEntry) { if (_historyListView.Groups[historyEntry.LastConnection.ToString("yyyy-MM-dd")] == null) { int insertIndex = 0; string groupName = historyEntry.LastConnection.ToString("yyyy-MM-dd"); for (insertIndex = 0; insertIndex < _historyListView.Groups.Count; insertIndex++) { if (String.Compare(_historyListView.Groups[insertIndex].Name, groupName, StringComparison.Ordinal) > 0) break; } _historyListView.Groups.Insert(insertIndex, new ListViewGroup(groupName, historyEntry.LastConnection.ToLongDateString())); } // To account for legacy versions of the application where everything was an RDP connection, if a history entry was LegacyHistoricalConnection, // we use the RDP icon ListViewItem listViewItem = new ListViewItem( historyEntry.LastConnection.ToLongTimeString(), _connectionTypeIcons[historyEntry.Connection.GetType() == typeof (LegacyHistoricalConnection) ? typeof (RdpConnection) : historyEntry.Connection.GetType()]); listViewItem.SubItems.Add(historyEntry.Connection.DisplayName); listViewItem.SubItems.Add(historyEntry.Connection.Host); _connections[listViewItem] = historyEntry; _historyListView.Items.Add(listViewItem); _historyListView.Groups[historyEntry.LastConnection.ToString("yyyy-MM-dd")].Items.Add(listViewItem); _historyListView.Columns[0].Width = 119; _historyListView.Columns[1].Width = 143; _historyListView.Columns[2].Width = 419; if (IsHandleCreated) _historyListView.BeginInvoke(new Action(_historyListView.Sort)); }
/// <summary> /// Adds a connection that the user has made to the list of historical connections. /// </summary> /// <param name="connection">Connection that was made that should be added to the history.</param> public void AddToHistory(IConnection connection) { HistoricalConnection historyEntry = new HistoricalConnection(connection) { LastConnection = DateTime.Now }; AddToHistory(historyEntry); Save(); }
public void AddToHistory(RDCConnection connection) { TreeNode connectionNode = FindConnectionNode(historyTreeView.Nodes, connection); HistoricalConnection historyEntry = new HistoricalConnection(connection, _password); if (connectionNode != null) { if (!String.IsNullOrEmpty(_connections[connectionNode].Name) && String.IsNullOrEmpty(connection.Name)) historyEntry.Name = _connections[connectionNode].Name; } historyEntry.LastConnection = DateTime.Now; if (FindConnectionNode(historyTreeView.Nodes[0].Nodes[0].Nodes, connection) == null) { if (connectionNode != null) { _connections.Remove(connectionNode); connectionNode.Remove(); } TreeNode newTreeNode = new TreeNode((String.IsNullOrEmpty(historyEntry.Name) ? historyEntry.Host : historyEntry.Name), 2, 2); AddTreeNode(historyTreeView.Nodes[0].Nodes[0].Nodes, newTreeNode); _connections[newTreeNode] = historyEntry; } else if (connectionNode != null) { TreeNode newTreeNode = new TreeNode((String.IsNullOrEmpty(historyEntry.Name) ? historyEntry.Host : historyEntry.Name), 2, 2); _connections.Remove(connectionNode); connectionNode.Remove(); AddTreeNode(historyTreeView.Nodes[0].Nodes[0].Nodes, newTreeNode); _connections[newTreeNode] = historyEntry; } Save(); }