Exemple #1
0
        public bool ConnectVpn(int vpnId)
        {
            if (_ListVpn.ContainsKey(vpnId))
            {
                //Connection already established
                if (_ListVpn[vpnId].IsConnected)
                {
                    _ListVpn[vpnId].ConnectionCounter++; //One more connection uses this VPN
                    return(true);
                }

                if (_ListVpn[vpnId].Connect() == false)
                {
                    return(false);
                }

                _ListVpn[vpnId].ConnectionCounter++; //One more connection uses this VPN
                return(true);
            }

            VpnBase vpnConnection = GetUserVpnConnection(vpnId);

            //Add VPN-Connection to list
            if (vpnConnection != null)
            {
                _ListVpn.Add(vpnConnection.Id, vpnConnection);
                _ListVpn[vpnId].ConnectionCounter = 1;

                bool establishSuccess = vpnConnection.Connect();

                if (establishSuccess == false)
                {
                    _ListVpn.Remove(vpnConnection.Id);
                }

                return(establishSuccess);
            }

            return(false);
        }