示例#1
0
        public async Task Connect(ServerCandidates candidates, Profile profile)
        {
            var servers = Servers(candidates);

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

            await Connect(sortedServers, VpnProtocol(profile.Protocol));
        }
示例#2
0
        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));
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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>();
        }
示例#7
0
 private Features ServerFeatures(Profile profile)
 {
     return(profile.IsPredefined
         ? _appSettings.SecureCore ? Features.SecureCore : Features.None
         : profile.Features);
 }
示例#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)));
        }
示例#9
0
 public Task UpdateProfile(Profile profile)
 {
     AddCountryCode(profile);
     return(_profiles.Update(profile));
 }
示例#10
0
 public Task RemoveProfile(Profile profile)
 {
     return(_profiles.Delete(profile));
 }
示例#11
0
 public Task AddProfile(Profile profile)
 {
     AddCountryCode(profile);
     return(_profiles.Create(profile));
 }