Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
- Rewritten IrcConnect class (now called IrcClient) to prevent Race conditions!
- Added timeout warnings.
- Added support for TLS/SSL
- Added better error handeling using the error codes from RFC 1459 IRC Protocol
- Added full support for receiving and sending to seperate channels
- Added comments and changed names to fit C# code convention
- Under the hood DCC fixes for more stability and error handeling when downloads go wrong
- **Changed Action based callback methods to Event handlers**

Should fix issue: #9
  • Loading branch information
Eldin Zenderink committed May 21, 2018
1 parent fcd826c commit 8978448
Show file tree
Hide file tree
Showing 26 changed files with 3,173 additions and 1,546 deletions.
103 changes: 91 additions & 12 deletions FormExample/DebugForm.Designer.cs

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

135 changes: 118 additions & 17 deletions FormExample/DebugForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,151 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SimpleIRCLib;

namespace FormExample
{
public partial class DebugForm : Form
{

public DebugForm()
private readonly SimpleIRC _simpleIrc;

/// <summary>
/// Constructor for the debug form.
/// </summary>
/// <param name="irc">SimpleIRC instance</param>
public DebugForm(SimpleIRC irc)
{
_simpleIrc = irc;
InitializeComponent();
}

private void ClearButton_Click(object sender, EventArgs e)
/// <summary>
/// Clears a specific rich textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void ClearButton_Click(object sender, EventArgs e)
{
DebugOutput.Clear();
RichTextBox selectedRtb = (RichTextBox)debugTabs.SelectedTab.Controls[0];
selectedRtb.Clear();
}

/// <summary>
/// Appends debug messages from irc client to debug richtextbox output box.
/// Invoke is needed because this method executes on a different thread!
/// Makes sure that the form doesn't actually close, but hides instead, so debug messages can still be appended!
/// </summary>
/// <param name="debugMessage">defines the message to be appended to the debug richtextbox output box</param>
public void AppendToDebugOutput(string debugMessage)
/// <param name="sender"></param>
/// <param name="e"></param>
public void DebugForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.DebugOutput.InvokeRequired)
if (e.CloseReason == CloseReason.UserClosing)
{
this.DebugOutput.Invoke(new MethodInvoker(() => AppendToDebugOutput(debugMessage)));
e.Cancel = true;
Hide();
}
}

/// <summary>
/// Register event handlers for the IrcClient and DCCClient when the form loads.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void DebugForm_Load(object sender, EventArgs e)
{
_simpleIrc.IrcClient.OnDebugMessage += OnIrcDebugMessage;
_simpleIrc.IrcClient.OnRawMessageReceived += OnRawMessageReceived;
_simpleIrc.DccClient.OnDccDebugMessage += OnDccDebugMessage;
}

/// <summary>
/// Event for receiving debug messages from the IrcClient
/// </summary>
/// <param name="source">source class</param>
/// <param name="args">IrcDebugMessageEventArgs contains debug message and type</param>
public void OnIrcDebugMessage(object source, IrcDebugMessageEventArgs args)
{
OnIrcDebugMessageLocal(args.Type, args.Message);
}

/// <summary>
/// For appending the debug message on the main thread using invoke required.
/// </summary>
/// <param name="type">Debug message type, handy for figuring out where the debug message came from</param>
/// <param name="message">message to append to the rich textbox</param>
public void OnIrcDebugMessageLocal(string type, string message)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => OnIrcDebugMessageLocal(type, message)));
}
else
{
this.DebugOutput.AppendText(debugMessage + "\n");
if (debugTabs != null)
{
RichTextBox selectedRtb = (RichTextBox)debugTabs.TabPages[0].Controls[0];
selectedRtb.AppendText(type + " | " + message + Environment.NewLine);
}
}
}

/// <summary>
/// Makes sure that the form doesn't actually close, but hides instead, so debug messages can still be appended!
/// Event for receiving raw messages from the irc server.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DebugForm_FormClosing(object sender, FormClosingEventArgs e)
/// <param name="source">source class</param>
/// <param name="args">IrcRawReceivedEventArgs contains the message received</param>
public void OnRawMessageReceived(object source, IrcRawReceivedEventArgs args)
{
if (e.CloseReason == CloseReason.UserClosing)
OnRawMessageReceivedLocal(args.Message);
}

/// <summary>
/// For appending the rawmessage on the main thread using invoke required.
/// </summary>
/// <param name="message">message to append to the rich textbox</param>
public void OnRawMessageReceivedLocal(string message)
{
if (this.InvokeRequired)
{
e.Cancel = true;
Hide();
this.Invoke(new MethodInvoker(() => OnRawMessageReceivedLocal(message)));
}
else
{
if (debugTabs != null)
{
RichTextBox selectedRtb = (RichTextBox) debugTabs.TabPages[2].Controls[0];
selectedRtb.AppendText(message + Environment.NewLine);
}
}
}

/// <summary>
/// Event for receiving debug messages from the DccClient
/// </summary>
/// <param name="source">source class</param>
/// <param name="args">DCCDebugMessageArgs contains the debug message and type</param>
public void OnDccDebugMessage(object source, DCCDebugMessageArgs args)
{
OnDccDebugMessageLocal(args.Type, args.Message);
}

/// <summary>
/// For appending the debug message on the main thread using invoke required.
/// </summary>
/// <param name="type">Debug message type, handy for figuring out where the debug message came from</param>
/// <param name="message">message to append to the rich textbox</param>
public void OnDccDebugMessageLocal(string type, string message)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => OnDccDebugMessageLocal(type, message)));
}
else
{
if (debugTabs != null)
{
RichTextBox selectedRtb = (RichTextBox) debugTabs.TabPages[1].Controls[0];
selectedRtb.AppendText(type + " | " + message + Environment.NewLine);
}
}
}
}
Expand Down
Loading

0 comments on commit 8978448

Please sign in to comment.