private void CalculateIPv4SubnetAction()
        {
            IsDetailsVisible = false;

            string[] subnet = Subnet.Trim().Split('/');

            string subnetmask = subnet[1];

            // Convert CIDR to subnetmask
            if (subnetmask.Length < 3)
            {
                subnetmask = Subnetmask.GetFromCidr(int.Parse(subnet[1])).Subnetmask;
            }

            SubnetInfo subnetInfo = Models.Network.Subnet.CalculateIPv4Subnet(IPAddress.Parse(subnet[0]), IPAddress.Parse(subnetmask));

            DetailsNetworkAddress = subnetInfo.NetworkAddress;
            DetailsBroadcast      = subnetInfo.Broadcast;
            DetailsSubnetmask     = subnetInfo.Subnetmask;
            DetailsCIDR           = subnetInfo.CIDR;
            DetailsIPAddresses    = subnetInfo.IPAddresses;
            DetailsFirstIPAddress = subnetInfo.HostFirstIP;
            DetailsLastIPAddress  = subnetInfo.HostLastIP;
            DetailsHosts          = subnetInfo.Hosts;

            IsDetailsVisible = true;

            SubnetHistory = new List <string>(HistoryListHelper.Modify(SubnetHistory, Subnet, SettingsManager.Current.Application_HistoryListEntries));
        }
示例#2
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);
        }
示例#3
0
        private void CalculateIPv4SubnetAction()
        {
            IsDetailsVisible = false;

            string[] subnet = Subnet.Trim().Split('/');

            string subnetmask = subnet[1];

            // Convert CIDR to subnetmask
            if (subnetmask.Length < 3)
            {
                subnetmask = Subnetmask.GetFromCidr(int.Parse(subnet[1])).Subnetmask;
            }

            SubnetInfo subnetInfo = Models.Network.Subnet.CalculateIPv4Subnet(IPAddress.Parse(subnet[0]), IPAddress.Parse(subnetmask));

            DetailsNetworkAddress = subnetInfo.NetworkAddress;
            DetailsBroadcast      = subnetInfo.Broadcast;
            DetailsSubnetmask     = subnetInfo.Subnetmask;
            DetailsCIDR           = subnetInfo.CIDR;
            DetailsIPAddresses    = subnetInfo.IPAddresses;
            DetailsFirstIPAddress = subnetInfo.HostFirstIP;
            DetailsLastIPAddress  = subnetInfo.HostLastIP;
            DetailsHosts          = subnetInfo.Hosts;

            IsDetailsVisible = true;

            AddSubnetToHistory(Subnet);
        }
示例#4
0
        public async void ApplyNetworkInterfaceConfig()
        {
            IsConfigurationRunning = true;
            DisplayStatusMessage   = false;

            string subnetmask = ConfigSubnetmaskOrCidr;

            // CIDR to subnetmask
            if (ConfigEnableStaticIPAddress && subnetmask.StartsWith("/"))
            {
                subnetmask = Subnetmask.GetFromCidr(int.Parse(subnetmask.TrimStart('/'))).Subnetmask;
            }

            // If primary and secondary DNS are empty --> autoconfiguration
            if (ConfigEnableStaticDNS && string.IsNullOrEmpty(ConfigPrimaryDNSServer) && string.IsNullOrEmpty(ConfigSecondaryDNSServer))
            {
                ConfigEnableDynamicDNS = true;
            }

            // When primary DNS is empty, swap it with secondary (if not empty)
            if (ConfigEnableStaticDNS && string.IsNullOrEmpty(ConfigPrimaryDNSServer) && !string.IsNullOrEmpty(ConfigSecondaryDNSServer))
            {
                ConfigPrimaryDNSServer   = ConfigSecondaryDNSServer;
                ConfigSecondaryDNSServer = string.Empty;
            }

            NetworkInterfaceConfig config = new NetworkInterfaceConfig
            {
                Name = SelectedNetworkInterface.Name,
                EnableStaticIPAddress = ConfigEnableStaticIPAddress,
                IPAddress             = ConfigIPAddress,
                Subnetmask            = subnetmask,
                Gateway            = ConfigGateway,
                EnableStaticDNS    = ConfigEnableStaticDNS,
                PrimaryDNSServer   = ConfigPrimaryDNSServer,
                SecondaryDNSServer = ConfigSecondaryDNSServer
            };

            try
            {
                Models.Network.NetworkInterface networkInterface = new Models.Network.NetworkInterface();

                networkInterface.UserHasCanceled += NetworkInterface_UserHasCanceled;

                await networkInterface.ConfigureNetworkInterfaceAsync(config);

                ReloadNetworkInterfacesAction();
            }
            catch (Exception ex)
            {
                StatusMessage        = ex.Message;
                DisplayStatusMessage = true;
            }
            finally
            {
                IsConfigurationRunning = false;
            }
        }
        private async void StartSplit()
        {
            DisplayStatusMessage = false;
            IsSplitRunning       = true;

            SplitResult.Clear();

            string[] subnetSplit         = Subnet.Trim().Split('/');
            string   newSubnetmaskOrCidr = NewSubnetmaskOrCIDR.TrimStart('/');

            // Validate the user input and display warning
            double cidr    = subnetSplit[1].Length < 3 ? double.Parse(subnetSplit[1]) : Subnetmask.ConvertSubnetmaskToCidr(subnetSplit[1]);
            double newCidr = newSubnetmaskOrCidr.Length < 3 ? double.Parse(newSubnetmaskOrCidr) : Subnetmask.ConvertSubnetmaskToCidr(newSubnetmaskOrCidr);

            if (65535 < (Math.Pow(2, (32 - cidr)) / Math.Pow(2, (32 - newCidr))))
            {
                MetroDialogSettings settings = AppearanceManager.MetroDialog;

                settings.AffirmativeButtonText = LocalizationManager.GetStringByKey("String_Button_Continue");
                settings.NegativeButtonText    = LocalizationManager.GetStringByKey("String_Button_Cancel");

                settings.DefaultButtonFocus = MessageDialogResult.Affirmative;

                if (await dialogCoordinator.ShowMessageAsync(this, LocalizationManager.GetStringByKey("String_Header_AreYouSure"), LocalizationManager.GetStringByKey("String_TheProcessCanTakeUpSomeTimeAndResources"), MessageDialogStyle.AffirmativeAndNegative, settings) != MessageDialogResult.Affirmative)
                {
                    CancelSplit    = false;
                    IsSplitRunning = false;

                    return;
                }
            }

            // Convert CIDR to subnetmask
            string subnetmask    = Subnetmask.GetFromCidr((int)cidr).Subnetmask;
            string newSubnetmask = Subnetmask.GetFromCidr((int)newCidr).Subnetmask;

            // Add history
            AddSubnetToHistory(Subnet);
            AddNewSubnetmaskOrCIDRToHistory(NewSubnetmaskOrCIDR);

            cancellationTokenSource = new CancellationTokenSource();

            try
            {
                foreach (SubnetInfo subnetInfo in await Models.Network.Subnet.SplitIPv4SubnetAsync(IPAddress.Parse(subnetSplit[0]), IPAddress.Parse(subnetmask), IPAddress.Parse(newSubnetmask), cancellationTokenSource.Token))
                {
                    SplitResult.Add(subnetInfo);
                }
            }
            catch (OperationCanceledException)
            {
                StatusMessage        = LocalizationManager.GetStringByKey("String_CanceledByUser");
                DisplayStatusMessage = true;
            }

            CancelSplit    = false;
            IsSplitRunning = false;
        }
