Пример #1
0
        public async Task <bool> UpdateVpnUIItemStatus(AsusSshVpnService asusCommander)
        {
            if (asusCommander.Connection.IsConnected)
            {
                var vpnStatus = await asusCommander.Status();

                foreach (var key in vpnStatus.Keys)
                {
                    VpnUIItems[key].Status = vpnStatus[key];
                }

                return(true);
            }

            return(false);
        }
Пример #2
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);
        }