using System; using System.Text; namespace Swan.Net { /// /// The event arguments for connection failure events. /// /// public class ConnectionFailureEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The ex. public ConnectionFailureEventArgs(Exception ex) => this.Error = ex; /// /// Gets the error. /// /// /// The error. /// public Exception Error { get; } } /// /// Event arguments for when data is received. /// /// public class ConnectionDataReceivedEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The buffer. /// The trigger. /// if set to true [more available]. public ConnectionDataReceivedEventArgs(Byte[] buffer, ConnectionDataReceivedTrigger trigger, Boolean moreAvailable) { this.Buffer = buffer ?? throw new ArgumentNullException(nameof(buffer)); this.Trigger = trigger; this.HasMoreAvailable = moreAvailable; } /// /// Gets the buffer. /// /// /// The buffer. /// public Byte[] Buffer { get; } /// /// Gets the cause as to why this event was thrown. /// /// /// The trigger. /// public ConnectionDataReceivedTrigger Trigger { get; } /// /// Gets a value indicating whether the receive buffer has more bytes available. /// /// /// true if this instance has more available; otherwise, false. /// public Boolean HasMoreAvailable { get; } /// /// Gets the string from buffer. /// /// The encoding. /// /// A that contains the results of decoding the specified sequence of bytes. /// /// encoding public String GetStringFromBuffer(Encoding encoding) => encoding?.GetString(this.Buffer).TrimEnd('\r', '\n') ?? throw new ArgumentNullException(nameof(encoding)); } }