Ejemplo n.º 1
0
        protected void CreateVPNSupport()
        {
            NetConnUtils.InitSettings();

            //
            // vpnButton
            //
            this.vpnButton = new System.Windows.Forms.ToolStripSplitButton();
            this.vpnButton.DisplayStyle          = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.vpnButton.Enabled               = true;
            this.vpnButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.vpnButton.Name        = "vpnButton";
            this.vpnButton.Size        = new System.Drawing.Size(19, 23);
            this.vpnButton.Text        = "VPN";
            this.vpnButton.ToolTipText = "VPN";
            vpnButton.Image            = VpnSelectorLibRes.network_off;
            //vpnButton.DoubleClick += VpnButton_DoubleClick; - do not working

            //
            // ipAddressLabel
            //
            this.ipAddressLabel             = new System.Windows.Forms.ToolStripStatusLabel();
            this.ipAddressLabel.AutoToolTip = true;
            this.ipAddressLabel.Enabled     = false;
            this.ipAddressLabel.Name        = "ipAddressLabel";
            this.ipAddressLabel.Size        = new System.Drawing.Size(66, 20);
            this.ipAddressLabel.Text        = "127.0.0.1";
            this.ipAddressLabel.ToolTipText = "127.0.0.1";

            this.statusBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.eventWarrningButton, this.vpnButton, this.ipAddressLabel
            });

            if (useMainTrayIconForVPN && BaseApplicationContext.NotifyIcon != null)
            {
                vpnNotifyIcon = BaseApplicationContext.NotifyIcon;
            }
            else
            {
                vpnNotifyIcon = new NotifyIcon(components)
                {
                    ContextMenuStrip = new ContextMenuStrip(),
                    Icon             = vpnOffIcon,
                    Text             = "VPN",
                    Visible          = true
                };
            }

            vpnButton.MouseDown += VpnButton_MouseDown;
            vpnNotifyIcon.ContextMenuStrip.Opening += VpnNotifyIconContextMenuStrip_Opening;
            vpnNotifyIcon.DoubleClick += VpnNotifyIcon_DoubleClick;

            NetConnUtils.OnNetworkChekComplatedEvent += JustNetworkUtils_OnNetworkChekComplatedEvent;
            NetConnUtils.VpnDisconnectedEvent        += VpnSelector_OnVpnDisconnectedEvent;
            NetConnUtils.VpnConnectedEvent           += VpnSelector_OnVpnConnectedEvent;
            NetConnUtils.VpnDialerErrorEvent         += VpnSelector_OnVpnDialerErrorEvent;

            NetConnUtils.CreateDialerAndBeginWatch();
            bool _isActiveConnectionPresent = NetConnUtils.IsActiveConnectionPresent();

            if (_isActiveConnectionPresent)
            {
                NetConnUtils.CurrentProxyServer = BaseProxyServer.FindFromNames(NetConnUtils.GetActiveConnectionsNames());
                ProcessVpnConnectedEvent();
                //DotRasUtils.CurrentProxyServer = DotRasUtils.CurrentProxyServer;
            }
            else
            {
                NetConnUtils.ConfirmIpAddressAsync();
            }
        }