refactor: use some better syntax
This commit is contained in:
parent
fff3ce820b
commit
52ec386801
|
@ -36,7 +36,7 @@ namespace NoSoliciting {
|
|||
|
||||
Definitions defs = null;
|
||||
|
||||
var download = await Download().ConfigureAwait(true);
|
||||
Tuple<Definitions, string> download = await Download().ConfigureAwait(true);
|
||||
if (download != null) {
|
||||
defs = download.Item1;
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace NoSoliciting {
|
|||
}
|
||||
|
||||
public static Definitions Load(string text) {
|
||||
var de = new DeserializerBuilder()
|
||||
IDeserializer de = new DeserializerBuilder()
|
||||
.WithNamingConvention(UnderscoredNamingConvention.Instance)
|
||||
.WithTypeConverter(new MatcherConverter())
|
||||
.IgnoreUnmatchedProperties()
|
||||
|
@ -82,7 +82,7 @@ namespace NoSoliciting {
|
|||
}
|
||||
|
||||
string text;
|
||||
using (var file = File.OpenText(cachedPath)) {
|
||||
using (StreamReader file = File.OpenText(cachedPath)) {
|
||||
text = await file.ReadToEndAsync().ConfigureAwait(true);
|
||||
}
|
||||
|
||||
|
@ -102,11 +102,10 @@ namespace NoSoliciting {
|
|||
|
||||
private static async Task<Tuple<Definitions, string>> Download() {
|
||||
try {
|
||||
using (WebClient client = new WebClient()) {
|
||||
string text = await client.DownloadStringTaskAsync(URL).ConfigureAwait(true);
|
||||
LastError = null;
|
||||
return Tuple.Create(Load(text), text);
|
||||
}
|
||||
using WebClient client = new WebClient();
|
||||
string text = await client.DownloadStringTaskAsync(URL).ConfigureAwait(true);
|
||||
LastError = null;
|
||||
return Tuple.Create(Load(text), text);
|
||||
} catch (Exception e) when (e is WebException || e is YamlException) {
|
||||
PluginLog.Log($"Could not download newest definitions.");
|
||||
PluginLog.Log(e.ToString());
|
||||
|
@ -122,9 +121,8 @@ namespace NoSoliciting {
|
|||
|
||||
byte[] b = Encoding.UTF8.GetBytes(defs);
|
||||
|
||||
using (var file = File.OpenWrite(cachePath)) {
|
||||
await file.WriteAsync(b, 0, b.Length).ConfigureAwait(true);
|
||||
}
|
||||
using FileStream file = File.OpenWrite(cachePath);
|
||||
await file.WriteAsync(b, 0, b.Length).ConfigureAwait(true);
|
||||
}
|
||||
|
||||
internal void Initialise(Plugin plugin) {
|
||||
|
@ -221,7 +219,7 @@ namespace NoSoliciting {
|
|||
// calculate likelihood
|
||||
int likelihood = 0;
|
||||
|
||||
foreach (var matchers in this.LikelyMatchers) {
|
||||
foreach (List<Matcher> matchers in this.LikelyMatchers) {
|
||||
if (matchers.Any(matcher => matcher.Matches(text))) {
|
||||
likelihood += 1;
|
||||
}
|
||||
|
|
|
@ -256,21 +256,12 @@ namespace NoSoliciting {
|
|||
ImGui.Text("Click on one of the entries below to report it to the developer as miscategorised.");
|
||||
|
||||
if (this.lastReportStatus != ReportStatus.None) {
|
||||
string status;
|
||||
switch (this.lastReportStatus) {
|
||||
case ReportStatus.Failure:
|
||||
status = "failed to send";
|
||||
break;
|
||||
case ReportStatus.Successful:
|
||||
status = "sent successfully";
|
||||
break;
|
||||
case ReportStatus.InProgress:
|
||||
status = "sending";
|
||||
break;
|
||||
default:
|
||||
status = "unknown";
|
||||
break;
|
||||
}
|
||||
string status = this.lastReportStatus switch {
|
||||
ReportStatus.Failure => "failed to send",
|
||||
ReportStatus.Successful => "sent successfully",
|
||||
ReportStatus.InProgress => "sending",
|
||||
_ => "unknown",
|
||||
};
|
||||
ImGui.Text($"Last report status: {status}");
|
||||
}
|
||||
|
||||
|
@ -394,10 +385,9 @@ namespace NoSoliciting {
|
|||
Task.Run(async () => {
|
||||
string resp = null;
|
||||
try {
|
||||
using (WebClient client = new WebClient()) {
|
||||
this.lastReportStatus = ReportStatus.InProgress;
|
||||
resp = await client.UploadStringTaskAsync(this.plugin.Definitions.ReportUrl, message.ToJson()).ConfigureAwait(true);
|
||||
}
|
||||
using WebClient client = new WebClient();
|
||||
this.lastReportStatus = ReportStatus.InProgress;
|
||||
resp = await client.UploadStringTaskAsync(this.plugin.Definitions.ReportUrl, message.ToJson()).ConfigureAwait(true);
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
} catch (Exception) { }
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
|
|
Loading…
Reference in New Issue
Block a user