/// <summary> /// Remove the selected profile. /// </summary> private async Task RemoveProfileAsync() { BusyStateManager.EnterBusy(); BusyStateManager.SetMessage(SeverityType.Info, "Removing selected profile."); /* Temporary store selected interface and WiFi profile so they can be restored after deletion. */ Guid selectedInterfaceId = SelectedInterface.Id; int profilePosition = SelectedWiFiProfile.Position; await _mainController.DeleteProfileAsync(SelectedWiFiProfile); await DownloadProfilesAsync(); /* Restore selected interface and position of selected WiFi profile. */ Profile selectedWifiProfile = WiFiProfiles.Where(x => x.Id == selectedInterfaceId && x.Position == profilePosition).FirstOrDefault(); if (selectedWifiProfile == default(Profile)) { selectedWifiProfile = WiFiProfiles.Where(x => x.Id == selectedInterfaceId).OrderByDescending(x => x.Position).FirstOrDefault(); } Interface selectedInterface = Interfaces.Where(x => x.Id == selectedInterfaceId).FirstOrDefault(); SelectedInterface = selectedInterface == default(Interface) ? Interfaces.FirstOrDefault() : selectedInterface; if (selectedWifiProfile != default(Profile)) { SelectedWiFiProfile = selectedWifiProfile; } BusyStateManager.SetMessage(SeverityType.None); BusyStateManager.ExitBusy(); }
/// <summary> /// Retrieves the WiFi profiles and interfaces and updates the View. /// </summary> private async Task DownloadProfilesAsync() { BusyStateManager.EnterBusy(); BusyStateManager.SetMessage(SeverityType.Info, "Retrieving profiles and interfaces."); /* Temporary store selected interface and wifi profile so they can be restored after download. */ Guid? interfaceId = SelectedInterface?.Id; string profileName = SelectedWiFiProfile?.ProfileName; /* Download wifi profiles and interfaces. */ IEnumerable <Profile> profiles = await _mainController.GetWiFiProfilesAsync(); IEnumerable <Interface> interfaces = await _mainController.GetWiFiInterfacesAsync(); if (profiles == default(IEnumerable <Profile>) || interfaces == default(IEnumerable <Interface>)) { WiFiProfiles = new ObservableCollection <Profile>(Enumerable.Empty <Profile>()); WiFiProfilesViewSource.Source = WiFiProfiles; Interfaces = new ObservableCollection <Interface>(Enumerable.Empty <Interface>()); } else { WiFiProfiles = new ObservableCollection <Profile>(profiles); WiFiProfilesViewSource.Source = WiFiProfiles; Interfaces = new ObservableCollection <Interface>(interfaces); } /* Restore selected interface and wifi profile. */ Interface selectedInterface = Interfaces.Where(x => x.Id == interfaceId).FirstOrDefault(); Profile selectedWifiProfile = WiFiProfiles.Where(x => x.Id == interfaceId && x.ProfileName == profileName).FirstOrDefault(); SelectedInterface = selectedInterface == default(Interface) ? Interfaces.FirstOrDefault() : selectedInterface; if (selectedWifiProfile != default(Profile)) { SelectedWiFiProfile = selectedWifiProfile; } BusyStateManager.SetMessage(SeverityType.None); BusyStateManager.ExitBusy(); }