private Task <ProcessResult> FlushNetworkSequence(bool isEth0Changes, bool isWlan0Changes, NICProperties theEth0, NICProperties theWlan0) { return(Task.Run(async() => { await DHCPCD.UpdateResultAsync(new NICProperties[] { theEth0, theWlan0 }); await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "daemon-reload"); await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "stop dhcpcd.service"); if (isEth0Changes) { await ProcessRunner.GetProcessResultAsync(c_IPCommand, "addr flush dev eth0"); } if (isWlan0Changes) { await ProcessRunner.GetProcessResultAsync(c_IPCommand, "addr flush dev wlan0"); } await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "start dhcpcd.service"); await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "restart networking.service"); if (isWlan0Changes) { await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 reconfigure"); } return new ProcessResult(0, string.Empty, string.Empty); })); }
internal NetworkProperties RepopulateAndGetProperties() { if (!Utils.Hardware.isRunningRaspberryPi) { return(this); } Task <ProcessResult>[] Tasks = new Task <ProcessResult> [4]; Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/hostname"); Tasks[1] = ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 get country"); Tasks[2] = GetSSIDs(); Tasks[3] = ProcessRunner.GetProcessResultAsync(c_IFConfigCommand); ReadResult ReadResult = DHCPCD.Read(); var Eth0 = ReadResult.Properties.FirstOrDefault(nic => nic.Id == c_Eth0); Eth0IPAddress = (Eth0 == null || Eth0.IPAddress == null) ? string.Empty : Eth0.IPAddress; Eth0IP6Address = (Eth0 == null || Eth0.IP6Address == null) ? string.Empty : Eth0.IP6Address; Eth0Routers = (Eth0 == null || Eth0.Routers == null) ? new string[0] : Eth0.Routers; Eth0DomainNameServers = (Eth0 == null || Eth0.DomainNameServers == null) ? new string[0] : Eth0.DomainNameServers; var Wlan0 = ReadResult.Properties.FirstOrDefault(nic => nic.Id == c_Wlan0); Wlan0IPAddress = (Wlan0 == null || Wlan0.IPAddress == null) ? string.Empty : Wlan0.IPAddress; Wlan0IP6Address = (Wlan0 == null || Wlan0.IP6Address == null) ? string.Empty : Wlan0.IP6Address; Wlan0Routers = (Wlan0 == null || Wlan0.Routers == null) ? new string[0] : Wlan0.Routers; Wlan0DomainNameServers = (Wlan0 == null || Wlan0.DomainNameServers == null) ? new string[0] : Wlan0.DomainNameServers; ReadResult = null; Task.WaitAll(Tasks); var WiFiCountryResult = Tasks[1].Result.GetOutput().TrimEnd(); WiFiCountrySet = WiFiCountryResult != c_WiFiCountryNotSet; HostName = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd() : string.Empty; WiFiCountry = WiFiCountrySet ? WiFiCountryResult : string.Empty; SSIDs = ProcessSSIDs(Tasks[2]); Interfaces = Tasks[3].Result.Okay() ? IFCONFIG.Parse(Tasks[3].Result.GetOutput()) : new NICInterface[0]; // Log only if errors have occured LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.HostNameSettingsGetError); LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.WiFiCountrySettingGetError); LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.SSIDSettingsGetError); LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.NICInterfacesGetError); return(this); }