Ejemplo n.º 1
0
 private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (e.CloseReason == CloseReason.None && this.DialogResult == DialogResult.OK)
     {
         var config = new ConnectManagerConfig
         {
             VpnClientPath    = pathToClient_textBox.Text,
             PingAddress      = pingAddress_textBox.Text,
             ReconnectDelay   = (int)reconnectDelay_numericUpDown.Value,
             VerifyPeriod     = (int)verifyPeriod_numericUpDown.Value,
             VpnProfileName   = vpnProfileName_textBox.Text,
             EnableBypassTime = enableBaypassTime_checkBox.Checked,
             BypassFrom       = TimeSpan.Parse(bypassFrom_maskedTextBox.Text),
             BypassTo         = TimeSpan.Parse(bypassTo_maskedTextBox.Text)
         };
         if (!new ConnectManagerConfigValidator().Validate(config))
         {
             e.Cancel = true;
             MessageBox.Show(this, "Config has errors. Change values.", "Config has errors");
             return;
         }
         _config.VpnClientPath    = config.VpnClientPath;
         _config.PingAddress      = config.PingAddress;
         _config.ReconnectDelay   = config.ReconnectDelay;
         _config.VerifyPeriod     = config.VerifyPeriod;
         _config.VpnProfileName   = config.VpnProfileName;
         _config.EnableBypassTime = config.EnableBypassTime;
         _config.BypassFrom       = config.BypassFrom;
         _config.BypassTo         = config.BypassTo;
     }
 }
        private void SaveSettings(ConnectManagerConfig config)
        {
            Properties.Settings.Default.VpnClientPath    = config.VpnClientPath;
            Properties.Settings.Default.PingAddress      = config.PingAddress;
            Properties.Settings.Default.ReconnectDelay   = config.ReconnectDelay;
            Properties.Settings.Default.VerifyPeriod     = config.VerifyPeriod;
            Properties.Settings.Default.VpnProfileName   = config.VpnProfileName;
            Properties.Settings.Default.EnableBypassTime = config.EnableBypassTime;
            Properties.Settings.Default.BypassFrom       = config.BypassFrom;
            Properties.Settings.Default.BypassTo         = config.BypassTo;

            Properties.Settings.Default.Save();
        }
        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);
        }
        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);
        }
Ejemplo n.º 5
0
        public SettingsForm(ConnectManagerConfig config)
        {
            InitializeComponent();

            _config = config;

            reconnectDelay_numericUpDown.Maximum = int.MaxValue;
            verifyPeriod_numericUpDown.Maximum   = int.MaxValue;

            pathToClient_textBox.Text          = config.VpnClientPath;
            pingAddress_textBox.Text           = config.PingAddress;
            reconnectDelay_numericUpDown.Value = config.ReconnectDelay;
            verifyPeriod_numericUpDown.Value   = config.VerifyPeriod;
            vpnProfileName_textBox.Text        = config.VpnProfileName;
            enableBaypassTime_checkBox.Checked = config.EnableBypassTime;
            bypassFrom_maskedTextBox.Text      = config.BypassFrom.ToString();
            bypassTo_maskedTextBox.Text        = config.BypassTo.ToString();
        }
        public ConnectManager(ConnectManagerConfig config, ConsoleRunnerDataReceived outputCallback)
        {
            _runner = new AsyncConsoleRunner();
            _runner.OnConsoleRunnerDataReceived      += (s, p) => outputCallback(this, p);
            _runner.OnConsoleRunnerErrorDataReceived += (s, p) => outputCallback(this, p);

            _ping = new Ping();

            _address           = config.PingAddress;
            _clientPath        = config.VpnClientPath;
            _connectCommand    = $" connect \"{config.VpnProfileName}\"";
            _disconnectCommand = $" disconnect";

            _delay          = config.ReconnectDelay;
            _verifyInterval = config.VerifyPeriod;
            _connected      = false;

            _enabledBypass = config.EnableBypassTime;
            _bypassFrom    = config.BypassFrom;
            _bypassTo      = config.BypassTo;
        }