示例#6
0
        private async void StartSplit()
        {
            DisplayStatusMessage = false;
            IsSplitRunning       = true;

            SplitResult.Clear();

            string[] subnetSplit = Subnet.Trim().Split('/');

            string subnetmask = subnetSplit[1];

            // Convert CIDR to subnetmask
            if (subnetmask.Length < 3)
            {
                subnetmask = Subnetmask.GetFromCidr(int.Parse(subnetSplit[1])).Subnetmask;
            }

            string newSubnetmask = NewSubnetmaskOrCIDR.TrimStart('/');

            if (newSubnetmask.Length < 3)
            {
                newSubnetmask = Subnetmask.GetFromCidr(int.Parse(newSubnetmask)).Subnetmask;
            }

            // Add history
            SubnetHistory = new List <string>(HistoryListHelper.Modify(SubnetHistory, Subnet, SettingsManager.Current.Application_HistoryListEntries));
            NewSubnetmaskOrCIDRHistory = new List <string>(HistoryListHelper.Modify(NewSubnetmaskOrCIDRHistory, NewSubnetmaskOrCIDR, SettingsManager.Current.Application_HistoryListEntries));

            cancellationTokenSource = new CancellationTokenSource();

            try
            {
                foreach (SubnetInfo subnetInfo in await Models.Network.Subnet.SplitIPv4SubnetAsync(IPAddress.Parse(subnetSplit[0]), IPAddress.Parse(subnetmask), IPAddress.Parse(newSubnetmask), cancellationTokenSource.Token))
                {
                    SplitResult.Add(subnetInfo);
                }
            }
            catch (OperationCanceledException)
            {
                StatusMessage        = Application.Current.Resources["String_CanceledByUser"] as string;
                DisplayStatusMessage = true;
            }

            CancelSplit    = false;
            IsSplitRunning = false;
        }
        private void CalculateIPv4SubnetAction()
        {
            string subnetmask = SubnetmaskOrCidr;

            if (SubnetmaskOrCidr.StartsWith("/"))
            {
                subnetmask = Subnetmask.GetFromCidr(int.Parse(SubnetmaskOrCidr.TrimStart('/'))).Subnetmask;
            }

            SubnetInfo subnetInfo = Subnet.CalculateIPv4Subnet(IPAddress.Parse(IPv4Address), IPAddress.Parse(subnetmask));

            DetailsNetworkAddress = subnetInfo.NetworkAddress;
            DetailsBroadcast      = subnetInfo.Broadcast;
            DetailsSubnetmask     = subnetInfo.Subnetmask;
            DetailsCIDR           = subnetInfo.CIDR;
            DetailsTotalIPs       = subnetInfo.TotalIPs;
            DetailsHostIPRange    = string.Format("{0} - {1}", subnetInfo.HostFirstIP, subnetInfo.HostLastIP);
            DetailsHostIPs        = subnetInfo.HostIPs;

            IsDetailsVisible = true;
        }
