diff --git a/src/Color/Main.cs b/src/Color/Main.cs index 55a4367..1594f00 100644 --- a/src/Color/Main.cs +++ b/src/Color/Main.cs @@ -1,6 +1,6 @@ namespace Dot.Color; -public sealed class Main : Tool +public sealed class Main : ToolBase { public Main(Option opt) : base(opt) { } diff --git a/src/Color/Option.cs b/src/Color/Option.cs index 8aaf317..f1e3fed 100644 --- a/src/Color/Option.cs +++ b/src/Color/Option.cs @@ -1,4 +1,4 @@ namespace Dot.Color; [Verb("color", HelpText = nameof(Str.ScreenPixelTool), ResourceType = typeof(Str))] -public class Option : IOption { } \ No newline at end of file +public class Option : OptionBase { } \ No newline at end of file diff --git a/src/DirOption.cs b/src/DirOption.cs index 7504ca9..46acf25 100644 --- a/src/DirOption.cs +++ b/src/DirOption.cs @@ -1,6 +1,6 @@ namespace Dot; -public class DirOption : IOption +public class DirOption : OptionBase { [Option('f', "filter", HelpText = nameof(Str.FileSearchPattern), Default = "*.*", ResourceType = typeof(Str))] public string Filter { get; set; } diff --git a/src/Guid/Main.cs b/src/Guid/Main.cs index 8bf6cb3..9c46163 100644 --- a/src/Guid/Main.cs +++ b/src/Guid/Main.cs @@ -2,7 +2,7 @@ using TextCopy; namespace Dot.Guid; -public sealed class Main : Tool +public sealed class Main : ToolBase { public Main(Option opt) : base(opt) { } diff --git a/src/Guid/Option.cs b/src/Guid/Option.cs index ecc826b..c40c4b2 100644 --- a/src/Guid/Option.cs +++ b/src/Guid/Option.cs @@ -1,7 +1,7 @@ namespace Dot.Guid; [Verb("guid", HelpText = nameof(Str.GuidTool), ResourceType = typeof(Str))] -public class Option : IOption +public class Option : OptionBase { [Option('u', "upper", HelpText = nameof(Str.UseUppercase), Default = false, ResourceType = typeof(Str))] public bool Upper { get; set; } //normal options here diff --git a/src/IP/Main.cs b/src/IP/Main.cs index f772d53..5c934ef 100644 --- a/src/IP/Main.cs +++ b/src/IP/Main.cs @@ -3,7 +3,7 @@ using System.Net.Sockets; namespace Dot.IP; -public sealed class Main : Tool +public sealed class Main : ToolBase { public Main(Option opt) : base(opt) { } diff --git a/src/IP/Option.cs b/src/IP/Option.cs index d3ef77a..5ed2605 100644 --- a/src/IP/Option.cs +++ b/src/IP/Option.cs @@ -1,4 +1,4 @@ namespace Dot.IP; [Verb("ip", HelpText = nameof(Str.Ip), ResourceType = typeof(Str))] -public class Option : IOption { } \ No newline at end of file +public class Option : OptionBase { } \ No newline at end of file diff --git a/src/Lang/Str.Designer.cs b/src/Lang/Str.Designer.cs index aaf4f04..353b6e2 100644 --- a/src/Lang/Str.Designer.cs +++ b/src/Lang/Str.Designer.cs @@ -131,6 +131,15 @@ namespace Dot.Lang { } } + /// + /// Looks up a localized string similar to 执行命令后保留会话. + /// + public static string KeepSession { + get { + return ResourceManager.GetString("KeepSession", resourceCulture); + } + } + /// /// Looks up a localized string similar to Local clock offset. /// @@ -194,6 +203,15 @@ namespace Dot.Lang { } } + /// + /// Looks up a localized string similar to NTP 服务器标准时钟: {0}. + /// + public static string NtpServerTime { + get { + return ResourceManager.GetString("NtpServerTime", resourceCulture); + } + } + /// /// Looks up a localized string similar to 指定的路径“{0}”不存在. /// diff --git a/src/Lang/Str.en-US.resx b/src/Lang/Str.en-US.resx index 25c0ec5..564b9db 100644 --- a/src/Lang/Str.en-US.resx +++ b/src/Lang/Str.en-US.resx @@ -131,4 +131,10 @@ IP tools + + Keep the session after executing the command + + + NTP server standard clock: {0} + \ No newline at end of file diff --git a/src/Lang/Str.resx b/src/Lang/Str.resx index 8d28ed4..b91ca60 100644 --- a/src/Lang/Str.resx +++ b/src/Lang/Str.resx @@ -60,6 +60,9 @@ 文件通配符 + + 执行命令后保留会话 + 连接NTP服务器超时时间 (毫秒) @@ -121,6 +124,9 @@ {0}, 本机时钟偏移: {1} ms + + NTP 服务器标准时钟: {0} + 本机时间已同步 diff --git a/src/Option.cs b/src/Option.cs new file mode 100644 index 0000000..5bac861 --- /dev/null +++ b/src/Option.cs @@ -0,0 +1,7 @@ +namespace Dot; + +public abstract class OptionBase : IOption +{ + [Option('k', "keep-session", HelpText = nameof(Str.KeepSession), Default = false, ResourceType = typeof(Str))] + public virtual bool KeepSession { get; set; } +} \ No newline at end of file diff --git a/src/Program.cs b/src/Program.cs index 19e2623..5e5ac7f 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -12,8 +12,14 @@ Type[] LoadVerbs() async Task Run(object args) { - var tool = ToolsFactory.Create(args as IOption); + var option = args as OptionBase; + var tool = ToolsFactory.Create(option); await tool.Run(); + if (option!.KeepSession) { + Console.WriteLine(); + Console.WriteLine(Str.PressAnyKey); + Console.ReadKey(); + } } diff --git a/src/Pwd/Main.cs b/src/Pwd/Main.cs index 03d138c..d73869f 100644 --- a/src/Pwd/Main.cs +++ b/src/Pwd/Main.cs @@ -3,7 +3,7 @@ using TextCopy; namespace Dot.Pwd; -public sealed class Main : Tool +public sealed class Main : ToolBase { private readonly char[][] _charTable = { "0123456789".ToCharArray() // diff --git a/src/Pwd/Option.cs b/src/Pwd/Option.cs index 7e205e5..cb2a9a5 100644 --- a/src/Pwd/Option.cs +++ b/src/Pwd/Option.cs @@ -1,7 +1,7 @@ namespace Dot.Pwd; [Verb("pwd", HelpText = nameof(Str.RandomPasswordGenerator), ResourceType = typeof(Str))] -public class Option : IOption +public class Option : OptionBase { [Flags] public enum GenerateTypes diff --git a/src/RmBlank/Main.cs b/src/RmBlank/Main.cs index 2ec8dd9..f2e7be4 100644 --- a/src/RmBlank/Main.cs +++ b/src/RmBlank/Main.cs @@ -3,7 +3,7 @@ using NSExt.Extensions; namespace Dot.RmBlank; -public sealed class Main : Tool, IDisposable +public sealed class Main : ToolBase, IDisposable { private int _breakCnt; private bool _disposed; diff --git a/src/RmBom/Main.cs b/src/RmBom/Main.cs index 155867e..28f6961 100644 --- a/src/RmBom/Main.cs +++ b/src/RmBom/Main.cs @@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis; namespace Dot.RmBom; -public sealed class Main : Tool, IDisposable +public sealed class Main : ToolBase, IDisposable { private int _breakCnt; private bool _disposed; diff --git a/src/Text/Main.cs b/src/Text/Main.cs index 776226c..ec56fbe 100644 --- a/src/Text/Main.cs +++ b/src/Text/Main.cs @@ -5,7 +5,7 @@ using TextCopy; namespace Dot.Text; -public sealed class Main : Tool +public sealed class Main : ToolBase { private ref struct Output { @@ -108,7 +108,5 @@ html-decode: {o.HtmlDecode} ParseAndShow(Opt.Text); - Console.Write(Str.PressAnyKey); - Console.ReadKey(); } } \ No newline at end of file diff --git a/src/Text/Option.cs b/src/Text/Option.cs index 90528c6..8f2197b 100644 --- a/src/Text/Option.cs +++ b/src/Text/Option.cs @@ -1,7 +1,7 @@ namespace Dot.Text; [Verb("text", HelpText = nameof(Str.TextTool), ResourceType = typeof(Str))] -public class Option : IOption +public class Option : OptionBase { [Value(0, HelpText = nameof(Str.TextTobeProcessed), ResourceType = typeof(Str))] public string Text { get; set; } diff --git a/src/Time/Main.cs b/src/Time/Main.cs index 85a72af..c54dbf2 100644 --- a/src/Time/Main.cs +++ b/src/Time/Main.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; namespace Dot.Time; -public sealed class Main : Tool +public sealed class Main : ToolBase { private record Server { @@ -217,16 +217,20 @@ public sealed class Main : Tool Console.WriteLine(Str.NtpReceiveDone, _successCnt, _serverCnt, avgOffset.TotalMilliseconds); if (!Opt.Sync) { + if (!Opt.KeepSession) return; + + var waitObj = new ManualResetEvent(false); var _ = Task.Run(async () => { + var top = Console.GetCursorPosition().Top; while (true) { + Console.SetCursorPosition(0, top); + Console.Write(Str.NtpServerTime, (DateTime.Now - avgOffset).ToString("O")); + waitObj.Set(); await Task.Delay(100); - Console.SetCursorPosition(0, Console.GetCursorPosition().Top); - Console.Write(Str.ServerTime, (DateTime.Now - avgOffset).ToString("O")); - Console.Write(@", {0}", Str.PressAnyKey); } // ReSharper disable once FunctionNeverReturns }); - Console.ReadKey(); + waitObj.WaitOne(); return; } diff --git a/src/Time/Option.cs b/src/Time/Option.cs index 401bb0b..5b0d585 100644 --- a/src/Time/Option.cs +++ b/src/Time/Option.cs @@ -1,7 +1,7 @@ namespace Dot.Time; [Verb("time", HelpText = nameof(Str.TimeTool), ResourceType = typeof(Str))] -public class Option : IOption +public class Option : OptionBase { [Option('s', "sync", HelpText = nameof(Str.SyncToLocalTime), Default = false, ResourceType = typeof(Str))] public bool Sync { get; set; } diff --git a/src/ToLf/Main.cs b/src/ToLf/Main.cs index 00afacd..e05ef03 100644 --- a/src/ToLf/Main.cs +++ b/src/ToLf/Main.cs @@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis; namespace Dot.ToLf; -public sealed class Main : Tool, IDisposable +public sealed class Main : ToolBase, IDisposable { private int _breakCnt; private bool _disposed; diff --git a/src/Tool.cs b/src/ToolBase.cs similarity index 95% rename from src/Tool.cs rename to src/ToolBase.cs index 05496f4..54511f0 100644 --- a/src/Tool.cs +++ b/src/ToolBase.cs @@ -1,6 +1,6 @@ namespace Dot; -public abstract class Tool : ITool +public abstract class ToolBase : ITool where TOption : OptionBase { protected readonly ProgressBarOptions // DefaultProgressBarOptions = new() { @@ -15,7 +15,7 @@ public abstract class Tool : ITool protected TOption Opt { get; } - protected Tool(TOption opt) + protected ToolBase(TOption opt) { Opt = opt; }