diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/ProcessUtils.cs b/WelsonJS.Toolkit/WelsonJS.Toolkit/ProcessUtils.cs index fdf813f..d3fbe7b 100644 --- a/WelsonJS.Toolkit/WelsonJS.Toolkit/ProcessUtils.cs +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/ProcessUtils.cs @@ -27,7 +27,7 @@ namespace WelsonJS { public class ProcessUtils { - public static List ProcessIDs = new List(); + public static List ProcessList = new List(); public static string OpenFileDialog() { @@ -48,12 +48,14 @@ namespace WelsonJS public static int Open(string filepath) { + int processId = -1; + if (string.IsNullOrEmpty(filepath)) { filepath = OpenFileDialog(); if (string.IsNullOrEmpty(filepath)) { - return -1; + return processId; } } @@ -62,16 +64,13 @@ namespace WelsonJS Process process = new Process(); process.StartInfo.FileName = filepath; process.Start(); - - int processId = process.Id; - ProcessIDs.Add(processId); - - return processId; + ProcessList.Add(process); } - catch - { - return -1; + catch { + processId = -1; } + + return processId; } public static bool Close(int processId) @@ -79,12 +78,13 @@ namespace WelsonJS try { Process.GetProcessById(processId).CloseMainWindow(); - return true; } catch { return false; } + + return true; } } } diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/Serialization/KVSerializer.cs b/WelsonJS.Toolkit/WelsonJS.Toolkit/Serialization/KVSerializer.cs new file mode 100644 index 0000000..5107f3c --- /dev/null +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/Serialization/KVSerializer.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Text; + +namespace WelsonJS.Serialization +{ + public class KVSerializer + { + private static Dictionary dict = new Dictionary(); + + public void Add(string key, string value) + { + dict[key] = value; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + + foreach (var x in dict) + { + sb.Append($"{x.Key}={x.Value}; "); + } + if (sb.Length > 0) sb.Length -= 2; + + return sb.ToString(); + } + } +} diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs b/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs index 51b016b..7cea066 100644 --- a/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/Toolkit.cs @@ -34,6 +34,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; using WelsonJS.Cryptography; +using WelsonJS.Serialization; namespace WelsonJS { @@ -247,21 +248,25 @@ namespace WelsonJS public string GetImageSize(string srcfile) { int[] result = BitmapUtils.GetSize(srcfile); - int width = result[0]; - int height = result[1]; - return $"width={width}; height={height}"; + var serializer = new KVSerializer(); + serializer.Add("width", result[0].ToString()); + serializer.Add("height", result[1].ToString()); + + return serializer.ToString(); } [ComVisible(true)] public string GetImagePixel(string srcfile) { int[] result = BitmapUtils.GetSize(srcfile); - int red = result[0]; - int green = result[1]; - int blue = result[2]; - return $"red={red}; green={green}; blue={blue}"; + var serializer = new KVSerializer(); + serializer.Add("red", result[0].ToString()); + serializer.Add("green", result[1].ToString()); + serializer.Add("blue", result[2].ToString()); + + return serializer.ToString(); } [ComVisible(true)] @@ -275,7 +280,5 @@ namespace WelsonJS { BitmapUtils.Crop(srcfile, dstfile, x, y, a, b); } - - } }