示例#8
0
        public async void ApplyNetworkInterfaceConfigAction()
        {
            DisplayStatusMessage = false;

            progressDialogController = await dialogCoordinator.ShowProgressAsync(this, Application.Current.Resources["String_ProgessHeader_ConfigureNetworkInterface"] as string, string.Empty);

            progressDialogController.SetIndeterminate();

            string configSubnetmask = ConfigSubnetmaskOrCidr;

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

            // If primary and secondary DNS are empty --> autoconfiguration
            if (ConfigEnableStaticDNS && string.IsNullOrEmpty(ConfigPrimaryDNSServer) && string.IsNullOrEmpty(ConfigSecondaryDNSServer))
            {
                ConfigEnableDynamicDNS = true;
            }

            // When primary DNS is empty, swap it with secondary (if not empty)
            if (ConfigEnableStaticDNS && string.IsNullOrEmpty(ConfigPrimaryDNSServer) && !string.IsNullOrEmpty(ConfigSecondaryDNSServer))
            {
                ConfigPrimaryDNSServer   = ConfigSecondaryDNSServer;
                ConfigSecondaryDNSServer = string.Empty;
            }

            NetworkInterfaceConfig config = new NetworkInterfaceConfig
            {
                Name = SelectedNetworkInterface.Name,
                EnableStaticIPAddress = ConfigEnableStaticIPAddress,
                IPAddress             = ConfigIPAddress,
                Subnetmask            = configSubnetmask,
                Gateway            = ConfigGateway,
                EnableStaticDNS    = ConfigEnableStaticDNS,
                PrimaryDNSServer   = ConfigPrimaryDNSServer,
                SecondaryDNSServer = ConfigSecondaryDNSServer
            };

            try
            {
                Models.Network.NetworkInterface networkInterface = new Models.Network.NetworkInterface();

                networkInterface.UserHasCanceled += NetworkInterface_UserHasCanceled;

                await networkInterface.ConfigureNetworkInterfaceAsync(config);

                ReloadNetworkInterfacesAction();
            }
            catch (Exception ex)
            {
                StatusMessage        = ex.Message;
                DisplayStatusMessage = true;
            }
            finally
            {
                await progressDialogController.CloseAsync();
            }
        }
示例#9
0
        private async void ApplyProfileAction()
        {
            DisplayStatusMessage = false;

            progressDialogController = await dialogCoordinator.ShowProgressAsync(this, Application.Current.Resources["String_Header_ConfigureNetworkInterface"] as string, string.Empty);

            progressDialogController.SetIndeterminate();

            string subnetmask = SelectedProfile.Subnetmask;

            // CIDR to subnetmask
            if (SelectedProfile.EnableStaticIPAddress && subnetmask.StartsWith("/"))
            {
                subnetmask = Subnetmask.GetFromCidr(int.Parse(subnetmask.TrimStart('/'))).Subnetmask;
            }

            bool enableStaticDNS = SelectedProfile.EnableStaticDNS;

            string primaryDNSServer   = SelectedProfile.PrimaryDNSServer;
            string secondaryDNSServer = SelectedProfile.SecondaryDNSServer;

            Debug.WriteLine(primaryDNSServer);
            Debug.WriteLine(secondaryDNSServer);

            // If primary and secondary DNS are empty --> autoconfiguration
            if (enableStaticDNS && string.IsNullOrEmpty(primaryDNSServer) && string.IsNullOrEmpty(secondaryDNSServer))
            {
                enableStaticDNS = false;
            }

            // When primary DNS is empty, swap it with secondary (if not empty)
            if (SelectedProfile.EnableStaticDNS && string.IsNullOrEmpty(primaryDNSServer) && !string.IsNullOrEmpty(secondaryDNSServer))
            {
                primaryDNSServer   = secondaryDNSServer;
                secondaryDNSServer = string.Empty;
            }

            NetworkInterfaceConfig config = new NetworkInterfaceConfig
            {
                Name = SelectedNetworkInterface.Name,
                EnableStaticIPAddress = SelectedProfile.EnableStaticIPAddress,
                IPAddress             = SelectedProfile.IPAddress,
                Subnetmask            = subnetmask,
                Gateway            = SelectedProfile.Gateway,
                EnableStaticDNS    = enableStaticDNS,
                PrimaryDNSServer   = primaryDNSServer,
                SecondaryDNSServer = secondaryDNSServer
            };

            try
            {
                Models.Network.NetworkInterface networkInterface = new Models.Network.NetworkInterface();

                networkInterface.UserHasCanceled += NetworkInterface_UserHasCanceled;

                await networkInterface.ConfigureNetworkInterfaceAsync(config);

                ReloadNetworkInterfacesAction();
            }
            catch (Exception ex)
            {
                StatusMessage        = ex.Message;
                DisplayStatusMessage = true;
            }
            finally
            {
                await progressDialogController.CloseAsync();
            }
        }