private void buttonUpdate_Click(System.Object sender, System.EventArgs e)
        {
            Cursor old = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;
            Exception ex = null;

            try
            {
                if (!SaveData())
                {
                    return;
                }


                m_cfgHelper.MaintainConnection = false;


                if (m_cfg.ConfigurationType == MFNetworkConfiguration.NetworkConfigType.Wireless)
                {
                    if (ValidateWirelessData())
                    {
                        m_wirelessCfg.Save();
                        m_cfg.SwapConfigBuffer(m_wirelessCfg.m_cfgHelper);
                    }
                    else
                    {
                        return;
                    }
                }

                m_cfg.Save();

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception e1)
            {
                /// First, we throw System.Exception from SaveData(), so we are ending up catching essentially
                /// all exceptions here.
                /// And then, failing to catch an exception here would abruptly end NetworkDialog's message loop,
                /// not a good termination scenario, instead we should communicate this to user, and give user
                /// option either to correct the reason, or press "Cancel". Exceptions are thrown usually for
                /// bad data, invalid format of data, or some issue in the device.
                ex = e1;
            }
            finally
            {
                Cursor.Current = old;
            }

            if (ex != null)
            {
                MessageBox.Show(this, ex.Message, Properties.Resources.NetworkTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #2
0
        private void SaveNetworkSettings(bool logToConsole = true)
        {
            MFNetworkConfiguration mfNetConfig = new MFNetworkConfiguration();

            mfNetConfig.Load(_networkManager);

            mfNetConfig.IpAddress         = _networkConfig.StaticIPAddress;
            mfNetConfig.SubNetMask        = _networkConfig.SubnetMask;
            mfNetConfig.PrimaryDns        = _networkConfig.PrimaryDNS;
            mfNetConfig.SecondaryDns      = _networkConfig.SecondaryDNS;
            mfNetConfig.Gateway           = _networkConfig.DefaultGateway;
            mfNetConfig.MacAddress        = _networkConfig.NetworkMacAddress;
            mfNetConfig.EnableDhcp        = _networkConfig.EnableDHCP;
            mfNetConfig.ConfigurationType = _networkConfig.IsWireless ? MFNetworkConfiguration.NetworkConfigType.Wireless : MFNetworkConfiguration.NetworkConfigType.Generic;

            if (_networkConfig.IsWireless)
            {
                MFWirelessConfiguration mfWifiConfig = new MFWirelessConfiguration();
                mfWifiConfig.Load(_networkManager);

                mfWifiConfig.Authentication   = _networkConfig.Authentication;
                mfWifiConfig.Encryption       = _networkConfig.Encryption;
                mfWifiConfig.Radio            = _networkConfig.Radio;
                mfWifiConfig.PassPhrase       = _networkConfig.Passphrase;
                mfWifiConfig.UseEncryption    = _networkConfig.EncryptConfig;
                mfWifiConfig.NetworkKeyLength = _networkConfig.NetworkKeyLength;
                mfWifiConfig.NetworkKey       = _networkConfig.NetworkKey;
                mfWifiConfig.ReKeyLength      = _networkConfig.ReKeyInternal.Length / 2;
                mfWifiConfig.ReKeyInternal    = _networkConfig.ReKeyInternal;
                mfWifiConfig.SSID             = _networkConfig.SSID;

                mfWifiConfig.Save(_networkManager);
            }
            mfNetConfig.Save(_networkManager);

            if (logToConsole)
            {
                OutputToConsole("Network settings saved.");
            }
        }