Esempio n. 1
0
        //Commented because of some oddity in NetworkManager that emits these signals multiple times with erroneous data.

        /*
         * void OnConnectionAdded (string objectPath)
         * {
         *      Console.WriteLine ("Connection added: {0}", objectPath);
         * }
         *
         * void OnNetworkConnectionRemoved (object o, NetworkConnection.NetworkConnectionRemovedArgs args)
         * {
         *      Console.WriteLine ("connection removed: {0}", args.ConnectionName);
         * }
         */

        public void UpdateConnections()
        {
            lock (SystemConnections) {
                SystemConnections.Clear();
                try {
                    foreach (string con in SystemConnectionManager.BusObject.ListConnections())
                    {
                        NetworkConnection connection = new NetworkConnection(SystemBus, con, ConnectionOwner.System);
                        if (connection.Settings.ContainsKey("802-11-wireless"))
                        {
                            connection = new WirelessConnection(SystemBus, con, ConnectionOwner.System);
                        }
                        else if (connection.Settings.ContainsKey("802-3-ethernet"))
                        {
                            connection = new WiredConnection(SystemBus, con, ConnectionOwner.System);
                        }
                        else
                        {
                            continue;
                        }
                        //connection.ConnectionRemoved += OnNetworkConnectionRemoved;
                        SystemConnections.Add(connection);
                    }
                } catch (Exception e) {
                    Log <ConnectionManager> .Error(e.Message);

                    Log <ConnectionManager> .Debug(e.StackTrace);
                }
            }

            lock (UserConnections) {
                UserConnections.Clear();
                try {
                    foreach (string con in UserConnectionManager.BusObject.ListConnections())
                    {
                        NetworkConnection connection = new NetworkConnection(UserBus, con, ConnectionOwner.User);
                        if (connection.Settings.ContainsKey("802-11-wireless"))
                        {
                            connection = new WirelessConnection(UserBus, con, ConnectionOwner.User);
                        }
                        else if (connection.Settings.ContainsKey("802-3-ethernet"))
                        {
                            connection = new WiredConnection(UserBus, con, ConnectionOwner.User);
                        }
                        else
                        {
                            continue;
                        }

                        //connection.ConnectionRemoved += OnNetworkConnectionRemoved;
                        UserConnections.Add(connection);
                    }
                } catch (Exception e) {
                    Log <ConnectionManager> .Error(e.Message);

                    Log <ConnectionManager> .Debug(e.StackTrace);
                }
            }
        }
		//Commented because of some oddity in NetworkManager that emits these signals multiple times with erroneous data.
		/*
		void OnConnectionAdded (string objectPath)
		{
			Console.WriteLine ("Connection added: {0}", objectPath);
		}

		void OnNetworkConnectionRemoved (object o, NetworkConnection.NetworkConnectionRemovedArgs args)
		{
			Console.WriteLine ("connection removed: {0}", args.ConnectionName);
		}
		*/
		
		public void UpdateConnections ()
		{
			lock (SystemConnections) {
				SystemConnections.Clear ();
				try {
					foreach (string con in SystemConnectionManager.BusObject.ListConnections ())
					{
						NetworkConnection connection = new NetworkConnection (SystemBus, con, ConnectionOwner.System);
						if (connection.Settings.ContainsKey ("802-11-wireless"))
							connection = new WirelessConnection (SystemBus, con, ConnectionOwner.System);
						else if (connection.Settings.ContainsKey ("802-3-ethernet"))
							connection = new WiredConnection (SystemBus, con, ConnectionOwner.System);
						else 
							continue;
						//connection.ConnectionRemoved += OnNetworkConnectionRemoved;
						SystemConnections.Add (connection);
					}
				} catch (Exception e) {
					Log<ConnectionManager>.Error (e.Message);
					Log<ConnectionManager>.Debug (e.StackTrace);
				}
			}
			
			lock (UserConnections) {
				UserConnections.Clear ();
				try {
					foreach (string con in UserConnectionManager.BusObject.ListConnections ())
					{
						NetworkConnection connection = new NetworkConnection (UserBus, con, ConnectionOwner.User);
						if (connection.Settings.ContainsKey ("802-11-wireless"))
							connection = new WirelessConnection (UserBus, con, ConnectionOwner.User);
						else if (connection.Settings.ContainsKey ("802-3-ethernet"))
							connection = new WiredConnection (UserBus, con, ConnectionOwner.User);
						else 
							continue;
						
						//connection.ConnectionRemoved += OnNetworkConnectionRemoved;
						UserConnections.Add (connection);
					}
				} catch (Exception e) {
					Log<ConnectionManager>.Error (e.Message);
					Log<ConnectionManager>.Debug (e.StackTrace);
				}
			}
		}