| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System;
- using System.Collections.Generic;
- namespace IvfTl.ControlHost
- {
- /// <summary>control 启动参数(由 operate 拉起时命令行传入)。纯 BCL,无 WPF/硬件依赖,可单测。</summary>
- public class HostArgs
- {
- public string Account { get; set; } = "";
- public string Password { get; set; } = "";
- public string CacheDisk { get; set; } = "";
- public int Port { get; set; } = 38080;
- /// <summary>有账号密码才允许启动采集(对齐 operate MainWindow 的空账号守卫)。</summary>
- public bool IsValid =>
- !string.IsNullOrEmpty(Account) && !string.IsNullOrEmpty(Password);
- public static HostArgs Parse(string[] args)
- {
- var map = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- if (args != null)
- {
- foreach (var raw in args)
- {
- if (string.IsNullOrEmpty(raw)) continue;
- var s = raw.StartsWith("--") ? raw.Substring(2) : raw;
- int eq = s.IndexOf('=');
- if (eq <= 0) continue;
- map[s.Substring(0, eq)] = s.Substring(eq + 1);
- }
- }
- var a = new HostArgs();
- if (map.TryGetValue("account", out var acc)) a.Account = acc;
- if (map.TryGetValue("password", out var pwd)) a.Password = pwd;
- if (map.TryGetValue("cacheDisk", out var cd)) a.CacheDisk = cd;
- if (map.TryGetValue("port", out var p) && int.TryParse(p, out var pi)) a.Port = pi;
- return a;
- }
- }
- }
|