Esempio n. 1
0
            /// <summary>
            /// Compares the <see cref="HistoricalConnection.LastConnection"/> properties of the <see cref="HistoricalConnection"/> instances for each
            /// <see cref="ListViewItem"/>.
            /// </summary>
            /// <param name="x">First <see cref="ListViewItem"/> that we should compare.</param>
            /// <param name="y">Second <see cref="ListViewItem"/> that we should compare.</param>
            /// <returns>The result of <see cref="DateTime.CompareTo(DateTime)"/> of <paramref name="x"/> when provided with
            /// <see cref="HistoricalConnection.LastConnection"/> for <paramref name="y"/>.</returns>
            public int Compare(object x, object y)
            {
                HistoricalConnection connectionX = _connections[(ListViewItem)x];
                HistoricalConnection connectionY = _connections[(ListViewItem)y];

                return(connectionY.LastConnection.CompareTo(connectionX.LastConnection));
            }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
        /// <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 async Task AddToHistory(IConnection connection)
        {
            HistoricalConnection historyEntry = new HistoricalConnection(connection)
            {
                LastConnection = DateTime.Now
            };

            AddToHistory(historyEntry);
            await Save();
        }
Esempio n. 4
0
        private void Connections_CollectionModified(object sender, ListModificationEventArgs e)
        {
            ListWithEvents <HistoricalConnection> history = sender as ListWithEvents <HistoricalConnection>;

            if (e.Modification == ListModification.ItemModified || e.Modification == ListModification.ItemAdded || e.Modification == ListModification.RangeAdded)
            {
                for (int i = e.StartIndex; i < e.StartIndex + e.Count; i++)
                {
                    HistoricalConnection historyEntry = history[i];

                    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));
                }
            }
        }
Esempio n. 5
0
        /// <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));
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Adds <paramref name="historyEntry"/> to <see cref="_connections"/>.
 /// </summary>
 /// <param name="historyEntry">Connection that we're adding to the history.</param>
 protected void AddToHistory(HistoricalConnection historyEntry)
 {
     _connections.Add(historyEntry);
 }