Ejemplo n.º 1
0
        static private void watcher_Connected(object sender, RasConnectionEventArgs e)
        {
            // A connection has successfully connected.
            Log.ProcessDebug("Event " + VpnSelectorLibRes.A_connection_has_successfully_connected_ + e.Connection.EntryName);

            BaseProxyServer oldProxy = NetConnUtils.CurrentProxyServer;

            if (IsSynchMode == false)
            {
                NetConnUtils.CurrentProxyServer = BaseProxyServer.FindFromNames(NetConnUtils.GetActiveConnectionsNames());
            }
            if (VpnConnectedEvent != null)
            {
                VpnConnectedEvent(null, new VpnConnectedEventArgs());
            }
            if (IsSynchMode == false)
            {
                if ((oldProxy == null && NetConnUtils.CurrentProxyServer != null) ||
                    (oldProxy != null && oldProxy != NetConnUtils.CurrentProxyServer))
                {
                    //proxy changed
                    NetConnUtils.ConfirmIpAddressAsync();
                }
            }
        }
Ejemplo n.º 2
0
        private static void Dialer_DialCompleted(object sender, DialCompletedEventArgs e)
        {
            //Note: events are not generated when manipulating with a connection from outside
            if (e.Cancelled)
            {
                Log.ProcessDebug("Event Dialer Cancelled");
            }
            else if (e.TimedOut)
            {
                Log.ProcessDebug("Event Dialer Timeout");
            }
            else if (e.Connected)
            {
                Log.ProcessDebug("Event Dialer Connection successful");
            }
            else if (e.Error != null)
            {
                Log.LogError("Event Dialer Error " + e.Error.ToString(), e.Error);
                try
                {
                    if (dialer.EntryName != null)
                    {
                        BaseProxyServer currentProxyServer = BaseProxyServer.FindFromNames(new List <string>()
                        {
                            dialer.EntryName
                        });
                        if (currentProxyServer != null)
                        {
                            currentProxyServer.ErrorCount    = currentProxyServer.ErrorCount + 1;
                            currentProxyServer.LastErrorDate = DateTimeOffset.Now;
                            Dm.Instance.SaveObject(currentProxyServer);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.ProcessDebug("Event Error find BaseProxyServer " + ex);
                }

                if (IsSynchMode == false)
                {
                    if (VpnDialerErrorEvent != null)
                    {
                        VpnDialerErrorEvent(null, new VpnDialerErrorEventArgs()
                        {
                            Exception = e.Error
                        });
                    }
                }
            }
            if (!e.Connected)
            {
                Log.ProcessDebug("Dialer not connected");
            }
        }
Ejemplo n.º 3
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();
            }
        }