diff --git a/Core/Core/Sipgate/FaxScheduler.cs b/Core/Core/Sipgate/FaxScheduler.cs index ab9d1a2..ea03ba3 100644 --- a/Core/Core/Sipgate/FaxScheduler.cs +++ b/Core/Core/Sipgate/FaxScheduler.cs @@ -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: @@ -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; + } + } } \ No newline at end of file diff --git a/GUI/FaxListItem.xaml.cs b/GUI/FaxListItem.xaml.cs index ed056e5..c985833 100644 --- a/GUI/FaxListItem.xaml.cs +++ b/GUI/FaxListItem.xaml.cs @@ -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 @@ -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); } } } @@ -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) => diff --git a/GUI/Properties/Resources.Designer.cs b/GUI/Properties/Resources.Designer.cs index fe9b5a7..e3c5d61 100644 --- a/GUI/Properties/Resources.Designer.cs +++ b/GUI/Properties/Resources.Designer.cs @@ -303,6 +303,42 @@ public static string Status_Failed { } } + /// + /// Looks up a localized string similar to Recipient is busy.. + /// + public static string Status_FailedBusy { + get { + return ResourceManager.GetString("Status_FailedBusy", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Recipient is invalid.. + /// + public static string Status_FailedInvalidDestination { + get { + return ResourceManager.GetString("Status_FailedInvalidDestination", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Recipient did not pick up.. + /// + public static string Status_FailedNoPickup { + get { + return ResourceManager.GetString("Status_FailedNoPickup", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sending failed: {0}. + /// + public static string Status_FailedWithReason { + get { + return ResourceManager.GetString("Status_FailedWithReason", resourceCulture); + } + } + /// /// Looks up a localized string similar to Pending. /// diff --git a/GUI/Properties/Resources.de.Designer.cs b/GUI/Properties/Resources.de.Designer.cs index ec022e7..948c333 100644 --- a/GUI/Properties/Resources.de.Designer.cs +++ b/GUI/Properties/Resources.de.Designer.cs @@ -303,6 +303,42 @@ public static string Status_Failed { } } + /// + /// Looks up a localized string similar to Empfänger ist besetzt.. + /// + public static string Status_FailedBusy { + get { + return ResourceManager.GetString("Status_FailedBusy", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Empfänger ist ungültig.. + /// + public static string Status_FailedInvalidDestination { + get { + return ResourceManager.GetString("Status_FailedInvalidDestination", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Empfänger hat nicht abgehoben.. + /// + public static string Status_FailedNoPickup { + get { + return ResourceManager.GetString("Status_FailedNoPickup", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Senden fehlgeschlagen: {0}. + /// + public static string Status_FailedWithReason { + get { + return ResourceManager.GetString("Status_FailedWithReason", resourceCulture); + } + } + /// /// Looks up a localized string similar to Wartend. /// diff --git a/GUI/Properties/Resources.de.resx b/GUI/Properties/Resources.de.resx index d4f60af..3506c71 100644 --- a/GUI/Properties/Resources.de.resx +++ b/GUI/Properties/Resources.de.resx @@ -121,4 +121,16 @@ Die Verbindung zum Scanner-Subsystem konnte nicht geschlossen werden! Möglicherweise war der Scan trotzdem erfolgreich. + + Senden fehlgeschlagen: {0} + + + Empfänger hat nicht abgehoben. + + + Empfänger ist besetzt. + + + Empfänger ist ungültig. + \ No newline at end of file diff --git a/GUI/Properties/Resources.resx b/GUI/Properties/Resources.resx index 5d410f4..902426b 100644 --- a/GUI/Properties/Resources.resx +++ b/GUI/Properties/Resources.resx @@ -121,4 +121,16 @@ An unknown scanning related error occurred. Please report this to the developer! + + Sending failed: {0} + + + Recipient did not pick up. + + + Recipient is busy. + + + Recipient is invalid. + \ No newline at end of file