コード例 #1
0
        public VpnTrayTabViewModel(VpnProvider vpnProvider, IVpnTrayConfigurationProvider configurationProvider)
        {
            _vpnProvider           = vpnProvider;
            _configurationProvider = configurationProvider;

            Settings = new ObservableCollection <VpnTraySettingsEntryViewModel>();
            Icons    = new ObservableCollection <VpnTrayIconViewModel>();

            vpnProvider.VpnEnumerator.Vpns.Clear();
            if (!configurationProvider.Configuration.Entries.TryGetValue(vpnProvider.Name, out var entries))
            {
                configurationProvider.Configuration.Entries[vpnProvider.Name] = entries = new List <VpnTraySettingsEntryConfiguration>();
                configurationProvider.Save();
            }
            foreach (var entry in entries)
            {
                var vpn = new Vpn(entry.Id, entry.Name);
                vpnProvider.VpnEnumerator.Vpns.Add(vpn);

                var vm = new VpnTraySettingsEntryViewModel(vpnProvider.VpnManagerFactory.Create(vpn), entry);
                vm.PropertyChanged += Entry_PropertyChanged;
                Settings.Add(vm);

                if (vm.IsSelected)
                {
                    Icons.Add(new VpnTrayIconViewModel(vm.VpnManager));
                }
            }

            vpnProvider.VpnEnumerator.Added   += (s, e) => AddManager(e.Vpn);
            vpnProvider.VpnEnumerator.Removed += (s, e) => RemoveManager(e.Vpn);

            vpnProvider.VpnEnumerator.RefreshInterval = configurationProvider.Configuration.EnumeratorRefreshInterval;
            vpnProvider.VpnEnumerator.IsEnabled       = true;
        }
コード例 #2
0
        private void AddManager(Vpn vpn)
        {
            var configuration = new VpnTraySettingsEntryConfiguration
            {
                Id              = vpn.Id,
                Name            = vpn.Name,
                IsSelected      = false,
                RefreshInterval = _configurationProvider.Configuration.DefaultMonitorRefreshInterval
            };

            _configurationProvider.Configuration.Entries[_vpnProvider.Name].Add(configuration);
            _configurationProvider.Save();

            var entry = new VpnTraySettingsEntryViewModel(_vpnProvider.VpnManagerFactory.Create(vpn), configuration);

            entry.PropertyChanged += Entry_PropertyChanged;
            Settings.Add(entry);
        }