Exemplo n.º 1
0
 public void SaveVpnUIItemsPreferences(VeeKeePreferences preferences)
 {
     for (int i = 1; i < VpnUIItems.Count + 1; i++)
     {
         var vpnUIItem = VpnUIItems[i];
         preferences.SetVpnName(i, vpnUIItem.Name);
         preferences.SetVpnFlag(i, vpnUIItem.FlagResourceId.ToString());
     }
 }
Exemplo n.º 2
0
        public void LoadVpnUIItemsFromPreferences(VeeKeePreferences preferences)
        {
            for (int i = 1; i < this._resources.GetInteger(Resource.Integer.VpnItemCount) + 1; i++)
            {
                var vpnItemName = string.Format(this._resources.GetString(Resource.String.VpnClientFormat), i);

                VpnUIItems.Add(i, new VpnUIItem(preferences.GetVpnName(i), GetFlagResourceId(preferences.GetVpnFlag(i), this._packageName, this._resources), VpnStatus.Off));
            }
        }
Exemplo n.º 3
0
        public async Task <bool> AutoConfigureFromRouterSettings(AsusSshVpnService asusCommander, VeeKeePreferences preferences)
        {
            Dictionary <int, VpnDetails> vpnDetails = null;

            var connected = await asusCommander.Connect();

            var routerStatus = asusCommander.Connection.Status;

            if (routerStatus == RouterConnectionStatus.Connected)
            {
                // Get a Dictionary of all the VPN details from the router settings
                vpnDetails = await asusCommander.Details();
            }

            for (int i = 1; i < VpnUIItems.Count + 1; i++)
            {
                var vpnUIItem = VpnUIItems[i];

                vpnUIItem.Name = vpnDetails[i].Name;
            }

            // Lookup the country codes for each configured VPN
            foreach (int vpnIndex in vpnDetails.Keys)
            {
                var address = vpnDetails[vpnIndex].Address;

                if (address != string.Empty)
                {
                    string countryCode = await IPStackCountryLookupService.LookupAsync(vpnDetails[vpnIndex].Address, new CancellationTokenSource().Token);

                    if (countryCode != null)
                    {
                        int flagResourceId = GetFlagResourceId(countryCode, this._packageName, this._resources);
                        VpnUIItems[vpnIndex].FlagResourceId = flagResourceId;
                    }
                }
            }

            this.SaveVpnUIItemsPreferences(preferences);

            return(true);
        }