Messages, Notifications, Log, Exceptions, Translation

Translation guideline

xMessgeBox.Show and LoggerSink.PushMessage go through l.Translate with success only if they contain strings without parameters.

Any parameter requires an explicit call of l.Translate (which is similar to a string.format command).

Exceptions and messages with arguments need l.Translate.

throw new Exception(l.Translate("Mehrwertsteuer Array konnte nicht berechnet werden."));
xMessageBox.Show(l.Translate("Gebinde nicht vorhanden),....);

Yes/No

answer = xMessageBox.Show(l.Translate("Gebinde nicht vorhanden. Soll es erstellt werden?"), "Abfrage", MessageBoxButton.YesNo);
if (answer == MessageBoxResult.Yes)
{
    //Create container
    this.CreateGebinde(gebindeNr);
    return;
}

LoggerSink

LoggerSink.PushMessage(this, "Speichern erfolgreich.", Severity.Confirmation);
LoggerSink [deprecated]

Exceptions

If more than a Message (a string) is needed after an exception occurred, we can use custom exceptions.

Example for creating such an exception:

public class SchichtplanSaveException : Exception
{
    public DataRow faultyRow;

    public SchichtplanSaveException() { }

    public SchichtplanSaveException(string message) : base(message) { }

    public SchichtplanSaveException(string message, DataRow row) : base(message) { faultyRow = row; }

    public SchichtplanSaveException(string message, Exception inner) : base(message, inner) { }
}

Handling the exception:

public override int OnPreSave()
{
    try 
    {
        BusObj.SaveTest();
    }
    catch (SchichtplanSaveException ex)
    {                
        xMessageBox.ShowException(ex, "Speichern abgebrochen.");
        if (ex.faultyRow != null) dxgSchichtplanPos.SelectedRow = ex.faultyRow;
        return -1;
    }

    return base.OnPreSave();
}

Last updated