/// <summary>Retrieve credentials if not already stored with data model</summary>
        /// <param name="dataModel">The data on the connection</param>
        private WifiErrorCode WifiGetConnectCredentials(WifiNetworkInfo dataModel, ref bool save)
        {
            // By default we do not want to save unless
            this.log.Info("WifiGetConnectCredentials", () => string.Format(""));
            WifiErrorCode result = WifiErrorCode.Success;

            if (dataModel.RemoteHostName.Trim().Length == 0 ||
                dataModel.RemoteServiceName.Trim().Length == 0 ||
                dataModel.Password.Trim().Length == 0)
            {
                this.log.Info("********************************", "Comm Wrapper - GetConnectionCredentials");


                this.log.Info("WifiGetConnectCredentials", () => string.Format("No data in data model"));
                if (!this.WifiGetStoredCredentials(dataModel))
                {
                    this.log.Info("WifiGetConnectCredentials", () => string.Format("No stored data - get from user"));
                    result = this.GetUserCredentials(dataModel, ref save);
                    this.log.Info("WifiGetConnectCredentials", () => string.Format("result {0}", result));
                    //if (result == WifiErrorCode.Success) {
                    //    if (save) {
                    //        this.WifiStoreCredentials(dataModel);
                    //    }
                    //}
                }
            }
            else
            {
                this.log.Info("WifiGetConnectCredentials",
                              () => string.Format("Has data:{0}:{1}", dataModel.RemoteHostName, dataModel.RemoteServiceName));
            }
            return(result);
        }
Exemplo n.º 2
0
 private async Task <WifiErrorCode> ConnectToNetwork(WiFiAdapter adapter, string ssid, string password)
 {
     try {
         // Should already be scanned
         WiFiNetworkReport report      = adapter.NetworkReport;
         WifiErrorCode     returnValue = WifiErrorCode.NetworkNotAvailable;
         foreach (var net in report.AvailableNetworks)
         {
             if (net.Ssid == ssid)
             {
                 // TODO Will need to have multiple types of authentication
                 PasswordCredential cred = new PasswordCredential()
                 {
                     Password = password
                 };
                 returnValue = (await adapter.ConnectAsync(net, WiFiReconnectionKind.Automatic, cred)).ConnectionStatus.Convert();
                 break;
             }
         }
         if (returnValue != WifiErrorCode.Success)
         {
             this.OnError?.Invoke(this, new WifiError(returnValue));
         }
         return(returnValue);
     }
     catch (Exception e) {
         WrapErr.SafeAction(() => {
             this.OnError?.Invoke(this, new WifiError(WifiErrorCode.Unknown));
         });
         return(WifiErrorCode.Unknown);
     }
 }
        private void RaiseError(WifiErrorCode code, string details = "")
        {
            WifiError err = new WifiError(code);

            if (details.Length > 0)
            {
                err.ExtraInfo = details;
            }
            this.OnError?.Invoke(this, err);
        }
        public void WifiConnectAsync(WifiNetworkInfo dataModel)
        {
            this.log.InfoEntry("WifiConnectAsync");
            // TODO use a try catch and change signature to have an error delegate return?
            try {
                bool          save   = false;
                WifiErrorCode result = this.WifiGetConnectCredentials(dataModel, ref save);
                this.log.Info("********************************", "Comm Wrapper - WifiConnectAsync after get credentials");

                if (result != WifiErrorCode.Success)
                {
                    this.OnWifiError?.Invoke(this, new WifiError(result));
                }
                else
                {
                    if (save)
                    {
                        this.pendingSaveConnectNetInfo = dataModel;
                    }
                    this.wifi.ConnectAsync(dataModel);
                }
            }
            catch (ErrReportException erE) {
                this.OnWifiError?.Invoke(this, new WifiError(WifiErrorCode.Unknown)
                {
                    ExtraInfo = erE.Report.Msg
                });
            }
            catch (Exception e) {
                this.log.Exception(9999, "", e);
                this.OnWifiError?.Invoke(this, new WifiError(WifiErrorCode.Unknown)
                {
                    ExtraInfo = e.Message
                });
            }
        }
Exemplo n.º 5
0
 public WifiError(WifiErrorCode code)
 {
     this.Code = code;
 }