mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-01-14 01:25:38 -05:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1db13fbe2e | |||
| c64ec21bd9 |
@@ -10,7 +10,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -19,6 +18,7 @@ using System.Net.Http.Headers;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FeedCenter;
|
||||
|
||||
@@ -270,7 +270,11 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
||||
_httpClient.DefaultRequestHeaders.Authorization = Authenticate ? new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Username}:{Password}"))) : null;
|
||||
|
||||
// Attempt to get the response
|
||||
var feedStream = _httpClient.GetStreamAsync(Source).Result;
|
||||
var response = _httpClient.GetAsync(Source).Result;
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var feedStream = response.Content.ReadAsStream();
|
||||
|
||||
// Create the text reader
|
||||
using StreamReader textReader = new XmlSanitizingStream(feedStream, Encoding.UTF8);
|
||||
@@ -293,78 +297,23 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
||||
|
||||
return Tuple.Create(FeedReadResult.Success, feedText);
|
||||
}
|
||||
catch (IOException ioException)
|
||||
catch (HttpRequestException httpRequestException)
|
||||
{
|
||||
Log.Logger.Error(ioException, "Exception");
|
||||
Log.Logger.Error(httpRequestException, "Exception");
|
||||
|
||||
return Tuple.Create(FeedReadResult.ConnectionFailed, string.Empty);
|
||||
return HandleHttpRequestException(httpRequestException);
|
||||
}
|
||||
catch (AggregateException aggregateException)
|
||||
{
|
||||
Log.Logger.Error(aggregateException, "Exception");
|
||||
|
||||
var innerException = aggregateException.InnerException;
|
||||
|
||||
if (innerException is not HttpRequestException httpRequestException)
|
||||
return Tuple.Create(FeedReadResult.UnknownError, string.Empty);
|
||||
|
||||
switch (httpRequestException.StatusCode)
|
||||
return aggregateException.InnerException switch
|
||||
{
|
||||
case HttpStatusCode.ServiceUnavailable:
|
||||
return Tuple.Create(FeedReadResult.TemporarilyUnavailable, string.Empty);
|
||||
|
||||
case HttpStatusCode.InternalServerError:
|
||||
return Tuple.Create(FeedReadResult.ServerError, string.Empty);
|
||||
|
||||
case HttpStatusCode.NotModified:
|
||||
return Tuple.Create(FeedReadResult.NotModified, string.Empty);
|
||||
|
||||
case HttpStatusCode.NotFound:
|
||||
return Tuple.Create(FeedReadResult.NotFound, string.Empty);
|
||||
|
||||
case HttpStatusCode.Unauthorized:
|
||||
case HttpStatusCode.Forbidden:
|
||||
return Tuple.Create(FeedReadResult.Unauthorized, string.Empty);
|
||||
|
||||
case HttpStatusCode.Moved:
|
||||
return Tuple.Create(FeedReadResult.Moved, string.Empty);
|
||||
}
|
||||
|
||||
if (httpRequestException.InnerException is not SocketException socketException)
|
||||
return Tuple.Create(FeedReadResult.UnknownError, string.Empty);
|
||||
|
||||
return socketException.SocketErrorCode switch
|
||||
{
|
||||
SocketError.NoData => Tuple.Create(FeedReadResult.NoResponse, string.Empty),
|
||||
SocketError.HostNotFound => Tuple.Create(FeedReadResult.NotFound, string.Empty),
|
||||
TaskCanceledException => Tuple.Create(FeedReadResult.Timeout, string.Empty),
|
||||
HttpRequestException httpRequestException => HandleHttpRequestException(httpRequestException),
|
||||
_ => Tuple.Create(FeedReadResult.UnknownError, string.Empty)
|
||||
};
|
||||
}
|
||||
catch (WebException webException)
|
||||
{
|
||||
var result = FeedReadResult.UnknownError;
|
||||
|
||||
switch (webException.Status)
|
||||
{
|
||||
case WebExceptionStatus.ConnectFailure:
|
||||
case WebExceptionStatus.NameResolutionFailure:
|
||||
result = FeedReadResult.ConnectionFailed;
|
||||
|
||||
break;
|
||||
|
||||
case WebExceptionStatus.Timeout:
|
||||
result = FeedReadResult.Timeout;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Log.Logger.Error(webException, "Exception");
|
||||
|
||||
if (result == FeedReadResult.UnknownError)
|
||||
Debug.Print("Unknown error");
|
||||
|
||||
return Tuple.Create(result, string.Empty);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Logger.Error(exception, "Exception");
|
||||
@@ -373,6 +322,42 @@ public partial class Feed : RealmObject, INotifyDataErrorInfo
|
||||
}
|
||||
}
|
||||
|
||||
private static Tuple<FeedReadResult, string> HandleHttpRequestException(HttpRequestException httpRequestException)
|
||||
{
|
||||
switch (httpRequestException.StatusCode)
|
||||
{
|
||||
case HttpStatusCode.ServiceUnavailable:
|
||||
return Tuple.Create(FeedReadResult.TemporarilyUnavailable, string.Empty);
|
||||
|
||||
case HttpStatusCode.InternalServerError:
|
||||
return Tuple.Create(FeedReadResult.ServerError, string.Empty);
|
||||
|
||||
case HttpStatusCode.NotModified:
|
||||
return Tuple.Create(FeedReadResult.NotModified, string.Empty);
|
||||
|
||||
case HttpStatusCode.NotFound:
|
||||
return Tuple.Create(FeedReadResult.NotFound, string.Empty);
|
||||
|
||||
case HttpStatusCode.Unauthorized:
|
||||
case HttpStatusCode.Forbidden:
|
||||
return Tuple.Create(FeedReadResult.Unauthorized, string.Empty);
|
||||
|
||||
case HttpStatusCode.Moved:
|
||||
case HttpStatusCode.Redirect:
|
||||
return Tuple.Create(FeedReadResult.Moved, string.Empty);
|
||||
}
|
||||
|
||||
if (httpRequestException.InnerException is not SocketException socketException)
|
||||
return Tuple.Create(FeedReadResult.UnknownError, string.Empty);
|
||||
|
||||
return socketException.SocketErrorCode switch
|
||||
{
|
||||
SocketError.NoData => Tuple.Create(FeedReadResult.NoResponse, string.Empty),
|
||||
SocketError.HostNotFound => Tuple.Create(FeedReadResult.NotFound, string.Empty),
|
||||
_ => Tuple.Create(FeedReadResult.UnknownError, string.Empty)
|
||||
};
|
||||
}
|
||||
|
||||
private FeedReadResult ReadFeed(bool forceRead)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
<HintPath>$(WixExtDir)\WixNetFxExtension.dll</HintPath>
|
||||
<Name>WixNetFxExtension</Name>
|
||||
</WixExtension>
|
||||
<WixExtension Include="WixUtilExtension">
|
||||
<HintPath>$(WixExtDir)\WixUtilExtension.dll</HintPath>
|
||||
<Name>WixUtilExtension</Name>
|
||||
</WixExtension>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Application\FeedCenter.csproj">
|
||||
@@ -66,12 +70,4 @@
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent />
|
||||
</PropertyGroup>
|
||||
<!--
|
||||
To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Wix.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
|
||||
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
|
||||
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"
|
||||
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
|
||||
|
||||
<?define ProductName="$(fileVersion.ProductName($(var.FeedCenter.TargetPath)))" ?>
|
||||
<?define CompanyName="$(fileVersion.CompanyName($(var.FeedCenter.TargetPath)))" ?>
|
||||
@@ -13,6 +14,18 @@
|
||||
UpgradeCode="5e5c13a5-635e-4310-a653-0f9760f46935"
|
||||
Compressed="no">
|
||||
|
||||
<util:DirectorySearch Id="DotnetDesktopRuntimeSearch_x86"
|
||||
Path="[ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App\7.0.5"
|
||||
Result="exists"
|
||||
Variable="DotnetDesktopRuntimeExists_x86"
|
||||
Condition="NOT VersionNT64" />
|
||||
|
||||
<util:DirectorySearch Id="DotnetDesktopRuntimeSearch_x64"
|
||||
Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\7.0.5"
|
||||
Result="exists"
|
||||
Variable="DotnetDesktopRuntimeExists_x64"
|
||||
Condition="VersionNT64" />
|
||||
|
||||
<BootstrapperApplicationRef Id="WixExtendedBootstrapperApplication.HyperlinkLicense">
|
||||
<bal:WixExtendedBootstrapperApplication LicenseUrl=""
|
||||
SuppressOptionsUI="yes"
|
||||
@@ -28,9 +41,10 @@
|
||||
DisplayName=".NET 7.0 Desktop Runtime (x64)"
|
||||
InstallCommand="/install /quiet"
|
||||
Permanent="yes"
|
||||
Compressed="no"
|
||||
Compressed="no"
|
||||
DownloadUrl="https://download.visualstudio.microsoft.com/download/pr/dffb1939-cef1-4db3-a579-5475a3061cdd/578b208733c914c7b7357f6baa4ecfd6/windowsdesktop-runtime-7.0.5-win-x64.exe"
|
||||
Name="windowsdesktop-runtime-7.0.5-win-x64.exe"
|
||||
DetectCondition="DotnetDesktopRuntimeExists_x64 = 1"
|
||||
InstallCondition='VersionNT64'>
|
||||
<RemotePayload ProductName="Microsoft Windows Desktop Runtime - 7.0.5 (x64)"
|
||||
Description="Microsoft Windows Desktop Runtime - 7.0.5 (x64)"
|
||||
@@ -42,9 +56,10 @@
|
||||
DisplayName=".NET 7.0 Desktop Runtime (x86)"
|
||||
InstallCommand="/install /quiet"
|
||||
Permanent="yes"
|
||||
Compressed="no"
|
||||
Compressed="no"
|
||||
DownloadUrl="https://download.visualstudio.microsoft.com/download/pr/eb64dcd1-d277-4798-ada1-600805c9e2dc/fc73c843d66f3996e7ef22468f4902e6/windowsdesktop-runtime-7.0.5-win-x86.exe"
|
||||
Name="windowsdesktop-runtime-7.0.5-win-x86.exe"
|
||||
DetectCondition="DotnetDesktopRuntimeExists_x86 = 1"
|
||||
InstallCondition='NOT VersionNT64'>
|
||||
<RemotePayload ProductName="Microsoft Windows Desktop Runtime - 7.0.5 (x86)"
|
||||
Description="Microsoft Windows Desktop Runtime - 7.0.5 (x86)"
|
||||
|
||||
Reference in New Issue
Block a user