mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
refactored some protocol base events to standardize how disconnect/error events are raised
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Connection.Protocol.RDP;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Messages;
|
||||
using mRemoteNG.UI.Forms;
|
||||
@@ -204,25 +203,27 @@ namespace mRemoteNG.Connection
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
private static void Prot_Event_Disconnected(object sender, string disconnectedMessage)
|
||||
private static void Prot_Event_Disconnected(object sender, string disconnectedMessage, int? reasonCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sender is VncSharp.RemoteDesktop)
|
||||
var prot = (ProtocolBase)sender;
|
||||
var msgClass = MessageClass.InformationMsg;
|
||||
|
||||
if (prot.InterfaceControl.Info.Protocol == ProtocolType.RDP)
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strProtocolEventDisconnected, @"VncSharp Disconnected."), true);
|
||||
return;
|
||||
if (reasonCode > 3)
|
||||
{
|
||||
msgClass = MessageClass.WarningMsg;
|
||||
}
|
||||
}
|
||||
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strProtocolEventDisconnected, disconnectedMessage), true);
|
||||
|
||||
var prot = (ProtocolBase)sender;
|
||||
if (prot.InterfaceControl.Info.Protocol != ProtocolType.RDP) return;
|
||||
var reasonCode = disconnectedMessage.Split("\r\n".ToCharArray())[0];
|
||||
var desc = disconnectedMessage.Replace("\r\n", " ");
|
||||
|
||||
if (Convert.ToInt32(reasonCode) > 3)
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strRdpDisconnected + Environment.NewLine + desc);
|
||||
Runtime.MessageCollector.AddMessage(msgClass,
|
||||
string.Format(
|
||||
Language.strProtocolEventDisconnected,
|
||||
disconnectedMessage,
|
||||
prot.InterfaceControl.Info.Hostname,
|
||||
prot.InterfaceControl.Info.Protocol.ToString()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -266,16 +267,18 @@ namespace mRemoteNG.Connection
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strConnectionEventConnectedDetail, prot.InterfaceControl.Info.Hostname, prot.InterfaceControl.Info.Protocol, Environment.UserName, prot.InterfaceControl.Info.Description, prot.InterfaceControl.Info.UserField));
|
||||
}
|
||||
|
||||
private static void Prot_Event_ErrorOccured(object sender, string errorMessage)
|
||||
private static void Prot_Event_ErrorOccured(object sender, string errorMessage, int? errorCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnectionEventErrorOccured, true);
|
||||
var prot = (ProtocolBase)sender;
|
||||
var prot = (ProtocolBase) sender;
|
||||
|
||||
if (prot.InterfaceControl.Info.Protocol != ProtocolType.RDP) return;
|
||||
if (Convert.ToInt32(errorMessage) > -1)
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, string.Format(Language.strConnectionRdpErrorDetail, errorMessage, RdpErrorCodes.GetError(errorMessage)));
|
||||
var msg = string.Format(
|
||||
Language.strConnectionEventErrorOccured,
|
||||
errorMessage,
|
||||
prot.InterfaceControl.Info.Hostname,
|
||||
errorCode?.ToString() ?? "-");
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, msg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -285,12 +285,12 @@ namespace mRemoteNG.Connection.Protocol.ICA
|
||||
|
||||
private void ICAEvent_OnConnectFailed(object sender, EventArgs e)
|
||||
{
|
||||
Event_ErrorOccured(this, e.ToString());
|
||||
Event_ErrorOccured(this, e.ToString(), null);
|
||||
}
|
||||
|
||||
private void ICAEvent_OnDisconnect(object sender, EventArgs e)
|
||||
{
|
||||
Event_Disconnected(this, e.ToString());
|
||||
Event_Disconnected(this, e.ToString(), null);
|
||||
|
||||
if (Settings.Default.ReconnectOnDisconnect)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Tools;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Tools;
|
||||
|
||||
|
||||
namespace mRemoteNG.Connection.Protocol
|
||||
{
|
||||
public abstract class ProtocolBase
|
||||
public abstract class ProtocolBase
|
||||
{
|
||||
#region Private Variables
|
||||
|
||||
@@ -239,14 +239,14 @@ namespace mRemoteNG.Connection.Protocol
|
||||
remove { ConnectedEvent = (ConnectedEventHandler) Delegate.Remove(ConnectedEvent, value); }
|
||||
}
|
||||
|
||||
public delegate void DisconnectedEventHandler(object sender, string DisconnectedMessage);
|
||||
public delegate void DisconnectedEventHandler(object sender, string disconnectedMessage, int? reasonCode);
|
||||
public event DisconnectedEventHandler Disconnected
|
||||
{
|
||||
add { DisconnectedEvent = (DisconnectedEventHandler) Delegate.Combine(DisconnectedEvent, value); }
|
||||
remove { DisconnectedEvent = (DisconnectedEventHandler) Delegate.Remove(DisconnectedEvent, value); }
|
||||
}
|
||||
|
||||
public delegate void ErrorOccuredEventHandler(object sender, string ErrorMessage);
|
||||
public delegate void ErrorOccuredEventHandler(object sender, string errorMessage, int? errorCode);
|
||||
public event ErrorOccuredEventHandler ErrorOccured
|
||||
{
|
||||
add { ErrorOccuredEvent = (ErrorOccuredEventHandler) Delegate.Combine(ErrorOccuredEvent, value); }
|
||||
@@ -288,14 +288,14 @@ namespace mRemoteNG.Connection.Protocol
|
||||
ConnectedEvent?.Invoke(sender);
|
||||
}
|
||||
|
||||
protected void Event_Disconnected(object sender, string DisconnectedMessage)
|
||||
protected void Event_Disconnected(object sender, string disconnectedMessage, int? reasonCode)
|
||||
{
|
||||
DisconnectedEvent?.Invoke(sender, DisconnectedMessage);
|
||||
DisconnectedEvent?.Invoke(sender, disconnectedMessage, reasonCode);
|
||||
}
|
||||
|
||||
protected void Event_ErrorOccured(object sender, string ErrorMsg)
|
||||
protected void Event_ErrorOccured(object sender, string errorMsg, int? errorCode)
|
||||
{
|
||||
ErrorOccuredEvent?.Invoke(sender, ErrorMsg);
|
||||
ErrorOccuredEvent?.Invoke(sender, errorMsg, errorCode);
|
||||
}
|
||||
|
||||
protected void Event_ReconnectGroupCloseClicked()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using mRemoteNG.App;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using mRemoteNG.App;
|
||||
|
||||
namespace mRemoteNG.Connection.Protocol.RDP
|
||||
{
|
||||
@@ -12,19 +12,19 @@ namespace mRemoteNG.Connection.Protocol.RDP
|
||||
{
|
||||
_description = new Hashtable
|
||||
{
|
||||
{"0", "Language.strRdpErrorUnknown"},
|
||||
{"1", "Language.strRdpErrorCode1"},
|
||||
{"2", "Language.strRdpErrorOutOfMemory"},
|
||||
{"3", "Language.strRdpErrorWindowCreation"},
|
||||
{"4", "Language.strRdpErrorCode2"},
|
||||
{"5", "Language.strRdpErrorCode3"},
|
||||
{"6", "Language.strRdpErrorCode4"},
|
||||
{"7", "Language.strRdpErrorConnection"},
|
||||
{"100", "Language.strRdpErrorWinsock"}
|
||||
{ 0, "Language.strRdpErrorUnknown"},
|
||||
{ 1, "Language.strRdpErrorCode1"},
|
||||
{ 2, "Language.strRdpErrorOutOfMemory"},
|
||||
{ 3, "Language.strRdpErrorWindowCreation"},
|
||||
{ 4, "Language.strRdpErrorCode2"},
|
||||
{ 5, "Language.strRdpErrorCode3"},
|
||||
{ 6, "Language.strRdpErrorCode4"},
|
||||
{ 7, "Language.strRdpErrorConnection"},
|
||||
{ 100, "Language.strRdpErrorWinsock"}
|
||||
};
|
||||
}
|
||||
|
||||
public static string GetError(string id)
|
||||
public static string GetError(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -690,8 +690,9 @@ namespace mRemoteNG.Connection.Protocol.RDP
|
||||
|
||||
|
||||
private void RDPEvent_OnFatalError(int errorCode)
|
||||
{
|
||||
Event_ErrorOccured(this, Convert.ToString(errorCode));
|
||||
{
|
||||
var errorMsg = RdpErrorCodes.GetError(errorCode);
|
||||
Event_ErrorOccured(this, errorMsg, errorCode);
|
||||
}
|
||||
|
||||
private void RDPEvent_OnDisconnected(int discReason)
|
||||
@@ -700,7 +701,7 @@ namespace mRemoteNG.Connection.Protocol.RDP
|
||||
if (discReason != UI_ERR_NORMAL_DISCONNECT)
|
||||
{
|
||||
var reason = _rdpClient.GetErrorDescription((uint)discReason, (uint) _rdpClient.ExtendedDisconnectReason);
|
||||
Event_Disconnected(this, discReason + "\r\n" + reason);
|
||||
Event_Disconnected(this, reason, discReason);
|
||||
}
|
||||
|
||||
if (Settings.Default.ReconnectOnDisconnect)
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace mRemoteNG.Connection.Protocol.VNC
|
||||
private void VNCEvent_Disconnected(object sender, EventArgs e)
|
||||
{
|
||||
FrmMain.ClipboardChanged -= VNCEvent_ClipboardChanged;
|
||||
Event_Disconnected(sender, e.ToString());
|
||||
Event_Disconnected(sender, @"VncSharp Disconnected.", null);
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1473,7 +1473,7 @@ namespace mRemoteNG {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Protocol Event ErrorOccured.
|
||||
/// Looks up a localized string similar to A connection protocol error occurred. Host: "{1}"; Error code: "{2}"; Error Description: "{0}".
|
||||
/// </summary>
|
||||
internal static string strConnectionEventErrorOccured {
|
||||
get {
|
||||
@@ -5551,9 +5551,7 @@ namespace mRemoteNG {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Protocol Event Disconnected.
|
||||
///Message:
|
||||
///{0}.
|
||||
/// Looks up a localized string similar to Protocol Event Disconnected. Host: "{1}"; Protocol: "{2}" Message: "{0}".
|
||||
/// </summary>
|
||||
internal static string strProtocolEventDisconnected {
|
||||
get {
|
||||
|
||||
@@ -508,7 +508,7 @@ VncSharp Control Version {0}</value>
|
||||
<value>Connection failed!</value>
|
||||
</data>
|
||||
<data name="strConnectionEventErrorOccured" xml:space="preserve">
|
||||
<value>Protocol Event ErrorOccured</value>
|
||||
<value>A connection protocol error occurred. Host: "{1}"; Error code: "{2}"; Error Description: "{0}"</value>
|
||||
</data>
|
||||
<data name="strConnectionOpenFailed" xml:space="preserve">
|
||||
<value>Opening connection failed!</value>
|
||||
@@ -1683,9 +1683,7 @@ If you run into such an error, please create a new connection file!</value>
|
||||
<value>Proxy Username</value>
|
||||
</data>
|
||||
<data name="strProtocolEventDisconnected" xml:space="preserve">
|
||||
<value>Protocol Event Disconnected.
|
||||
Message:
|
||||
{0}</value>
|
||||
<value>Protocol Event Disconnected. Host: "{1}"; Protocol: "{2}" Message: "{0}"</value>
|
||||
</data>
|
||||
<data name="strProtocolEventDisconnectFailed" xml:space="preserve">
|
||||
<value>Protocol Event Disconnected failed.
|
||||
|
||||
Reference in New Issue
Block a user