Dart.PowerTCP.EmailValidation Namespace : SegmentEventHandler Delegate |
Represents the method (event handler) that is raised when data is received or sent.
[Visual Basic]
Public Delegate Sub SegmentEventHandler( _
ByVal sender As Object, _
ByVal e As SegmentEventArgs _
)
[C#]
public delegate void SegmentEventHandler(
object sender,
SegmentEventArgs e
);
[C++]
public: __gc __delegate void SegmentEventHandler(
Object* sender,
SegmentEventArgs* e
)
[C++/CLI]
public delegate void SegmentEventHandler(
Object^ sender,
SegmentEventArgs^ e
)
As Microsoft describes in their MSDN documentation, the event model in the .NET Framework is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:
For more information about event handler delegates, see the Using Events in PowerTCP topic.
If your code causes an exception, it would be returned to the handling event without you seeing it. To preclude such a condition, you should ALWAYS use a try/ catch block around your event-handling code.
[Visual Basic]
' The Trace Event will fire whenever data is sent/received over the control connection.
Private Sub Ftp1_Log(ByVal sender As Object, ByVal e As Dart.PowerTCP.Ftp.SegmentEventArgs) Handles Ftp1.Log
' Create FileStream to write to log file
Dim stream1 As New System.IO.FileStream("c:\FtpTest\mylog.log", IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
' Create text to precede sent/received data.
Dim recv() As Byte = System.Text.Encoding.ASCII.GetBytes(vbCrLf + "Received <--" + vbCrLf)
Dim sent() As Byte = System.Text.Encoding.ASCII.GetBytes(vbCrLf + "Sent -->" + vbCrLf)
' Set the stream position to append.
stream1.Position = stream1.Length
' Check if data is incoming or outgoing and write appropriate data
If e.Segment.Sent = True Then
stream1.Write(sent, 0, sent.Length)
Else
stream1.Write(recv, 0, recv.Length)
End If
' Write the data
stream1.Write(e.Segment.Buffer, e.Segment.Offset, e.Segment.Count)
' Close the stream
stream1.Close()
End Sub
[C#]
// The Trace Event will fire whenever data is sent/received.
private void Ftp1_Trace(object
sender, Dart.PowerTCP.Ftp.SegmentEventArgs e)
{
// Create FileStream to write to log file
System.IO.FileStream stream1 = new System.IO.FileStream("c:\\FtpTest\\log.txt", System.IO.FileMode.OpenOrCreate,
System.IO.FileAccess.ReadWrite);
// Create text to precede sent/received data.
byte[] recv = System.Text.ASCIIEncoding.ASCII.GetBytes("\r\nReceived <-- \r\n");
byte[] sent = System.Text.ASCIIEncoding.ASCII.GetBytes("\r\nSent --> \r\n");
// Set the stream position to append.
stream1.Position = stream1.Length;
// Check if data is incoming or outgoing and write appropriate data
if(e.Segment.Sent == true)
stream1.Write(sent, 0, sent.Length);
else
stream1.Write(recv, 0, recv.Length);
// Write the data
stream1.Write(e.Segment.Buffer, e.Segment.Offset, e.Segment.Count);
// Close the stream
stream1.Close();
Namespace: Dart.PowerTCP.EmailValidation
Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista
Assembly: Dart.PowerTCP.EmailValidation (in Dart.PowerTCP.EmailValidation.dll)
Dart.PowerTCP.EmailValidation Namespace
Send comments on this topic.
Documentation version 1.0.3.0.
© 2008 Dart Communications. All rights reserved.