C# Class GSF.Communication.ClientBase

Base class for a client involved in server-client communication.
Inheritance: System.ComponentModel.Component, IClient, ISupportInitialize, IPersistSettings
Afficher le fichier Open project: GridProtectionAlliance/gsf Class Usage Examples

Private Properties

Свойство Type Description
ReConnect void

Méthodes publiques

Méthode Description
BeginInit ( ) : void

Performs necessary operations before the client properties are initialized.

BeginInit() should never be called by user-code directly. This method exists solely for use by the designer if the server is consumed through the designer surface of the IDE.

Connect ( ) : void

Connects the client to the server synchronously.

ConnectAsync ( ) : WaitHandle

Connects the client to the server asynchronously.

Derived classes are expected to override this method with protocol specific connection operations. Call the base class method to obtain an operational wait handle if protocol connection operation doesn't provide one already.

Create ( string connectionString ) : IClient

Create a communications client

Note that typical connection string should be prefixed with a "protocol=tcp", "protocol=udp", "protocol=serial" or "protocol=file"

Disconnect ( ) : void

When overridden in a derived class, disconnects client from the server synchronously.

EndInit ( ) : void

Performs necessary operations after the client properties are initialized.

EndInit() should never be called by user-code directly. This method exists solely for use by the designer if the server is consumed through the designer surface of the IDE.

Initialize ( ) : void

Initializes the client.

Initialize() is to be called by user-code directly only if the client is not consumed through the designer surface of the IDE.

LoadSettings ( ) : void

Loads saved client settings from the config file if the PersistSettings property is set to true.

Read ( byte buffer, int startIndex, int length ) : int

When overridden in a derived class, reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset.

This function should only be called from within the ReceiveData event handler. Calling this method outside this event will have unexpected results.

SaveSettings ( ) : void

Saves client settings to the config file if the PersistSettings property is set to true.

Send ( byte data ) : void

Sends data to the server synchronously.

Send ( byte data, int offset, int length ) : void

Sends data to the server synchronously.

Send ( object serializableObject ) : void

Sends data to the server synchronously.

Send ( string data ) : void

Sends data to the server synchronously.

SendAsync ( byte data ) : WaitHandle

Sends data to the server asynchronously.

SendAsync ( byte data, int offset, int length ) : WaitHandle

Sends data to the server asynchronously.

SendAsync ( object serializableObject ) : WaitHandle

Sends data to the server asynchronously.

SendAsync ( string data ) : WaitHandle

Sends data to the server asynchronously.

Méthodes protégées

Méthode Description
ClientBase ( ) : System

Initializes a new instance of the client.

ClientBase ( TransportProtocol transportProtocol, string connectionString ) : System

Initializes a new instance of the client.

Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the client and optionally releases the managed resources.

OnConnectionAttempt ( ) : void

Raises the ConnectionAttempt event.

OnConnectionEstablished ( ) : void

Raises the ConnectionEstablished event.

OnConnectionException ( Exception ex ) : void

Raises the ConnectionException event.

OnConnectionTerminated ( ) : void

Raises the ConnectionTerminated event.

OnReceiveData ( int size ) : void

Raises the ReceiveData event.

This event is automatically raised by call to OnReceiveDataComplete so that inheritors never need to worry about raising this event. This method is only included here in case any custom client implementations need to explicitly raise this event.

OnReceiveDataComplete ( byte data, int size ) : void

Raises the ReceiveDataComplete event.

OnReceiveDataException ( Exception ex ) : void

Raises the ReceiveDataException event.

OnSendDataComplete ( ) : void

Raises the SendDataComplete event.

OnSendDataException ( Exception ex ) : void

Raises the SendDataException event.

OnSendDataStart ( ) : void

Raises the SendDataStart event.

OnUnhandledUserException ( Exception ex ) : void

Raises the UnhandledUserException event.

SendDataAsync ( byte data, int offset, int length ) : WaitHandle

When overridden in a derived class, sends data to the server asynchronously.

UpdateBytesReceived ( int bytes ) : void

Updates the Statistics pertaining to bytes received.

UpdateBytesSent ( int bytes ) : void

Updates the Statistics pertaining to bytes sent.

ValidateConnectionString ( string connectionString ) : void

When overridden in a derived class, validates the specified connectionString.

Private Methods

Méthode Description
ReConnect ( ) : void

Re-connects the client if currently connected.

Method Details

BeginInit() public méthode

Performs necessary operations before the client properties are initialized.
BeginInit() should never be called by user-code directly. This method exists solely for use by the designer if the server is consumed through the designer surface of the IDE.
public BeginInit ( ) : void
Résultat void

ClientBase() protected méthode

Initializes a new instance of the client.
protected ClientBase ( ) : System
Résultat System

ClientBase() protected méthode

Initializes a new instance of the client.
protected ClientBase ( TransportProtocol transportProtocol, string connectionString ) : System
transportProtocol TransportProtocol One of the values.
connectionString string The data used by the client for connection to a server.
Résultat System

Connect() public méthode

Connects the client to the server synchronously.
public Connect ( ) : void
Résultat void

ConnectAsync() public méthode

Connects the client to the server asynchronously.
Derived classes are expected to override this method with protocol specific connection operations. Call the base class method to obtain an operational wait handle if protocol connection operation doesn't provide one already.
Server property in is invalid. Attempt is made to connect the client when it is not disconnected.
public ConnectAsync ( ) : WaitHandle
Résultat System.Threading.WaitHandle

Create() public static méthode

Create a communications client
Note that typical connection string should be prefixed with a "protocol=tcp", "protocol=udp", "protocol=serial" or "protocol=file"
public static Create ( string connectionString ) : IClient
connectionString string Connection string for the client.
Résultat IClient

Disconnect() public méthode

When overridden in a derived class, disconnects client from the server synchronously.
public Disconnect ( ) : void
Résultat void

Dispose() protected méthode

Releases the unmanaged resources used by the client and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
Résultat void

EndInit() public méthode

Performs necessary operations after the client properties are initialized.
EndInit() should never be called by user-code directly. This method exists solely for use by the designer if the server is consumed through the designer surface of the IDE.
public EndInit ( ) : void
Résultat void

Initialize() public méthode

Initializes the client.
Initialize() is to be called by user-code directly only if the client is not consumed through the designer surface of the IDE.
public Initialize ( ) : void
Résultat void

LoadSettings() public méthode

Loads saved client settings from the config file if the PersistSettings property is set to true.
has a value of null or empty string.
public LoadSettings ( ) : void
Résultat void

OnConnectionAttempt() protected méthode

Raises the ConnectionAttempt event.
protected OnConnectionAttempt ( ) : void
Résultat void

OnConnectionEstablished() protected méthode

Raises the ConnectionEstablished event.
protected OnConnectionEstablished ( ) : void
Résultat void

OnConnectionException() protected méthode

Raises the ConnectionException event.
protected OnConnectionException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Résultat void

OnConnectionTerminated() protected méthode

Raises the ConnectionTerminated event.
protected OnConnectionTerminated ( ) : void
Résultat void

OnReceiveData() protected méthode

Raises the ReceiveData event.
This event is automatically raised by call to OnReceiveDataComplete so that inheritors never need to worry about raising this event. This method is only included here in case any custom client implementations need to explicitly raise this event.
protected OnReceiveData ( int size ) : void
size int Number of bytes received from the client.
Résultat void

OnReceiveDataComplete() protected méthode

Raises the ReceiveDataComplete event.
protected OnReceiveDataComplete ( byte data, int size ) : void
data byte Data received from the client.
size int Number of bytes received from the client.
Résultat void

OnReceiveDataException() protected méthode

Raises the ReceiveDataException event.
protected OnReceiveDataException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Résultat void

OnSendDataComplete() protected méthode

Raises the SendDataComplete event.
protected OnSendDataComplete ( ) : void
Résultat void

OnSendDataException() protected méthode

Raises the SendDataException event.
protected OnSendDataException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Résultat void

OnSendDataStart() protected méthode

Raises the SendDataStart event.
protected OnSendDataStart ( ) : void
Résultat void

OnUnhandledUserException() protected méthode

Raises the UnhandledUserException event.
protected OnUnhandledUserException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Résultat void

Read() public abstract méthode

When overridden in a derived class, reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset.
This function should only be called from within the ReceiveData event handler. Calling this method outside this event will have unexpected results.
public abstract Read ( byte buffer, int startIndex, int length ) : int
buffer byte Destination buffer used to hold copied bytes.
startIndex int 0-based starting index into destination to begin writing data.
length int The number of bytes to read from current received data buffer and write into .
Résultat int

SaveSettings() public méthode

Saves client settings to the config file if the PersistSettings property is set to true.
has a value of null or empty string.
public SaveSettings ( ) : void
Résultat void

Send() public méthode

Sends data to the server synchronously.
public Send ( byte data ) : void
data byte The binary data that is to be sent.
Résultat void

Send() public méthode

Sends data to the server synchronously.
public Send ( byte data, int offset, int length ) : void
data byte The buffer that contains the binary data to be sent.
offset int The zero-based position in the at which to begin sending data.
length int The number of bytes to be sent from starting at the .
Résultat void

Send() public méthode

Sends data to the server synchronously.
public Send ( object serializableObject ) : void
serializableObject object The serializable object that is to be sent.
Résultat void

Send() public méthode

Sends data to the server synchronously.
public Send ( string data ) : void
data string The plain-text data that is to be sent.
Résultat void

SendAsync() public méthode

Sends data to the server asynchronously.
public SendAsync ( byte data ) : WaitHandle
data byte The binary data that is to be sent.
Résultat System.Threading.WaitHandle

SendAsync() public méthode

Sends data to the server asynchronously.
public SendAsync ( byte data, int offset, int length ) : WaitHandle
data byte The buffer that contains the binary data to be sent.
offset int The zero-based position in the at which to begin sending data.
length int The number of bytes to be sent from starting at the .
Résultat System.Threading.WaitHandle

SendAsync() public méthode

Sends data to the server asynchronously.
public SendAsync ( object serializableObject ) : WaitHandle
serializableObject object The serializable object that is to be sent.
Résultat System.Threading.WaitHandle

SendAsync() public méthode

Sends data to the server asynchronously.
public SendAsync ( string data ) : WaitHandle
data string The plain-text data that is to be sent.
Résultat System.Threading.WaitHandle

SendDataAsync() protected abstract méthode

When overridden in a derived class, sends data to the server asynchronously.
protected abstract SendDataAsync ( byte data, int offset, int length ) : WaitHandle
data byte The buffer that contains the binary data to be sent.
offset int The zero-based position in the at which to begin sending data.
length int The number of bytes to be sent from starting at the .
Résultat System.Threading.WaitHandle

UpdateBytesReceived() protected méthode

Updates the Statistics pertaining to bytes received.
protected UpdateBytesReceived ( int bytes ) : void
bytes int
Résultat void

UpdateBytesSent() protected méthode

Updates the Statistics pertaining to bytes sent.
protected UpdateBytesSent ( int bytes ) : void
bytes int
Résultat void

ValidateConnectionString() protected abstract méthode

When overridden in a derived class, validates the specified connectionString.
protected abstract ValidateConnectionString ( string connectionString ) : void
connectionString string The connection string to be validated.
Résultat void