Ejemplo n.º 1
0
        private async void AddProfileAction()
        {
            MetroDialogSettings settings = AppearanceManager.MetroDialog;

            settings.AffirmativeButtonText = Application.Current.Resources["String_Button_Add"] as string;
            settings.NegativeButtonText    = Application.Current.Resources["String_Button_Cancel"] as string;

            string name = await dialogCoordinator.ShowInputAsync(this, Application.Current.Resources["String_Header_AddProfile"] as string, Application.Current.Resources["String_EnterNameForProfile"] as string, settings);

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            string configSubnetmask = ConfigSubnetmaskOrCidr;

            if (ConfigEnableStaticIPAddress && ConfigSubnetmaskOrCidr.StartsWith("/"))
            {
                configSubnetmask = Subnetmask.GetFromCidr(int.Parse(ConfigSubnetmaskOrCidr.TrimStart('/'))).Subnetmask;
            }

            NetworkInterfaceProfileInfo profile = new NetworkInterfaceProfileInfo
            {
                Name = name,
                EnableStaticIPAddress = ConfigEnableStaticIPAddress,
                IPAddress             = ConfigIPAddress,
                Gateway            = ConfigGateway,
                Subnetmask         = configSubnetmask,
                EnableStaticDNS    = ConfigEnableStaticDNS,
                PrimaryDNSServer   = ConfigPrimaryDNSServer,
                SecondaryDNSServer = ConfigSecondaryDNSServer
            };

            NetworkInterfaceProfileManager.AddProfile(profile);
        }
Ejemplo n.º 2
0
        public NetworkInterfaceViewModel(IDialogCoordinator instance)
        {
            dialogCoordinator = instance;

            // Load network interfaces
            LoadNetworkInterfaces();

            // Load profiles
            if (NetworkInterfaceProfileManager.Profiles == null)
            {
                NetworkInterfaceProfileManager.Load();
            }

            _networkInterfaceProfiles = CollectionViewSource.GetDefaultView(NetworkInterfaceProfileManager.Profiles);
            _networkInterfaceProfiles.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            _networkInterfaceProfiles.Filter = o =>
            {
                if (string.IsNullOrEmpty(Search))
                {
                    return(true);
                }

                NetworkInterfaceProfileInfo info = o as NetworkInterfaceProfileInfo;

                string search = Search.Trim();

                // Search by: Name
                return(info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1);
            };

            LoadSettings();

            _isLoading = false;
        }
        private async void AddProfileAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = Application.Current.Resources["String_Header_AddProfile"] as string
            };

            NetworkInterfaceProfileViewModel networkInterfaceProfileViewModel = new NetworkInterfaceProfileViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                NetworkInterfaceProfileInfo networkInterfaceProfileInfo = new NetworkInterfaceProfileInfo
                {
                    Name = instance.Name,
                    EnableStaticIPAddress = instance.EnableStaticIPAddress,
                    IPAddress             = instance.IPAddress,
                    Subnetmask            = instance.SubnetmaskOrCidr,
                    Gateway            = instance.Gateway,
                    EnableStaticDNS    = instance.EnableStaticDNS,
                    PrimaryDNSServer   = instance.PrimaryDNSServer,
                    SecondaryDNSServer = instance.SecondaryDNSServer,
                    Group = instance.Group
                };

                NetworkInterfaceProfileManager.AddProfile(networkInterfaceProfileInfo);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, NetworkInterfaceProfileManager.GetProfileGroups(), new NetworkInterfaceProfileInfo()
            {
                EnableStaticIPAddress = ConfigEnableStaticIPAddress, IPAddress = ConfigIPAddress, Subnetmask = ConfigSubnetmaskOrCidr, Gateway = ConfigGateway, EnableStaticDNS = ConfigEnableStaticDNS, PrimaryDNSServer = ConfigPrimaryDNSServer, SecondaryDNSServer = ConfigSecondaryDNSServer
            });

            customDialog.Content = new NetworkInterfaceProfileDialog
            {
                DataContext = networkInterfaceProfileViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Ejemplo n.º 4
0
        private async void EditProfileAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = LocalizationManager.GetStringByKey("String_Header_EditProfile")
            };

            NetworkInterfaceProfileViewModel networkInterfaceProfileViewModel = new NetworkInterfaceProfileViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                NetworkInterfaceProfileManager.RemoveProfile(SelectedProfile);

                NetworkInterfaceProfileInfo networkInterfaceProfileInfo = new NetworkInterfaceProfileInfo
                {
                    Name = instance.Name,
                    EnableStaticIPAddress = instance.EnableStaticIPAddress,
                    IPAddress             = instance.IPAddress,
                    Subnetmask            = instance.SubnetmaskOrCidr,
                    Gateway            = instance.Gateway,
                    EnableStaticDNS    = instance.EnableStaticDNS,
                    PrimaryDNSServer   = instance.PrimaryDNSServer,
                    SecondaryDNSServer = instance.SecondaryDNSServer,
                    Group = instance.Group
                };

                NetworkInterfaceProfileManager.AddProfile(networkInterfaceProfileInfo);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, NetworkInterfaceProfileManager.GetProfileGroups(), SelectedProfile);

            customDialog.Content = new NetworkInterfaceProfileDialog
            {
                DataContext = networkInterfaceProfileViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Ejemplo n.º 5
0
        public NetworkInterfaceProfileViewModel(Action <NetworkInterfaceProfileViewModel> saveCommand, Action <NetworkInterfaceProfileViewModel> cancelHandler, List <string> groups, NetworkInterfaceProfileInfo profileInfo = null)
        {
            _saveCommand   = new RelayCommand(p => saveCommand(this));
            _cancelCommand = new RelayCommand(p => cancelHandler(this));

            _profileInfo = profileInfo ?? new NetworkInterfaceProfileInfo();

            Name = _profileInfo.Name;
            EnableStaticIPAddress = _profileInfo.EnableStaticIPAddress;
            IPAddress             = profileInfo.IPAddress;
            SubnetmaskOrCidr      = _profileInfo.Subnetmask;
            Gateway            = _profileInfo.Gateway;
            EnableStaticDNS    = _profileInfo.EnableStaticDNS;
            PrimaryDNSServer   = _profileInfo.PrimaryDNSServer;
            SecondaryDNSServer = _profileInfo.SecondaryDNSServer;
            Group = string.IsNullOrEmpty(_profileInfo.Group) ? Application.Current.Resources["String_Default"] as string : _profileInfo.Group;

            _groups = CollectionViewSource.GetDefaultView(groups);
            _groups.SortDescriptions.Add(new SortDescription());

            _isLoading = false;
        }
Ejemplo n.º 6
0
        public NetworkInterfaceProfileViewModel(Action <NetworkInterfaceProfileViewModel> saveCommand, Action <NetworkInterfaceProfileViewModel> cancelHandler, List <string> groups, NetworkInterfaceProfileInfo profileInfo = null)
        {
            _saveCommand   = new RelayCommand(p => saveCommand(this));
            _cancelCommand = new RelayCommand(p => cancelHandler(this));

            _profileInfo = profileInfo ?? new NetworkInterfaceProfileInfo();

            Name = _profileInfo.Name;
            EnableStaticIPAddress = _profileInfo.EnableStaticIPAddress;
            IPAddress             = profileInfo.IPAddress;
            SubnetmaskOrCidr      = _profileInfo.Subnetmask;
            Gateway            = _profileInfo.Gateway;
            EnableStaticDNS    = _profileInfo.EnableStaticDNS;
            PrimaryDNSServer   = _profileInfo.PrimaryDNSServer;
            SecondaryDNSServer = _profileInfo.SecondaryDNSServer;

            // Get the group, if not --> get the first group (ascending), fallback --> default group
            Group = string.IsNullOrEmpty(_profileInfo.Group) ? (groups.Count > 0 ? groups.OrderBy(x => x).First() : LocalizationManager.GetStringByKey("String_Default")) : _profileInfo.Group;

            _groups = CollectionViewSource.GetDefaultView(groups);
            _groups.SortDescriptions.Add(new SortDescription());

            _isLoading = false;
        }