private ConnectManager ConnectManagerFactory(ConnectManagerConfig config)
        {
            _manager = new ConnectManager(
                _config,
                (s, p) => LogToTextEdit((ConnectManager)s, p));

            _logToTextBoxWriter = (manager, value) =>
            {
                pictureBox1.BackColor = manager.Connected ? Color.Green : Color.Red;
                textBox1.AppendText($"{DateTime.Now} > {value}\r\n");
            };

            return(_manager);
        }
        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_manager.Connected)
            {
                return;
            }

            var settingsForm = new SettingsForm(_config);
            var dialogResult = settingsForm.ShowDialog(this);

            if (dialogResult == DialogResult.OK)
            {
                _manager = ConnectManagerFactory(_config);
                SaveSettings(_config);
            }
        }
        public MainForm()
        {
            InitializeComponent();

            _config = new ConnectManagerConfig
            {
                VpnClientPath    = Properties.Settings.Default.VpnClientPath,
                PingAddress      = Properties.Settings.Default.PingAddress,
                ReconnectDelay   = Properties.Settings.Default.ReconnectDelay,
                VerifyPeriod     = Properties.Settings.Default.VerifyPeriod,
                VpnProfileName   = Properties.Settings.Default.VpnProfileName,
                EnableBypassTime = Properties.Settings.Default.EnableBypassTime,
                BypassFrom       = Properties.Settings.Default.BypassFrom,
                BypassTo         = Properties.Settings.Default.BypassTo
            };

            _manager = ConnectManagerFactory(_config);
        }
 private void LogToTextEdit(ConnectManager manager, string value)
 {
     lock (lockObject) {
         textBox1.Invoke(_logToTextBoxWriter, manager, value);
     }
 }