added DisconnectedEvent to CommunicationProtocol,
added handling for sent data while not connected,
introduced IContext and WpfContext to handover UI context to backend (required to add to ObservableCollection)
if(this.CommunicationProtocol==null){thrownewNullReferenceException($"'{nameof(SendToCommunicationProtocol)}()' was called but {nameof(CommunicationProtocol)} is null.");}
// inform user and quit if communication protocol is not connected
// guard is not connected => log warning. user of this function shall only use SendBytes if IsConnected is true
if(this.IsConnected==false){this.logger.LogWarn($"'{nameof(SendBytes)}()' was reached with {nameof(IsConnected)} being false",nameof(CommunicationProtocol));}
if(this.InternalSendBytes(bytes))
{
// todo implement sent bytes
// ONsentBytes()
}
else
{
this.logger.LogError($"'{nameof(SendBytes)}()' failed to send during {nameof(InternalSendBytes)}.",nameof(CommunicationProtocol));
this.messenger.Send<IUserInterfaceMessage>(newGenericUserInterfaceMessage("Failed to send message",MessageImportance.High));
}
}
/// <summary>
@ -61,6 +91,13 @@ public abstract class CommunicationProtocol : ICommunicationProtocol
publicboolConnect(IProtocolSettingssettings)
{
// check if not already connected
if(this.IsConnected==true)
{
this.logger.LogWarn($"'{nameof(Connect)}()' was reached even if {nameof(IsConnected)} is already true.",nameof(CommunicationProtocol));
returntrue;
}
// check if settings are valid, cancel if not
if(settings.AreValid()==false)
{
@ -68,7 +105,7 @@ public abstract class CommunicationProtocol : ICommunicationProtocol
returnfalse;
}
// try connecting if serttings are valid
// try connecting if settings are valid
if(this.InternalConnect(settings))
{
// renew token source
@ -76,6 +113,8 @@ public abstract class CommunicationProtocol : ICommunicationProtocol