-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
51 lines (45 loc) · 1.15 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace AutoUpdateConfig;
internal static class Utils
{
public static async Task<string> GetContent(string targetUrl)
{
Log.Info($"Get response from {targetUrl}");
using var client = new HttpClient();
var response = await client.GetAsync(targetUrl);
if (response.IsSuccessStatusCode)
{
using var content = response.Content;
var res = await content.ReadAsStringAsync();
Log.Info("Get response complete");
return res;
}
else
{
Log.Error($"Failed: {response.StatusCode}");
return string.Empty;
}
}
public static bool IsNullOrWhiteSpace(this string? value)
{
return string.IsNullOrWhiteSpace(value);
}
}
internal static class Log
{
public static void Info(string str)
{
Msg("INFO", str);
}
public static void Warn(string str)
{
Msg("WARN", str);
}
public static void Error(string str)
{
Msg("ERROR", str);
}
static void Msg(string type, string str)
{
Console.WriteLine($"{DateTime.Now:s} [{type}] {str}");
}
}