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;
        }
示例#2
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;
        }