Пример #1
0
 /// <summary>
 /// Called when the Add button is clicked
 /// </summary>
 /// <param name="sender">
 /// autogenerated
 /// </param>
 /// <param name="e">
 /// autogenerated
 /// </param>
 private void AddButtonClick(object sender, RoutedEventArgs e)
 {
     if (stationGrid.SelectedCells.Count != 0)
     {
         IPEndPoint ipep = ((StationStatus)stationGrid.SelectedItem).Address;
         if (!_ui.GetPeerlist().Contains(ipep))
         {
             _ui.ExchangeKeys(ipep);
         }
     }
     UpdateControls();
 }
        /// <summary>
        /// the thread to populate the list
        /// </summary>
        /// <param name="mvp">this manager overview page</param>
        public void PopulateListThread(ManagerOverviewPage mvp)
        {
            mvp.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { UpdateLabel.Content = "Opdaterer..."; }));
            mvp.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { LoadingBar.Visibility = Visibility.Visible; }));
            IEnumerable <IPEndPoint> peerlist = _ui.GetPeerlist();

            if (peerlist != null)
            {
                var dataSource = (from ip in peerlist where _ui.IsStationActive(ip) select new StationStatus {
                    IpAdress = ip.Address.ToString(), Connected = true
                }).ToList();
                dataSource.AddRange(from ip in _ui.DiscoverPeers() where !peerlist.Contains(ip) select new StationStatus {
                    IpAdress = ip.Address.ToString(), Connected = false
                });

                mvp.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { ManagerstationGrid.ItemsSource = dataSource; }));
                mvp.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { ManagerstationGrid.Items.Refresh(); }));
            }
            mvp.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { UpdateLabel.Content = ""; }));
            mvp.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { LoadingBar.Visibility = Visibility.Hidden; }));
        }