/// <summary> /// Saves the current IP Configuration /// </summary> public async void SaveIPInformation() { EnableControl = false; StatusBarText = "Saving IP Configuration"; IPConfigurationList ipInfoList = new IPConfigurationList(); if (!string.IsNullOrWhiteSpace(IPConfigurationItem.IPConfigurationName)) { var item = IPConfigurationList.FirstOrDefault(x => x.IPConfigurationName == IPConfigurationItem.IPConfigurationName); if (item == null) { IPConfigurationList.Add(IPConfigurationItem); } foreach (var ipInfo in IPConfigurationList) { ipInfoList.IPConfList.Add(ipInfo); } await Tools.SaveIPInformationListAsync(ipInfoList); GetIPInformationList(); IPConfigurationItem = new IPConfiguration(); StatusBarText = "IP Configuration Saved"; } else { await _dialogMessageService.ShowAsync("Error", "You must enter a valid IP Configuration name"); } EnableControl = true; }
/// <summary> /// Gets the entries on the XML file containing the IP Configuration information /// </summary> public async void GetIPInformationList() { StatusBarText = "Getting saved IP Configurations"; IPConfigurationList.Clear(); var ipListFromFile = await Tools.GetIPInformationListAsync(); ipListFromFile.IPConfList.ForEach(ip => IPConfigurationList.Add(ip)); RaisePropertyChanged(IPConfigurationListPropertyName); GetConnectedNetworkInterfaces(); StatusBarText = "Ready"; }
/// <summary> /// Saves the IP Configuration instance /// </summary> /// <param name="ipInformationEntry">IP Configuration instance to save</param> /// <returns>Integer indicating wether the operation was successful</returns> public async Task<int> SaveIPInformationEntryAsync(IPConfiguration ipInformationEntry) { int result = 0; try { IPConfigurationList infoList = new IPConfigurationList(); infoList.IPConfList.Add(ipInformationEntry); await Tools.SaveIPInformationListAsync(infoList); } catch (Exception) { result = -1; } return result; }
public static async Task SaveIPInformationListAsync(IPConfigurationList infoList) { await Task.Factory.StartNew(() => { foreach (var info in infoList.IPConfList) { info.IPConfigurationName = info.IPConfigurationName.Trim(); info.IPAddress = string.IsNullOrWhiteSpace(info.IPAddress) ? null : info.IPAddress.Trim(); info.SubnetMask = string.IsNullOrWhiteSpace(info.SubnetMask) ? null : info.SubnetMask.Trim(); info.Gateway = string.IsNullOrWhiteSpace(info.Gateway) ? null : info.Gateway.Trim(); info.PreferredDNS = string.IsNullOrWhiteSpace(info.PreferredDNS) ? null : info.PreferredDNS.Trim(); info.SecondaryDNS = string.IsNullOrWhiteSpace(info.SecondaryDNS) ? null : info.SecondaryDNS.Trim(); } ; SerializeObject <IPConfigurationList>(infoList, IPCONFFILENAME); }); }
public void TestSaveIPConfigurationXML() { IPConfigurationList ipList = new IPConfigurationList(); ipList.IPConfList.Add(new IPConfiguration { IPConfigurationName = "SAT", IPAddress = "99.90.32.213", Gateway = "99.90.32.1", SubnetMask = "255.255.252.0", PreferredDNS = "99.90.4.210", SecondaryDNS = "10.4.5.5", IsDHCP = false }); ipList.IPConfList.Add(new IPConfiguration { IPConfigurationName = "Home", IPAddress = "10.0.0.1", Gateway = "10.0.0.254", SubnetMask = "255.255.255.0", PreferredDNS = "208.67.222.222", SecondaryDNS = "208.67.220.220", IsDHCP = false }); ipList.IPConfList.Add(new IPConfiguration { IPConfigurationName = "DHCP", IPAddress = "", Gateway = "", SubnetMask = "", PreferredDNS = "", SecondaryDNS = "", IsDHCP = true }); Tools.SaveIPInformationListAsync(ipList).Wait(); Assert.IsTrue(File.Exists(Tools.IPCONFFILENAME)); }