mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 10:58:31 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ecde89be0 | |||
| 845e80577c | |||
| 31a04b13e6 | |||
| 64d893ae0f |
@@ -202,6 +202,9 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
|||||||
case FeedReadResult.NotEnabled:
|
case FeedReadResult.NotEnabled:
|
||||||
case FeedReadResult.NotModified:
|
case FeedReadResult.NotModified:
|
||||||
|
|
||||||
|
// Reset status to success
|
||||||
|
LastReadResult = FeedReadResult.Success;
|
||||||
|
|
||||||
// Ignore
|
// Ignore
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -265,14 +268,20 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
|||||||
var clientHandler = new HttpClientHandler
|
var clientHandler = new HttpClientHandler
|
||||||
{
|
{
|
||||||
// Set that we'll accept compressed data
|
// Set that we'll accept compressed data
|
||||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli,
|
||||||
AllowAutoRedirect = true
|
AllowAutoRedirect = true
|
||||||
};
|
};
|
||||||
|
|
||||||
_httpClient = new HttpClient(clientHandler);
|
_httpClient = new HttpClient(clientHandler)
|
||||||
|
{
|
||||||
// Set a timeout
|
// Set a timeout
|
||||||
_httpClient.Timeout = TimeSpan.FromSeconds(10);
|
Timeout = TimeSpan.FromSeconds(10)
|
||||||
|
};
|
||||||
|
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.ParseAdd("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||||
|
_httpClient.DefaultRequestHeaders.AcceptEncoding.ParseAdd("gzip, deflate, br");
|
||||||
|
_httpClient.DefaultRequestHeaders.AcceptLanguage.ParseAdd("en-US,en;q=0.9");
|
||||||
|
_httpClient.DefaultRequestHeaders.CacheControl = CacheControlHeaderValue.Parse("max-age=0");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a user agent string
|
// Set a user agent string
|
||||||
@@ -283,6 +292,8 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
|||||||
// If we need to authenticate then set the credentials
|
// If we need to authenticate then set the credentials
|
||||||
_httpClient.DefaultRequestHeaders.Authorization = Authenticate ? new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Username}:{Password}"))) : null;
|
_httpClient.DefaultRequestHeaders.Authorization = Authenticate ? new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Username}:{Password}"))) : null;
|
||||||
|
|
||||||
|
_httpClient.DefaultRequestHeaders.IfModifiedSince = LastChecked;
|
||||||
|
|
||||||
// Attempt to get the response
|
// Attempt to get the response
|
||||||
var response = _httpClient.GetAsync(Source).Result;
|
var response = _httpClient.GetAsync(Source).Result;
|
||||||
|
|
||||||
@@ -313,6 +324,11 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
|||||||
}
|
}
|
||||||
catch (HttpRequestException httpRequestException)
|
catch (HttpRequestException httpRequestException)
|
||||||
{
|
{
|
||||||
|
if (httpRequestException.StatusCode == HttpStatusCode.NotModified)
|
||||||
|
{
|
||||||
|
return Tuple.Create(FeedReadResult.NotModified, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
Log.Logger.Error(httpRequestException, "Exception");
|
Log.Logger.Error(httpRequestException, "Exception");
|
||||||
|
|
||||||
return HandleHttpRequestException(httpRequestException);
|
return HandleHttpRequestException(httpRequestException);
|
||||||
@@ -391,12 +407,12 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
|||||||
return FeedReadResult.NotDue;
|
return FeedReadResult.NotDue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're checking it now so update the time
|
|
||||||
LastChecked = DateTimeOffset.Now;
|
|
||||||
|
|
||||||
// Read the feed text
|
// Read the feed text
|
||||||
var retrieveResult = RetrieveFeed();
|
var retrieveResult = RetrieveFeed();
|
||||||
|
|
||||||
|
// We're checking it now so update the time
|
||||||
|
LastChecked = DateTimeOffset.Now;
|
||||||
|
|
||||||
// Get the information out of the async result
|
// Get the information out of the async result
|
||||||
var result = retrieveResult.Item1;
|
var result = retrieveResult.Item1;
|
||||||
var feedText = retrieveResult.Item2;
|
var feedText = retrieveResult.Item2;
|
||||||
|
|||||||
@@ -24,17 +24,18 @@ public partial class MainWindow
|
|||||||
{
|
{
|
||||||
StopTimer();
|
StopTimer();
|
||||||
|
|
||||||
_mainTimer.Dispose();
|
_mainTimer?.Dispose();
|
||||||
|
_mainTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartTimer()
|
private void StartTimer()
|
||||||
{
|
{
|
||||||
_mainTimer.Start();
|
_mainTimer?.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopTimer()
|
private void StopTimer()
|
||||||
{
|
{
|
||||||
_mainTimer.Stop();
|
_mainTimer?.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleMainTimerElapsed(object sender, EventArgs e)
|
private void HandleMainTimerElapsed(object sender, EventArgs e)
|
||||||
|
|||||||
@@ -166,6 +166,12 @@ public partial class MainWindow
|
|||||||
|
|
||||||
// Delete the feed
|
// Delete the feed
|
||||||
_database.SaveChanges(() => _database.Feeds.Remove(feedToDelete));
|
_database.SaveChanges(() => _database.Feeds.Remove(feedToDelete));
|
||||||
|
|
||||||
|
// Refresh the database to current settings
|
||||||
|
ResetDatabase();
|
||||||
|
|
||||||
|
// Re-initialize the feed display
|
||||||
|
DisplayFeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenAllFeedItemsOnSinglePage()
|
private void OpenAllFeedItemsOnSinglePage()
|
||||||
|
|||||||
Reference in New Issue
Block a user