Skip to content

Commit

Permalink
properly communicate a fwe failure reasons in the fax list
Browse files Browse the repository at this point in the history
  • Loading branch information
pschichtel committed Oct 25, 2020
1 parent 5d3b459 commit 5977d04
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Core/Core/Sipgate/FaxScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private async void _pollFaxStatus(TrackedFax fax)
fax.ChangeStatus(FaxStatus.SuccessfullySent);
break;
case FaxEntryStatus.Failed:
fax.FailureCause = new FaxSendException(historyEntry.Status);
fax.ChangeStatus(FaxStatus.Failed);
break;
case FaxEntryStatus.Sending:
Expand Down Expand Up @@ -204,4 +205,14 @@ public static bool CanResend(this FaxStatus status)
}
}
}

public class FaxSendException : Exception
{
public EntryStatus Status { get; }

public FaxSendException(EntryStatus status) : base($"Final status of fax: {status}")
{
Status = status;
}
}
}
31 changes: 25 additions & 6 deletions GUI/FaxListItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Net;
using System.Windows;
using NLog;
using SipgateVirtualFax.Core;
using SipgateVirtualFax.Core.Sipgate;
using static SipGateVirtualFaxGui.Properties.Resources;
using MessageBox = System.Windows.MessageBox;

namespace SipGateVirtualFaxGui
Expand Down Expand Up @@ -32,7 +34,7 @@ private void OpenPdf_OnClick(object sender, RoutedEventArgs ev)
catch (Exception e)
{
_logger.Error(e, "Failed to open a fax document!");
MessageBox.Show(Properties.Resources.Err_FailedToOpenDocument);
MessageBox.Show(Err_FailedToOpenDocument);
}
}
}
Expand All @@ -53,16 +55,33 @@ public string Status
{
return Fax.Status switch
{
FaxStatus.Pending => Properties.Resources.Status_Pending,
FaxStatus.Sending => Properties.Resources.Status_Sending,
FaxStatus.SuccessfullySent => Properties.Resources.Status_SuccessfullySent,
FaxStatus.Failed => Properties.Resources.Status_Failed,
FaxStatus.Unknown => Properties.Resources.Status_Unknown,
FaxStatus.Pending => Status_Pending,
FaxStatus.Sending => Status_Sending,
FaxStatus.SuccessfullySent => Status_SuccessfullySent,
FaxStatus.Failed => FailedStatusText(Fax.FailureCause),
FaxStatus.Unknown => Status_Unknown,
_ => "???"
};
}
}

private static string FailedStatusText(Exception? cause)
{
if (cause != null)
{
switch (cause)
{
case FaxSendException e when e.Status == HistoryEntry.EntryStatus.NoPickup:
return string.Format(Status_FailedWithReason, Status_FailedNoPickup);
case FaxSendException e when e.Status == HistoryEntry.EntryStatus.Busy:
return string.Format(Status_FailedWithReason, Status_FailedBusy);
case SipgateApiHttpException e when e.Status == HttpStatusCode.ProxyAuthenticationRequired:
return string.Format(Status_FailedWithReason, Status_FailedInvalidDestination);
}
}
return Status_Failed;
}

private TrackedFax ConfigureFax(TrackedFax fax)
{
fax.StatusChanged += (sender, status) =>
Expand Down
36 changes: 36 additions & 0 deletions GUI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions GUI/Properties/Resources.de.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions GUI/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@
<data name="Err_TwainFailedToCloseSession" xml:space="preserve">
<value>Die Verbindung zum Scanner-Subsystem konnte nicht geschlossen werden! Möglicherweise war der Scan trotzdem erfolgreich.</value>
</data>
<data name="Status_FailedWithReason" xml:space="preserve">
<value>Senden fehlgeschlagen: {0}</value>
</data>
<data name="Status_FailedNoPickup" xml:space="preserve">
<value>Empfänger hat nicht abgehoben.</value>
</data>
<data name="Status_FailedBusy" xml:space="preserve">
<value>Empfänger ist besetzt.</value>
</data>
<data name="Status_FailedInvalidDestination" xml:space="preserve">
<value>Empfänger ist ungültig.</value>
</data>
</root>
12 changes: 12 additions & 0 deletions GUI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@
<data name="Err_TwainUnknown" xml:space="preserve">
<value>An unknown scanning related error occurred. Please report this to the developer!</value>
</data>
<data name="Status_FailedWithReason" xml:space="preserve">
<value>Sending failed: {0}</value>
</data>
<data name="Status_FailedNoPickup" xml:space="preserve">
<value>Recipient did not pick up.</value>
</data>
<data name="Status_FailedBusy" xml:space="preserve">
<value>Recipient is busy.</value>
</data>
<data name="Status_FailedInvalidDestination" xml:space="preserve">
<value>Recipient is invalid.</value>
</data>
</root>

0 comments on commit 5977d04

Please sign in to comment.