public static async Task ExecuteRegisterTasksAsync(string taskFileName, CancellationToken cancel = default) { CactiTask task = CactiTask.LoadFromFile(taskFileName); await task.ExecuteRegisterTasksAsync(cancel); }
public static CactiTask LoadFromData(ReadOnlySpan <byte> data) { string body = data._GetString(); string[] lines = body._GetLines(true); int mode = 0; CactiTask ret = new CactiTask(); string graphName = ""; foreach (string line in lines) { if (line.StartsWith("#") == false && line.StartsWith("//") == false && line.StartsWith(";") == false) { if (mode == 0) { // URL 等 if (line._GetKeyAndValue(out string key, out string value)) { switch (key.ToUpperInvariant()) { case "URL": ret.BaseUrl = value; break; case "USERNAME": ret.Username = value; break; case "PASSWORD": ret.Password = value; break; } } } else if (mode == 1) { string line2 = line.Trim(); // ホスト一覧 (形式は description hostname) if (line2.StartsWith("[") == false) { if (line2._GetKeyAndValue(out string description, out string hostname)) { CactiHost h = new CactiHost { Description = description, Hostname = hostname, }; ret.Hosts.Add(h); } else if (line2._IsFilled()) { CactiHost h = new CactiHost { Description = line2, Hostname = line2, }; ret.Hosts.Add(h); } } } else if (mode == 2) { // 値一覧 if (line.StartsWith("[") == false) { if (line.StartsWith(" ") || line.StartsWith("\t")) { // 値名ワイルドカード if (graphName._IsFilled()) { CactiEnableItem item = new CactiEnableItem(graphName, line.Trim()); ret.Items.Add(item); } } else { // グラフ名 graphName = line.Trim(); } } } switch (line.ToUpperInvariant()) { case "[HOSTS]": mode = 1; break; case "[VALUES]": mode = 2; break; } } } return(ret); }