public async Task Connect(ServerCandidates candidates, Profile profile)
        {
            var servers = Servers(candidates);

            var sortedServers = Sorted(servers, profile.ProfileType);

            await Connect(sortedServers, VpnProtocol(profile.Protocol));
        }
        public ServerCandidates ServerCandidates(Profile profile)
        {
            if (profile == null)
            {
                return(_serverCandidatesFactory.ServerCandidates(new Server[0]));
            }

            var serverSpec = ProfileServerSpec(profile);
            var servers    = _serverManager.GetServers(serverSpec);

            return(_serverCandidatesFactory.ServerCandidates(servers));
        }
        public bool CanConnect(ServerCandidates candidates, Profile profile)
        {
            var servers = Servers(candidates);

            if (servers.Any())
            {
                return(SwitchSecureCoreMode(servers.First().IsSecureCore()));
            }

            HandleNoServersAvailable(candidates.Items, profile);

            return(false);
        }
        public async Task <bool> UpdateServers(ServerCandidates candidates, Profile profile)
        {
            var servers = Servers(candidates);

            if (!servers.Any())
            {
                return(false);
            }

            var sortedServers = Sorted(servers, profile.ProfileType);

            await UpdateServers(sortedServers);

            return(true);
        }
        private Specification <LogicalServerContract> ProfileServerSpec(Profile profile)
        {
            if (profile.ProfileType == ProfileType.Custom)
            {
                return(new ServerById(profile.ServerId));
            }

            Specification <LogicalServerContract> spec = new ServerByFeatures(ServerFeatures(profile));

            if (!string.IsNullOrEmpty(profile.CountryCode))
            {
                spec &= new ExitCountryServer(profile.CountryCode);
            }

            return(spec);
        }
        private void HandleNoServersAvailable(IReadOnlyCollection <Server> candidates, Profile profile)
        {
            if (profile.ProfileType == ProfileType.Custom)
            {
                HandleNoCustomServerAvailable(candidates.FirstOrDefault());
                return;
            }

            if ((profile.Features.IsSecureCore() || profile.IsPredefined && _appSettings.SecureCore) &&
                _userStorage.User().MaxTier < ServerTiers.Plus)
            {
                _modals.Show <ScUpsellModalViewModel>();
                return;
            }

            if (!string.IsNullOrEmpty(profile.CountryCode))
            {
                HandleNoCountryServersAvailable(candidates);
                return;
            }

            if (!candidates.Any())
            {
                _dialogs.ShowWarning(StringResources.Get("Profiles_msg_NoServersAvailable"));
                return;
            }

            var userTierServers = candidates.UpToTierServers(_userStorage.User().MaxTier);

            if (!userTierServers.Any())
            {
                if (candidates.BasicServers().Any())
                {
                    _modals.Show <UpsellModalViewModel>();
                    return;
                }

                if (candidates.PlusServers().Any())
                {
                    _modals.Show <PlusUpsellModalViewModel>();
                    return;
                }
            }

            if (!candidates.OnlineServers().Any())
            {
                _dialogs.ShowWarning(StringResources.Get("Profiles_msg_AllServersOffline"));
                return;
            }

            _modals.Show <NoServerDueTierUpsellModalViewModel>();
        }
 private Features ServerFeatures(Profile profile)
 {
     return(profile.IsPredefined
         ? _appSettings.SecureCore ? Features.SecureCore : Features.None
         : profile.Features);
 }
Beispiel #8
0
        public async Task <bool> OtherProfileWithNameExists(Profile profile)
        {
            var profiles = await GetProfiles();

            return(profiles.Any(p => !ProfileByIdEqualityComparer.Equals(p, profile) && ProfileByNameEqualityComparer.Equals(p, profile)));
        }
Beispiel #9
0
 public Task UpdateProfile(Profile profile)
 {
     AddCountryCode(profile);
     return(_profiles.Update(profile));
 }
Beispiel #10
0
 public Task RemoveProfile(Profile profile)
 {
     return(_profiles.Delete(profile));
 }
Beispiel #11
0
 public Task AddProfile(Profile profile)
 {
     AddCountryCode(profile);
     return(_profiles.Create(profile));
 }