public void AddInterface(NetInterfaceModel netInterface) { var netInterfaceViewModel = new NetInterfaceViewModel(netInterface); // TODO deprecated //netInterfaceViewModel.ProfileChangedEvent += ProfileChangedEvent; NetInterfacesCollection.Add(netInterfaceViewModel); }
public NetInterfaceViewModel(NetInterfaceModel netInterface) { NetInterfaceModel = netInterface; Profiles = new ObservableCollection<ProfileButtonViewModel>(); foreach (AbstractProfileModel profile in netInterface.Profiles) { Profiles.Add(new ProfileButtonViewModel(profile)); } IsExpanded = true; }
private ProfileModel makeProfile(Dictionary<string, string> profileOptions, NetInterfaceModel netInterface) { String profileName = Encoding.UTF8.GetString(ibm852enc.GetBytes(profileOptions["Nazwa"])); ProfileModel profile = new ProfileModel(profileName, netInterface); profile.PhysicalAddress = profileOptions["Adres fizyczny"]; profile.GUID = profileOptions["Identyfikator GUID"]; // TODO: tylko jak jest połączony //profile.Signal = profileOptions[profileOptions.Keys.Where(x => x.StartsWith("Sygn")).ToList()[0]]; //profile.SSID = profileOptions["SSID"]; //profile.Authentication = profileOptions["Uwierzytelnianie"]; //Profile profile = new Profile(profileOptions["Name"]); //profile.PhysicalAddress = profileOptions["Physical address"]; //profile.GUID = profileOptions["GUID"]; //profile.Authentication = profileOptions["Authentication"]; //profile.BSSID = profileOptions["BSSID"]; //profile.Channel = profileOptions["Channel"]; //profile.Cipher = profileOptions["Cipher"]; //profile.ConnectionMode = profileOptions["Connection mode"]; //profile.Description = profileOptions["Description"]; //profile.NetworkType = profileOptions["Network type"]; //profile.ProfileName = profileOptions["Profile"]; //profile.RadioType = profileOptions["Radio type"]; //profile.ReceiveRate = profileOptions["Receive rate (Mbps)"]; //profile.Signal = profileOptions["Signal"]; //profile.SSID = profileOptions["SSID"]; //profile.State = profileOptions["State"]; //profile.TransmitRate = profileOptions["Transmit rate (Mbps)"]; //profile.BSSID = profileOptions["BSSID"]; //profile.Channel = profileOptions["Channel"]; //profile.Cipher = profileOptions["Cipher"]; //profile.ConnectionMode = profileOptions["Connection mode"]; //profile.Description = profileOptions["Description"]; //profile.NetworkType = profileOptions["Network type"]; //profile.ProfileName = profileOptions["Profile"]; //profile.RadioType = profileOptions["Radio type"]; //profile.ReceiveRate = profileOptions["Receive rate (Mbps)"]; //profile.State = profileOptions["State"]; //profile.TransmitRate = profileOptions["Transmit rate (Mbps)"]; return profile; }
public List<ProfileModel> parse(NetInterfaceModel netInterface) { string netshOutput = invokeNetsh(); List<ProfileModel> profiles = new List<ProfileModel>(); List<string> outputLines = netshOutput.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Where(p => p.Contains(":") && !p.StartsWith("There") && !p.StartsWith("Hosted")).ToList(); List<Tuple<string, string>> oneProfile = new List<Tuple<string, string>>(); foreach (string line in outputLines) { List<string> newLine = line.Split(new char[] { ':' }, 2).Select(p => p.Trim()).ToList(); oneProfile.Add(new Tuple<string, string>(newLine[0], newLine[1])); if (newLine[0].StartsWith("Stan sieci")) { profiles.Add(makeProfile(oneProfile.ToDictionary(x => x.Item1, x => x.Item2), netInterface)); oneProfile.Clear(); } } return profiles; }
private IList<NetInterfaceModel> GetAllNetInterfaces() { IList<NetInterfaceModel> interfaces = new List<NetInterfaceModel>(); IList<NetworkAdapter> adapters = new List<NetworkAdapter>(); foreach(NetworkAdapter adapter in NetworkAdapterEnumerator.GetAllNetworkAdapters()) { if (!String.IsNullOrWhiteSpace(adapter.NetConnectionID)) adapters.Add(adapter); } IDictionary<string, NetworkInterface> ifaceDict = NetworkInterface.GetAllNetworkInterfaces().ToDictionary(i => i.Name); foreach (NetworkAdapter adapter in adapters) { NetworkInterface value; NetInterfaceModel niface = null; if (ifaceDict.TryGetValue(adapter.NetConnectionID, out value)) niface = new NetInterfaceModel(adapter, value); else niface = new NetInterfaceModel(adapter, null); niface.SetNetInterfaceManager(this); interfaces.Add(niface); } return interfaces; }
private void WmiAdapterEventHandler(object sender, EventArrivedEventArgs e) { ManagementBaseObject targetInstance = (ManagementBaseObject)e.NewEvent["TargetInstance"]; ManagementBaseObject previousInstance = (ManagementBaseObject)e.NewEvent["PreviousInstance"]; NetworkAdapter targetAdapter = new NetworkAdapter(targetInstance); NetworkAdapter previousAdapter = new NetworkAdapter(previousInstance); NetInterfaceModel oldInterface = new NetInterfaceModel(previousAdapter, null, false); //CreateFromNetworkAdapter(targetAdapter); this.networkAdapter = targetAdapter; if (oldInterface.IsConnected != this.IsConnected) { if (this.IsConnected) { if (Connected != null) Connected(); } else { if (Disconnected != null) Disconnected(); } } if (oldInterface.IsEnabled != this.IsEnabled) { if (this.IsEnabled) { if (InterfaceUp != null) InterfaceUp(); } else { if (InterfaceDown != null) InterfaceDown(); } } Console.WriteLine("WmiAdapterEventHandler"); }