Revize afafbc22
Přidáno uživatelem Pultak před téměř 3 roky(ů)
ld_client/LDClient/Program.cs | ||
---|---|---|
41 | 41 |
Config.CacheFileName |
42 | 42 |
); |
43 | 43 |
|
44 |
IProcessDetection processProcessDetection = new ProcessProcessDetection(
|
|
44 |
IProcessDetection processProcessDetection = new ProcessDetection( |
|
45 | 45 |
Config.T32ProcessName, |
46 | 46 |
Config.DetectionPeriod, |
47 | 47 |
InfoFetcher, |
48 |
DefaultApiClient |
|
48 |
DefaultApiClient, |
|
49 |
new ProcessUtils() |
|
49 | 50 |
); |
50 | 51 |
|
51 | 52 |
var apiClientThread = new Thread(DefaultApiClient.Run) { |
ld_client/LDClient/appsettings.json | ||
---|---|---|
15 | 15 |
"LogFlowType": 0 |
16 | 16 |
}, |
17 | 17 |
"Network": { |
18 |
"ApiBaseAddress": "http://127.0.0.1",
|
|
19 |
"ApiLDEndPoint": "/lauterbach-debugger-logs/",
|
|
18 |
"ApiBaseAddress": "http://192.168.0.22",
|
|
19 |
"ApiLDEndPoint": "/api/v1/ld-logs",
|
|
20 | 20 |
"ApiPort": 8000 |
21 | 21 |
}, |
22 | 22 |
"Cache": { |
ld_client/LDClient/network/ApiClient.cs | ||
---|---|---|
10 | 10 |
|
11 | 11 |
public sealed class ApiClient : IApiClient { |
12 | 12 |
|
13 |
private readonly string _uri;
|
|
14 |
private readonly HttpClient _client;
|
|
15 |
private readonly IPersistentQueue _cache; |
|
13 |
public IHttpClient _client;
|
|
14 |
public IPersistentQueue _cache;
|
|
15 |
|
|
16 | 16 |
private readonly uint _retryPeriod; |
17 | 17 |
private readonly uint _maxEntries; |
18 | 18 |
private readonly uint _maxRetries; |
19 | 19 |
|
20 | 20 |
public ApiClient(string url, uint port, string path, uint retryPeriod, uint maxEntries, uint maxRetries, string cacheFilename) { |
21 |
_uri = $"{url}:{port}{path}";
|
|
21 |
var uri = $"{url}:{port}{path}";
|
|
22 | 22 |
_retryPeriod = retryPeriod; |
23 | 23 |
_maxEntries = maxEntries; |
24 | 24 |
_maxRetries = maxRetries; |
25 | 25 |
|
26 |
_client = new HttpClient(); |
|
26 |
_client = new HttpClient(uri);
|
|
27 | 27 |
_cache = new PersistentQueue(cacheFilename); |
28 | 28 |
} |
29 | 29 |
|
... | ... | |
32 | 32 |
Stopwatch stopWatch = new(); |
33 | 33 |
stopWatch.Start(); |
34 | 34 |
|
35 |
var response = await _client.PostAsJsonAsync(_uri, payload, new JsonSerializerOptions { |
|
36 |
Converters = { |
|
37 |
new JsonStringEnumConverter( JsonNamingPolicy.CamelCase) |
|
38 |
} |
|
39 |
}); |
|
35 |
var response = await _client.PostAsJsonAsync(payload); |
|
40 | 36 |
stopWatch.Stop(); |
41 | 37 |
CreateRequestLog(payload, response, stopWatch.ElapsedMilliseconds); |
42 | 38 |
|
ld_client/LDClient/network/HttpClient.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Net.Http.Json; |
|
5 |
using System.Text; |
|
6 |
using System.Text.Json; |
|
7 |
using System.Text.Json.Serialization; |
|
8 |
using System.Threading.Tasks; |
|
9 |
using LDClient.network.data; |
|
10 |
|
|
11 |
namespace LDClient.network { |
|
12 |
public class HttpClient : IHttpClient{ |
|
13 |
|
|
14 |
private readonly System.Net.Http.HttpClient _httpClient; |
|
15 |
|
|
16 |
private readonly string _uri; |
|
17 |
public HttpClient(string uri) { |
|
18 |
|
|
19 |
_httpClient = new System.Net.Http.HttpClient(); |
|
20 |
_uri = uri; |
|
21 |
} |
|
22 |
|
|
23 |
public Task<HttpResponseMessage> PostAsJsonAsync(Payload payload) { |
|
24 |
return _httpClient.PostAsJsonAsync(_uri, payload, new JsonSerializerOptions { |
|
25 |
Converters = { |
|
26 |
new JsonStringEnumConverter( JsonNamingPolicy.CamelCase) |
|
27 |
} |
|
28 |
}); |
|
29 |
|
|
30 |
} |
|
31 |
} |
|
32 |
} |
ld_client/LDClient/network/IHttpClient.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using LDClient.network.data; |
|
7 |
|
|
8 |
namespace LDClient.network { |
|
9 |
public interface IHttpClient { |
|
10 |
|
|
11 |
public Task<HttpResponseMessage> PostAsJsonAsync(Payload payload); |
|
12 |
} |
|
13 |
} |
ld_client/LDClient/utils/FileUtils.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace LDClient.utils { |
|
8 |
public class FileUtils : IFileUtils { |
|
9 |
public string[] ReadFileAllLines(string file) { |
|
10 |
return File.ReadAllLines(file); |
|
11 |
} |
|
12 |
} |
|
13 |
} |
ld_client/LDClient/utils/IFileUtils.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace LDClient.utils { |
|
8 |
public interface IFileUtils { |
|
9 |
|
|
10 |
public string[] ReadFileAllLines(string file); |
|
11 |
} |
|
12 |
} |
Také k dispozici: Unified diff
re #9443 refactoring of network and other utils for the purpose of testing