mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
minor tidies
This commit is contained in:
parent
f5d27329dd
commit
078c86ecd8
4 changed files with 21 additions and 4 deletions
|
|
@ -18,6 +18,8 @@ public Logger(string appInsightsKey)
|
|||
public void Dispose()
|
||||
{
|
||||
telemetryClient.Flush();
|
||||
|
||||
//https://docs.microsoft.com/en-us/azure/application-insights/app-insights-api-custom-events-metrics#flushing-data
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ private static async Task TryCaptureSnapshots()
|
|||
{
|
||||
await CaptureSnapshots(BatchSize).TimeoutAfter(Timeout);
|
||||
}
|
||||
catch (TimeoutException)
|
||||
catch (TimeoutException te)
|
||||
{
|
||||
logger.Log("Timeout - Program.CaptureSnapshots()");
|
||||
logger.Log(te);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,6 +200,8 @@ private void TrackException(Exception e)
|
|||
{
|
||||
telemetryClient.TrackException(e);
|
||||
telemetryClient.Flush();
|
||||
|
||||
//https://docs.microsoft.com/en-us/azure/application-insights/app-insights-api-custom-events-metrics#flushing-data
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,24 +16,37 @@ public static class UserAgentService
|
|||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
|
||||
|
||||
public static async Task<string> GetMostPopularString()
|
||||
{
|
||||
try
|
||||
{
|
||||
return await TryGetLatestMostPopularStringOrDefault();
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
return UaStringDefault;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<string> TryGetLatestMostPopularStringOrDefault()
|
||||
{
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
var response = await httpClient.GetAsync(UaStringSource, HttpCompletionOption.ResponseHeadersRead);
|
||||
response.EnsureSuccessStatusCode();
|
||||
using (var stream = await response.Content.ReadAsStreamAsync())
|
||||
using (var streamReader = new StreamReader(stream))
|
||||
{
|
||||
string line;
|
||||
while ((line = await streamReader.ReadLineAsync()) != null)
|
||||
if (line.Contains(UaStringSourceClass))
|
||||
return ParseUaString(line);
|
||||
return ParseUaStringOrDefault(line);
|
||||
}
|
||||
}
|
||||
|
||||
return UaStringDefault;
|
||||
}
|
||||
|
||||
private static string ParseUaString(string line)
|
||||
private static string ParseUaStringOrDefault(string line)
|
||||
{
|
||||
var classIndex = line.IndexOf(UaStringSourceClass, StringComparison.Ordinal);
|
||||
var postClassIndexSubstring = line.Substring(classIndex);
|
||||
|
|
|
|||
Loading…
Reference in a new issue