private void OnSubnetQueryChanged(SubnetQuery subnetQuery) { _hasResults = true; RaisePropertyChanged("BtnText"); SubnetworkAddresses.Clear(); SubnetHostAddresses.Clear(); SubnetBroadcastAddresses.Clear(); _eventAggregator.GetEvent <SubnetQueryEvent>().Unsubscribe(OnSubnetQueryChanged); CalculateSubnets(subnetQuery); }
private void CalculateSubnets(SubnetQuery subnetQuery) { // Yeah, this needs some refactoring. // TODO: Refactor this int bits = Convert.ToString(subnetQuery.NumberOfSubnets, 2).Length; int interval = GetInterval(bits); IpAddress startIp = subnetQuery.StartingIpAddress.MainIp; IpAddress snAdd = startIp; IpAddress sbAdd = startIp; PrefixLength = $"{subnetQuery.StartingIpAddress.PrefixLength + bits}"; // TASK: GET THE NEW SUBNET MASK. SubnetMask = GetNewSubnetMask(subnetQuery.StartingIpAddress.SubnetMask, bits); for (int i = 0; i < subnetQuery.NumberOfSubnets; i++) { SubnetworkAddresses.Add(snAdd); snAdd.FourthOctet += 1; SubnetHostAddresses.Add($"{snAdd.DisplayName} - "); snAdd.FourthOctet -= 1; snAdd.FourthOctet += interval; } sbAdd.FourthOctet = interval - 1; for (int i = 0; i < subnetQuery.NumberOfSubnets; i++) { SubnetBroadcastAddresses.Add(sbAdd); sbAdd.FourthOctet -= 1; SubnetHostAddresses[i] += $"{sbAdd.DisplayName}"; sbAdd.FourthOctet += 1; sbAdd.FourthOctet += interval; } }
private async void ExecuteNextCommand() { string validateForm = ValidateForm(); if (!string.IsNullOrWhiteSpace(validateForm)) { await _dialogService.DisplayAlertAsync("Form error!", validateForm, "OK"); return; } IpAddress ip = new IpAddress(int.Parse(FirstOctetEntry), int.Parse(SecondOctetEntry), int.Parse(ThirdOctetEntry), int.Parse(FourthOctetEntry)); SubnetQuery subnetQuery = new SubnetQuery { NumberOfSubnets = int.Parse(NumberOfSubnetsEntry), StartingIpAddress = new CompleteIpInfo(ip) }; _eventAggregator.GetEvent <SubnetQueryEvent>().Publish(subnetQuery); await _navigationService.GoBackAsync(); }