Ejemplo n.º 1
0
        public SuccessViewModel(IHotspot hotspot)
        {
            _hotspot                 = hotspot;
            this.CurrentSSID         = this.SSID = _hotspot.SSID;
            this.CurrentPresharedKey = this.PresharedKey = _hotspot.PresharedKey;

            var dirty = this.WhenAny(x => x.SSID, x => x.PresharedKey, x => x.CurrentSSID, x => x.CurrentPresharedKey,
                                     (ssid, psk, cssid, cpsk) => ssid.Value != cssid.Value || psk.Value != cpsk.Value);

            var valid = this.WhenAny(x => x.SSID, x => x.PresharedKey,
                                     (name, key) => IsSSIDValid(name.Value) && IsPresharedKeyValid(key.Value));

            var canAcceptChanges = Observable.CombineLatest(dirty, valid, (isDirty, isValid) => isDirty && isValid);

            canAcceptChanges.ToProperty(this, x => x.IsModified, out _modified);

            AcceptChanges = ReactiveCommand.CreateAsyncTask(
                canAcceptChanges,
                _ => Task.Run(() =>
            {
                _hotspot.Stop();

                _hotspot.SSID            = this.SSID;
                _hotspot.PresharedKey    = this.PresharedKey;
                this.CurrentSSID         = this.SSID;
                this.CurrentPresharedKey = this.PresharedKey;

                _hotspot.Start();
            }));
        }
Ejemplo n.º 2
0
 private async void StopHotspotBtn_Click(object sender, EventArgs e)
 {
     try { await _hotspot.Stop(); }
     catch (HotspotException) { MessageBox.Show(this, "Couldn't succesfully stop the hotspot.", "Error stopping hotspot", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }