See Also

Dart.PowerTCP.EmailValidation Namespace

Requirements

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)

Language

Visual Basic

C#

C++

C++/CLI

Show All

sender
The source of the event.
e
A SegmentEventArgs object that contains the event data.
See Also Requirements Languages PowerTCP Email Validation for .NET

SegmentEventHandler Delegate

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 )

Parameters

sender
The source of the event.
e
A SegmentEventArgs object that contains the event data.

Remarks

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:

When sending or receiving data, the class that holds the event data is the SegmentEventArgs class. A method must be created with the same signature as the delegate. In this example that would mean a method would have to be defined to accept two arguments (an object and a SegmentEventArgs) and return void. Once this has been done, the delegate must be "connected" to the handling event. This is done by adding an instance of the delegate to the event.

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.

Example

The following example demonstrates using the Log event to create a text log of all data sent over the control connection.

[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 &lt;-- \r\n");
   
byte[] sent = System.Text.ASCIIEncoding.ASCII.GetBytes("\r\nSent --&gt; \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();
                

Requirements

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)

See Also

Dart.PowerTCP.EmailValidation Namespace


Send comments on this topic.

Documentation version 1.0.3.0.

© 2008 Dart Communications.  All rights reserved.