private void btnConnect_Clicked(object sender, EventArgs e) { this.SetConnectedLight(false); Task.Run(() => { WifiCredAndIndex cred = App.Wrapper.ValidateCredentials(this.networkInfo, this.OnErr); if (cred.RequiresUserData) { Device.BeginInvokeOnMainThread(() => PopupNavigation.Instance.PushAsync( new WifiCredRequestPopUpPage(cred, this.networkInfo, this.DelegateRunConnection))); } else { this.DelegateRunConnection(this.networkInfo); } }); /* * Device.BeginInvokeOnMainThread(async () => { * this.SetConnectedLight(false); * WifiCredAndIndex cred = App.Wrapper.ValidateCredentials(this.networkInfo, this.OnErr); * if (cred.RequiresUserData) { * await PopupNavigation.Instance.PushAsync( * new WifiCredRequestPopUpPage(cred, this.networkInfo, this.DelegateRunConnection)); * } * else { * this.DelegateRunConnection(this.networkInfo); * } * }); */ }
/// <summary>Get discovered info to look up the stored WifiCredentials object to check for credentials /// /// </summary> /// <param name="discoverData">The WifiNetworkInfo with info from discovered devices</param> /// <returns></returns> public WifiCredAndIndex ValidateCredentials(WifiNetworkInfo discoverData, OnErr onError) { WifiCredAndIndex result = null; ErrReport report; WrapErr.ToErrReport(out report, 2000353, "Failure on ValidateCredentials", () => { this.log.Info("WifiGetConnectCredentials", () => string.Format("")); if (discoverData.SSID.Trim().Length == 0) { this.log.Error(9999, "ValidateCredentialsAsync", () => string.Format("No SSID in data retrieved from Discover")); } else { this.log.Info("ValidateCredentialsAsync", () => string.Format("SSID:{0}", discoverData.SSID)); result = this.WifiGetStoredCredentials(discoverData.SSID, onError); if (result != null && !result.RequiresUserData) { // initialize the fields in the data model sent to connect to WIFI discoverData.RemoteHostName = result.Data.RemoteHostName; discoverData.RemoteServiceName = result.Data.RemoteServiceName; discoverData.Password = result.Data.WifiPassword; } } }); this.RaiseIfException(report); return(result); }
//private async Task<WifiCredAndIndex> WifiGetStoredCredentials(string ssid, OnErr onError) { private WifiCredAndIndex WifiGetStoredCredentials(string ssid, OnErr onError) { //return await Task.Run<WifiCredAndIndex>(() => { WifiCredAndIndex result = null; this.GetWifiCredList( (list) => { foreach (var item in list) { this.log.Info("WifiGetStoredCredentials", () => string.Format("SSID '{0}' List itm display '{1}", ssid, item.Display)); if (item.Display == ssid) { this.RetrieveWifiCredData( item, (data) => { this.log.Info("WifiGetStoredCredentials", () => string.Format("FOUND SSID '{0}'", item.Display)); result = new WifiCredAndIndex() { Index = item, Data = data, RequiresUserData = (data.RemoteHostName.Trim().Length == 0 || data.RemoteServiceName.Trim().Length == 0 || data.WifiPassword.Trim().Length == 0), }; }, onError); break; } } if (result == null) { // Create new one WifiCredentialsDataModel dm = new WifiCredentialsDataModel() { SSID = ssid, }; this.CreateNewWifiCred( ssid, dm, (ndx) => { result = new WifiCredAndIndex() { Data = dm, Index = ndx, RequiresUserData = true, }; }, onError); } }, onError); return(result); //}); }
public WifiCredRequestPopUpPage( WifiCredAndIndex cred, WifiNetworkInfo discoverData, Action <WifiNetworkInfo> connectAction) { this.cred = cred; this.discoverData = discoverData; this.connectAction = connectAction; InitializeComponent(); this.CloseWhenBackgroundIsClicked = false; this.InitiEditBoxes(this.cred.Data); App.Wrapper.CurrentSupportedLanguage(this.UpdateLanguage); }