using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.Commands; using Tango.WiFi; namespace Tango.PPC.Common.Connectivity { public class WiFiNetwork : ExtendedObject { private Wifi _wifi; public bool IsConnected { get { return AccessPoint.IsConnected; } } public String Name { get { return AccessPoint.Name; } } public double SignalStrength { get { return AccessPoint.SignalStrength; } } public bool IsSecure { get { return AccessPoint.IsSecure; } } public bool HasProfile { get { return AccessPoint.HasProfile; } } private AccessPoint _accessPoint; public AccessPoint AccessPoint { get { return _accessPoint; } set { _accessPoint = value; foreach (var prop in this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { RaisePropertyChanged(prop.Name); } } } private bool _autoConnect; public bool AutoConnect { get { return _autoConnect; } set { _autoConnect = value; RaisePropertyChangedAuto(); } } private bool _connecting; public bool Connecting { get { return _connecting; } set { _connecting = value; RaisePropertyChangedAuto(); } } private bool _disconnecting; public bool Disconnecting { get { return _disconnecting; } set { _disconnecting = value; RaisePropertyChangedAuto(); } } public WiFiNetwork(AccessPoint accessPoint, Wifi wifi) { _wifi = wifi; AccessPoint = accessPoint; } public WiFiAuthentication CreateAuthenticationRequest() { return new WiFiAuthentication(new AuthRequest(AccessPoint)); } public Task Connect(WiFiAuthentication request, bool overwriteProfile) { return Task.Factory.StartNew(() => { try { Connecting = true; return AccessPoint.Connect(request.AuthRequest, overwriteProfile); } catch (Exception) { throw; } finally { Connecting = false; } }); } public Task Disconnect() { return Task.Factory.StartNew(() => { try { Disconnecting = true; _wifi.Disconnect(); AccessPoint.DeleteProfile(); } catch (Exception) { throw; } finally { Disconnecting = false; } }); } public Task Forget() { return Task.Factory.StartNew(() => { try { AccessPoint.DeleteProfile(); } catch { } }); } } }