mirror of
https://github.com/nsnail/dot.git
synced 2025-06-17 21:13:21 +08:00
<refactor>
This commit is contained in:
parent
7a0efaf015
commit
3cb3b13f98
@ -1,6 +1,6 @@
|
|||||||
namespace Dot.Color;
|
namespace Dot.Color;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<Option>
|
||||||
|
|
||||||
{
|
{
|
||||||
public Main(Option opt) : base(opt) { }
|
public Main(Option opt) : base(opt) { }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace Dot.Color;
|
namespace Dot.Color;
|
||||||
|
|
||||||
[Verb("color", HelpText = nameof(Str.ScreenPixelTool), ResourceType = typeof(Str))]
|
[Verb("color", HelpText = nameof(Str.ScreenPixelTool), ResourceType = typeof(Str))]
|
||||||
public class Option : IOption { }
|
public class Option : OptionBase { }
|
@ -1,6 +1,6 @@
|
|||||||
namespace Dot;
|
namespace Dot;
|
||||||
|
|
||||||
public class DirOption : IOption
|
public class DirOption : OptionBase
|
||||||
{
|
{
|
||||||
[Option('f', "filter", HelpText = nameof(Str.FileSearchPattern), Default = "*.*", ResourceType = typeof(Str))]
|
[Option('f', "filter", HelpText = nameof(Str.FileSearchPattern), Default = "*.*", ResourceType = typeof(Str))]
|
||||||
public string Filter { get; set; }
|
public string Filter { get; set; }
|
||||||
|
@ -2,7 +2,7 @@ using TextCopy;
|
|||||||
|
|
||||||
namespace Dot.Guid;
|
namespace Dot.Guid;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<Option>
|
||||||
{
|
{
|
||||||
public Main(Option opt) : base(opt) { }
|
public Main(Option opt) : base(opt) { }
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
namespace Dot.Guid;
|
namespace Dot.Guid;
|
||||||
|
|
||||||
[Verb("guid", HelpText = nameof(Str.GuidTool), ResourceType = typeof(Str))]
|
[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))]
|
[Option('u', "upper", HelpText = nameof(Str.UseUppercase), Default = false, ResourceType = typeof(Str))]
|
||||||
public bool Upper { get; set; } //normal options here
|
public bool Upper { get; set; } //normal options here
|
||||||
|
@ -3,7 +3,7 @@ using System.Net.Sockets;
|
|||||||
|
|
||||||
namespace Dot.IP;
|
namespace Dot.IP;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<Option>
|
||||||
|
|
||||||
{
|
{
|
||||||
public Main(Option opt) : base(opt) { }
|
public Main(Option opt) : base(opt) { }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace Dot.IP;
|
namespace Dot.IP;
|
||||||
|
|
||||||
[Verb("ip", HelpText = nameof(Str.Ip), ResourceType = typeof(Str))]
|
[Verb("ip", HelpText = nameof(Str.Ip), ResourceType = typeof(Str))]
|
||||||
public class Option : IOption { }
|
public class Option : OptionBase { }
|
18
src/Lang/Str.Designer.cs
generated
18
src/Lang/Str.Designer.cs
generated
@ -131,6 +131,15 @@ namespace Dot.Lang {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to 执行命令后保留会话.
|
||||||
|
/// </summary>
|
||||||
|
public static string KeepSession {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("KeepSession", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Local clock offset.
|
/// Looks up a localized string similar to Local clock offset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -194,6 +203,15 @@ namespace Dot.Lang {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to NTP 服务器标准时钟: {0}.
|
||||||
|
/// </summary>
|
||||||
|
public static string NtpServerTime {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("NtpServerTime", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to 指定的路径“{0}”不存在.
|
/// Looks up a localized string similar to 指定的路径“{0}”不存在.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -131,4 +131,10 @@
|
|||||||
<data name="Ip" xml:space="preserve">
|
<data name="Ip" xml:space="preserve">
|
||||||
<value>IP tools</value>
|
<value>IP tools</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="KeepSession" xml:space="preserve">
|
||||||
|
<value>Keep the session after executing the command</value>
|
||||||
|
</data>
|
||||||
|
<data name="NtpServerTime" xml:space="preserve">
|
||||||
|
<value>NTP server standard clock: {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -60,6 +60,9 @@
|
|||||||
<data name="FileSearchPattern" xml:space="preserve">
|
<data name="FileSearchPattern" xml:space="preserve">
|
||||||
<value>文件通配符</value>
|
<value>文件通配符</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="KeepSession" xml:space="preserve">
|
||||||
|
<value>执行命令后保留会话</value>
|
||||||
|
</data>
|
||||||
<data name="TimeoutMillSecs" xml:space="preserve">
|
<data name="TimeoutMillSecs" xml:space="preserve">
|
||||||
<value>连接NTP服务器超时时间 (毫秒)</value>
|
<value>连接NTP服务器超时时间 (毫秒)</value>
|
||||||
</data>
|
</data>
|
||||||
@ -121,6 +124,9 @@
|
|||||||
<data name="LocalTimeOffset" xml:space="preserve">
|
<data name="LocalTimeOffset" xml:space="preserve">
|
||||||
<value>{0}, 本机时钟偏移: {1} ms</value>
|
<value>{0}, 本机时钟偏移: {1} ms</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NtpServerTime" xml:space="preserve">
|
||||||
|
<value>NTP 服务器标准时钟: {0}</value>
|
||||||
|
</data>
|
||||||
<data name="LocalTimeSyncDone" xml:space="preserve">
|
<data name="LocalTimeSyncDone" xml:space="preserve">
|
||||||
<value>本机时间已同步</value>
|
<value>本机时间已同步</value>
|
||||||
</data>
|
</data>
|
||||||
|
7
src/Option.cs
Normal file
7
src/Option.cs
Normal file
@ -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; }
|
||||||
|
}
|
@ -12,8 +12,14 @@ Type[] LoadVerbs()
|
|||||||
|
|
||||||
async Task Run(object args)
|
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();
|
await tool.Run();
|
||||||
|
if (option!.KeepSession) {
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine(Str.PressAnyKey);
|
||||||
|
Console.ReadKey();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ using TextCopy;
|
|||||||
|
|
||||||
namespace Dot.Pwd;
|
namespace Dot.Pwd;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<Option>
|
||||||
{
|
{
|
||||||
private readonly char[][] _charTable = {
|
private readonly char[][] _charTable = {
|
||||||
"0123456789".ToCharArray() //
|
"0123456789".ToCharArray() //
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
namespace Dot.Pwd;
|
namespace Dot.Pwd;
|
||||||
|
|
||||||
[Verb("pwd", HelpText = nameof(Str.RandomPasswordGenerator), ResourceType = typeof(Str))]
|
[Verb("pwd", HelpText = nameof(Str.RandomPasswordGenerator), ResourceType = typeof(Str))]
|
||||||
public class Option : IOption
|
public class Option : OptionBase
|
||||||
{
|
{
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum GenerateTypes
|
public enum GenerateTypes
|
||||||
|
@ -3,7 +3,7 @@ using NSExt.Extensions;
|
|||||||
|
|
||||||
namespace Dot.RmBlank;
|
namespace Dot.RmBlank;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>, IDisposable
|
public sealed class Main : ToolBase<Option>, IDisposable
|
||||||
{
|
{
|
||||||
private int _breakCnt;
|
private int _breakCnt;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
|
|
||||||
namespace Dot.RmBom;
|
namespace Dot.RmBom;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>, IDisposable
|
public sealed class Main : ToolBase<Option>, IDisposable
|
||||||
{
|
{
|
||||||
private int _breakCnt;
|
private int _breakCnt;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
@ -5,7 +5,7 @@ using TextCopy;
|
|||||||
|
|
||||||
namespace Dot.Text;
|
namespace Dot.Text;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<Option>
|
||||||
{
|
{
|
||||||
private ref struct Output
|
private ref struct Output
|
||||||
{
|
{
|
||||||
@ -108,7 +108,5 @@ html-decode: {o.HtmlDecode}
|
|||||||
|
|
||||||
|
|
||||||
ParseAndShow(Opt.Text);
|
ParseAndShow(Opt.Text);
|
||||||
Console.Write(Str.PressAnyKey);
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
namespace Dot.Text;
|
namespace Dot.Text;
|
||||||
|
|
||||||
[Verb("text", HelpText = nameof(Str.TextTool), ResourceType = typeof(Str))]
|
[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))]
|
[Value(0, HelpText = nameof(Str.TextTobeProcessed), ResourceType = typeof(Str))]
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace Dot.Time;
|
namespace Dot.Time;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>
|
public sealed class Main : ToolBase<Option>
|
||||||
{
|
{
|
||||||
private record Server
|
private record Server
|
||||||
{
|
{
|
||||||
@ -217,16 +217,20 @@ public sealed class Main : Tool<Option>
|
|||||||
Console.WriteLine(Str.NtpReceiveDone, _successCnt, _serverCnt, avgOffset.TotalMilliseconds);
|
Console.WriteLine(Str.NtpReceiveDone, _successCnt, _serverCnt, avgOffset.TotalMilliseconds);
|
||||||
|
|
||||||
if (!Opt.Sync) {
|
if (!Opt.Sync) {
|
||||||
|
if (!Opt.KeepSession) return;
|
||||||
|
|
||||||
|
var waitObj = new ManualResetEvent(false);
|
||||||
var _ = Task.Run(async () => {
|
var _ = Task.Run(async () => {
|
||||||
|
var top = Console.GetCursorPosition().Top;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Console.SetCursorPosition(0, top);
|
||||||
|
Console.Write(Str.NtpServerTime, (DateTime.Now - avgOffset).ToString("O"));
|
||||||
|
waitObj.Set();
|
||||||
await Task.Delay(100);
|
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
|
// ReSharper disable once FunctionNeverReturns
|
||||||
});
|
});
|
||||||
Console.ReadKey();
|
waitObj.WaitOne();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
namespace Dot.Time;
|
namespace Dot.Time;
|
||||||
|
|
||||||
[Verb("time", HelpText = nameof(Str.TimeTool), ResourceType = typeof(Str))]
|
[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))]
|
[Option('s', "sync", HelpText = nameof(Str.SyncToLocalTime), Default = false, ResourceType = typeof(Str))]
|
||||||
public bool Sync { get; set; }
|
public bool Sync { get; set; }
|
||||||
|
@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
|
|
||||||
namespace Dot.ToLf;
|
namespace Dot.ToLf;
|
||||||
|
|
||||||
public sealed class Main : Tool<Option>, IDisposable
|
public sealed class Main : ToolBase<Option>, IDisposable
|
||||||
{
|
{
|
||||||
private int _breakCnt;
|
private int _breakCnt;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace Dot;
|
namespace Dot;
|
||||||
|
|
||||||
public abstract class Tool<TOption> : ITool
|
public abstract class ToolBase<TOption> : ITool where TOption : OptionBase
|
||||||
{
|
{
|
||||||
protected readonly ProgressBarOptions //
|
protected readonly ProgressBarOptions //
|
||||||
DefaultProgressBarOptions = new() {
|
DefaultProgressBarOptions = new() {
|
||||||
@ -15,7 +15,7 @@ public abstract class Tool<TOption> : ITool
|
|||||||
|
|
||||||
protected TOption Opt { get; }
|
protected TOption Opt { get; }
|
||||||
|
|
||||||
protected Tool(TOption opt)
|
protected ToolBase(TOption opt)
|
||||||
{
|
{
|
||||||
Opt = opt;
|
Opt = opt;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user