Beispiel #1
0
        private async Task ExecuteConnectToBestProfileAsync(Profile profile, Profile fallbackProfile = null, int?maxServers = null)
        {
            IList <Profile>             profiles          = CreateProfilePreferenceList(profile, fallbackProfile);
            VpnManagerProfileCandidates profileCandidates = GetBestProfileCandidates(profiles);

            await ConnectToProfileCandidatesAsync(profileCandidates, maxServers : maxServers);
        }
Beispiel #2
0
 private async Task ConnectToProfileCandidatesAsync(VpnManagerProfileCandidates profileCandidates, Protocol?protocol = null, int?maxServers = null)
 {
     if (profileCandidates.CanConnect)
     {
         await ConnectAsync(profileCandidates.Profile, profileCandidates.Candidates, protocol, maxServers);
     }
     else
     {
         _profileConnector.HandleNoServersAvailable(profileCandidates.Candidates.Items, profileCandidates.Profile);
     }
 }
Beispiel #3
0
        private async Task ConnectToBestProfileAsync(Profile profile, Profile fallbackProfile = null)
        {
            IList <Profile>             profiles          = this.CreateProfilePreferenceList(profile, fallbackProfile);
            VpnManagerProfileCandidates profileCandidates = this.GetBestProfileCandidates(profiles);

            if (profileCandidates.CanConnect)
            {
                await ConnectAsync(profileCandidates.Profile, profileCandidates.Candidates);
            }
            else
            {
                _profileConnector.HandleNoServersAvailable(profileCandidates.Candidates.Items, profileCandidates.Profile);
            }
        }
Beispiel #4
0
        private VpnManagerProfileCandidates GetBestProfileCandidates(IList <Profile> profiles)
        {
            VpnManagerProfileCandidates bestProfileCandidates = new VpnManagerProfileCandidates();

            foreach (Profile profile in profiles)
            {
                bestProfileCandidates.Profile    = profile;
                bestProfileCandidates.Candidates = _profileConnector.ServerCandidates(profile);
                bestProfileCandidates.CanConnect = _profileConnector.CanConnect(bestProfileCandidates.Candidates, profile);

                if (bestProfileCandidates.CanConnect)
                {
                    break;
                }
            }

            return(bestProfileCandidates);
        }
Beispiel #5
0
        public async Task <IList <Server> > GetSortedAndValidQuickConnectServersAsync(int?maxServers = null)
        {
            Profile profile = await GetQuickConnectProfileAsync();

            IList <Profile>             profiles          = CreateProfilePreferenceList(profile);
            VpnManagerProfileCandidates profileCandidates = GetBestProfileCandidates(profiles);

            IEnumerable <Server> sortedServers = _profileConnector.SortServers(
                _profileConnector.Servers(profileCandidates.Candidates),
                profileCandidates.Profile.ProfileType);

            if (maxServers.HasValue)
            {
                sortedServers = sortedServers.Take(maxServers.Value);
            }

            return(sortedServers.ToList());
        }
Beispiel #6
0
        private async Task ExecuteConnectToProfileAsync(Profile profile, Protocol?protocol = null)
        {
            VpnManagerProfileCandidates profileCandidates = GetProfileCandidates(profile);

            await ConnectToProfileCandidatesAsync(profileCandidates, protocol);
        }