diff --git a/App.config b/App.config index de27714..76452db 100755 --- a/App.config +++ b/App.config @@ -1,6 +1,14 @@ - + - + + + + + + + + + diff --git a/DaemonCommander/DaemonCommander.cs b/DaemonCommander/DaemonCommander.cs index 09a312f..1718487 100755 --- a/DaemonCommander/DaemonCommander.cs +++ b/DaemonCommander/DaemonCommander.cs @@ -2,8 +2,9 @@ using System.Text; using System.Net; using System.Net.Sockets; -using Newtonsoft.Json; using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; namespace tray_windows.Daemon { @@ -96,7 +97,9 @@ private string SendCommand(string command) daemonSocket.Send(msg); daemonSocket.Receive(resp); daemonSocket.Close(); - return Encoding.ASCII.GetString(resp); + + var result = Encoding.ASCII.GetString(resp); + return result.Replace("\0", string.Empty); } catch (SocketException e) { @@ -110,15 +113,18 @@ private string SendCommand(ConfigSetCommand command) { var resp = new byte[2048]; daemonSocket.Connect(daemonSocketEp); - var cmd = JsonConvert.SerializeObject(command, new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + + JsonSerializerOptions options = new JsonSerializerOptions(); + options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + var cmd = JsonSerializer.Serialize(command, options); + byte[] msg = Encoding.ASCII.GetBytes(cmd); daemonSocket.Send(msg); daemonSocket.Receive(resp); daemonSocket.Close(); - return Encoding.ASCII.GetString(resp); + + var result = Encoding.ASCII.GetString(resp); + return result.Replace("\0", string.Empty); } catch (SocketException e) { @@ -132,15 +138,18 @@ private string SendCommand(ConfigUnsetCommand command) { var resp = new byte[2048]; daemonSocket.Connect(daemonSocketEp); - var cmd = JsonConvert.SerializeObject(command, new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + + JsonSerializerOptions options = new JsonSerializerOptions(); + options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + var cmd = JsonSerializer.Serialize(command, options); + byte[] msg = Encoding.ASCII.GetBytes(cmd); daemonSocket.Send(msg); daemonSocket.Receive(resp); daemonSocket.Close(); - return Encoding.ASCII.GetString(resp); + + var result = Encoding.ASCII.GetString(resp); + return result.Replace("\0", string.Empty); } catch (SocketException e) { diff --git a/DaemonCommander/Handlers.cs b/DaemonCommander/Handlers.cs index 72c78c4..04f452d 100755 --- a/DaemonCommander/Handlers.cs +++ b/DaemonCommander/Handlers.cs @@ -1,6 +1,6 @@ -using Newtonsoft.Json; -using System.Collections.Generic; +using System.Collections.Generic; using System.Net.Sockets; +using System.Text.Json; using tray_windows.Daemon; namespace tray_windows @@ -9,12 +9,11 @@ class Handlers { public static StartResult HandleStart() { - var d = new Daemon.DaemonCommander(); + var daemon = new DaemonCommander(); try { - var r = d.Start(); - StartResult sr = JsonConvert.DeserializeObject(r); - return sr; + var result = daemon.Start(); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { @@ -30,13 +29,12 @@ public static StartResult HandleStart() public static StopResult HandleStop() { - var d = new Daemon.DaemonCommander(); + var daemon = new DaemonCommander(); try { - var r = d.Stop(); - StopResult sr = JsonConvert.DeserializeObject(r); - return sr; + var result = daemon.Stop(); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { @@ -47,12 +45,11 @@ public static StopResult HandleStop() public static DeleteResult HandleDelete() { - var d = new Daemon.DaemonCommander(); + var daemon = new DaemonCommander(); try { - var r = d.Delete(); - DeleteResult dr = JsonConvert.DeserializeObject(r); - return dr; + var result = daemon.Delete(); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { @@ -63,12 +60,11 @@ public static DeleteResult HandleDelete() public static StatusResult HandleStatus() { - var d = new Daemon.DaemonCommander(); + var daemon = new DaemonCommander(); try { - var r = d.GetStatus(); - StatusResult sr = JsonConvert.DeserializeObject(r); - return sr; + var result = daemon.GetStatus(); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { @@ -79,12 +75,11 @@ public static StatusResult HandleStatus() public static ConsoleResult HandleOpenWebConsole() { - var d = new Daemon.DaemonCommander(); + var daemon = new DaemonCommander(); try { - var r = d.GetWebconsoleURL(); - ConsoleResult cr = JsonConvert.DeserializeObject(r); - return cr; + var result = daemon.GetWebconsoleURL(); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { @@ -95,24 +90,21 @@ public static ConsoleResult HandleOpenWebConsole() public static ConfigResult GetConfig() { - ConfigResult cr = new ConfigResult(); - var d = new Daemon.DaemonCommander(); + var daemon = new DaemonCommander(); try { - var r = d.GetAllConfig(); - cr = JsonConvert.DeserializeObject(r); - return cr; + var result = daemon.GetAllConfig(); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { DisplayMessageBox.Error(ex.Message); - return cr; + return new ConfigResult(); // returning an empty result? } } public static SetUnsetConfig SetConfig(Dictionary cfg) { - var result = new SetUnsetConfig(); var config = new ConfigSetCommand(); var configArgs = new ConfigSetCommandArg(); configArgs.properties = cfg; @@ -120,23 +112,21 @@ public static SetUnsetConfig SetConfig(Dictionary cfg) config.command = "setconfig"; config.args = configArgs; - var d = new Daemon.DaemonCommander(); + var daemon = new DaemonCommander(); try { - var r = d.SetConfig(config); - result = JsonConvert.DeserializeObject(r); - return result; + var result = daemon.SetConfig(config); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { DisplayMessageBox.Error(ex.Message); - return result; + return new SetUnsetConfig(); // returning an empty result? } } public static SetUnsetConfig UnsetConfig(List cfg) { - var result = new SetUnsetConfig(); var config = new ConfigUnsetCommand(); var configArgs = new ConfigUnsetCommandArg(); configArgs.properties = cfg; @@ -144,17 +134,16 @@ public static SetUnsetConfig UnsetConfig(List cfg) config.command = "unsetconfig"; config.args = configArgs; - var d = new Daemon.DaemonCommander(); + var daemon = new Daemon.DaemonCommander(); try { - var r = d.UnsetConfig(config); - result = JsonConvert.DeserializeObject(r); - return result; + var result = daemon.UnsetConfig(config); + return JsonSerializer.Deserialize(result); } catch (SocketException ex) { DisplayMessageBox.Error(ex.Message); - return result; + return new SetUnsetConfig(); // returning an empty result? } } diff --git a/DaemonCommander/ResponseClasses.cs b/DaemonCommander/ResponseClasses.cs index 9ec612d..163280f 100755 --- a/DaemonCommander/ResponseClasses.cs +++ b/DaemonCommander/ResponseClasses.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace tray_windows { @@ -77,67 +77,67 @@ struct Config public string nameserver; public int memory; - [JsonProperty("disable-update-check")] + [JsonPropertyName("disable-update-check")] public bool DisableUpdateCheck { get; set; } - [JsonProperty("disk-size")] + [JsonPropertyName("disk-size")] public int DiskSize {get; set;} - [JsonProperty("enable-experimental-features")] + [JsonPropertyName("enable-experimental-features")] public bool EnableExperimentalFeatures { get; set; } - [JsonProperty("http-proxy")] + [JsonPropertyName("http-proxy")] public string HttpProxy { get; set; } - [JsonProperty("https-proxy")] + [JsonPropertyName("https-proxy")] public string HttpsProxy { get; set; } - [JsonProperty("no-proxy")] + [JsonPropertyName("no-proxy")] public string NoProxy { get; set; } - [JsonProperty("proxy-ca-file")] + [JsonPropertyName("proxy-ca-file")] public string ProxyCAFile { get; set; } - [JsonProperty("pull-secret-file")] + [JsonPropertyName("pull-secret-file")] public string PullSecretFile { get; set; } - [JsonProperty("network-mode")] + [JsonPropertyName("network-mode")] public string NetworkMode { get; set; } - [JsonProperty("skip-check-admin-helper-cached")] + [JsonPropertyName("skip-check-admin-helper-cached")] public bool SkipCheckAdminHelperCached { get; set; } - [JsonProperty("skip-check-administrator-user")] + [JsonPropertyName("skip-check-administrator-user")] public bool SkipCheckAdminUser { get; set; } - [JsonProperty("skip-check-bundle-extracted")] + [JsonPropertyName("skip-check-bundle-extracted")] public bool SkipCheckBundleExtracted { get; set; } - [JsonProperty("skip-check-hyperv-installed")] + [JsonPropertyName("skip-check-hyperv-installed")] public bool SkipCheckHypervInstalled { get; set; } - [JsonProperty("skip-check-hyperv-service-running")] + [JsonPropertyName("skip-check-hyperv-service-running")] public bool SkipCheckHypervServiceRunning; - [JsonProperty("skip-check-hyperv-switch")] + [JsonPropertyName("skip-check-hyperv-switch")] public bool SkipCheckHypervSwitch { get; set; } - [JsonProperty("skip-check-podman-cached")] + [JsonPropertyName("skip-check-podman-cached")] public bool SkipCheckPodmanCached { get; set; } - [JsonProperty("skip-check-ram")] + [JsonPropertyName("skip-check-ram")] public bool SkipCheckRam { get; set; } - [JsonProperty("skip-check-user-in-hyperv-group")] + [JsonPropertyName("skip-check-user-in-hyperv-group")] public bool SkipCheckUserInHypervGroup { get; set; } - [JsonProperty("skip-check-vscok")] + [JsonPropertyName("skip-check-vscok")] public bool SkipCheckVsock { get; set; } - [JsonProperty("skip-check-windows-edition")] + [JsonPropertyName("skip-check-windows-edition")] public bool SkipCheckWindowsEdition { get; set; } - [JsonProperty("skip-check-windows-version")] + [JsonPropertyName("skip-check-windows-version")] public bool SkipCheckWindowsVersion { get; set; } } diff --git a/Forms/AboutForm.cs b/Forms/AboutForm.cs index 3922c0b..e4224ff 100755 --- a/Forms/AboutForm.cs +++ b/Forms/AboutForm.cs @@ -1,7 +1,7 @@ using System; using System.Drawing; +using System.Text.Json; using System.Windows.Forms; -using Newtonsoft.Json; namespace tray_windows { @@ -26,11 +26,11 @@ private void AboutForm_Load(object sender, EventArgs e) private void GetVersion(object sender, EventArgs e) { - var d = new Daemon.DaemonCommander(); + var daemon = new Daemon.DaemonCommander(); try { - var r = d.GetVersion(); - version = JsonConvert.DeserializeObject(r); + var result = daemon.GetVersion(); + version = JsonSerializer.Deserialize(result); if (version.Success) { CrcVersionLabel.Text = String.Format("{0}+{1}", version.CrcVersion, version.CommitSha); OcpVersion.Text = version.OpenshiftVersion; diff --git a/Forms/CrcSettingsForm.cs b/Forms/CrcSettingsForm.cs index a37c295..9e8d332 100755 --- a/Forms/CrcSettingsForm.cs +++ b/Forms/CrcSettingsForm.cs @@ -28,7 +28,6 @@ private void CrcSettingsForm_Load(object sender, EventArgs e) this.FormClosing += CrcSettingsForm_FormClosing; this.tabControl1.SelectedIndexChanged += TabControl1_SelectedIndexChanged; - currentConfig = Handlers.GetConfig(); LoadConfigs(currentConfig); } diff --git a/packages.config b/packages.config index 1a00a65..9a59901 100755 --- a/packages.config +++ b/packages.config @@ -1,9 +1,17 @@  + - + + + + + + + + \ No newline at end of file diff --git a/tray-windows.csproj b/tray-windows.csproj index 7eb791c..751fc6c 100755 --- a/tray-windows.csproj +++ b/tray-windows.csproj @@ -75,12 +75,37 @@ false - - packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Text.Encodings.Web.5.0.0\lib\net461\System.Text.Encodings.Web.dll + + + packages\System.Text.Json.5.0.1\lib\net461\System.Text.Json.dll + + + packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll +