C# Класс GSF.Communication.ClientBase

Base class for a client involved in server-client communication.
Наследование: System.ComponentModel.Component, IClient, ISupportInitialize, IPersistSettings
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
ReConnect void

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
ReConnect ( ) : void

Re-connects the client if currently connected.

Описание методов

BeginInit() публичный Метод

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
Результат void

ClientBase() защищенный Метод

Initializes a new instance of the client.
protected ClientBase ( ) : System
Результат System

ClientBase() защищенный Метод

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.
Результат System

Connect() публичный Метод

Connects the client to the server synchronously.
public Connect ( ) : void
Результат void

ConnectAsync() публичный Метод

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
Результат System.Threading.WaitHandle

Create() публичный статический Метод

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.
Результат IClient

Disconnect() публичный Метод

When overridden in a derived class, disconnects client from the server synchronously.
public Disconnect ( ) : void
Результат void

Dispose() защищенный Метод

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.
Результат void

EndInit() публичный Метод

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
Результат void

Initialize() публичный Метод

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
Результат void

LoadSettings() публичный Метод

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
Результат void

OnConnectionAttempt() защищенный Метод

Raises the ConnectionAttempt event.
protected OnConnectionAttempt ( ) : void
Результат void

OnConnectionEstablished() защищенный Метод

Raises the ConnectionEstablished event.
protected OnConnectionEstablished ( ) : void
Результат void

OnConnectionException() защищенный Метод

Raises the ConnectionException event.
protected OnConnectionException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Результат void

OnConnectionTerminated() защищенный Метод

Raises the ConnectionTerminated event.
protected OnConnectionTerminated ( ) : void
Результат void

OnReceiveData() защищенный Метод

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.
Результат void

OnReceiveDataComplete() защищенный Метод

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.
Результат void

OnReceiveDataException() защищенный Метод

Raises the ReceiveDataException event.
protected OnReceiveDataException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Результат void

OnSendDataComplete() защищенный Метод

Raises the SendDataComplete event.
protected OnSendDataComplete ( ) : void
Результат void

OnSendDataException() защищенный Метод

Raises the SendDataException event.
protected OnSendDataException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Результат void

OnSendDataStart() защищенный Метод

Raises the SendDataStart event.
protected OnSendDataStart ( ) : void
Результат void

OnUnhandledUserException() защищенный Метод

Raises the UnhandledUserException event.
protected OnUnhandledUserException ( Exception ex ) : void
ex System.Exception Exception to send to event.
Результат void

Read() публичный абстрактный Метод

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 .
Результат int

SaveSettings() публичный Метод

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
Результат void

Send() публичный Метод

Sends data to the server synchronously.
public Send ( byte data ) : void
data byte The binary data that is to be sent.
Результат void

Send() публичный Метод

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 .
Результат void

Send() публичный Метод

Sends data to the server synchronously.
public Send ( object serializableObject ) : void
serializableObject object The serializable object that is to be sent.
Результат void

Send() публичный Метод

Sends data to the server synchronously.
public Send ( string data ) : void
data string The plain-text data that is to be sent.
Результат void

SendAsync() публичный Метод

Sends data to the server asynchronously.
public SendAsync ( byte data ) : WaitHandle
data byte The binary data that is to be sent.
Результат System.Threading.WaitHandle

SendAsync() публичный Метод

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 .
Результат System.Threading.WaitHandle

SendAsync() публичный Метод

Sends data to the server asynchronously.
public SendAsync ( object serializableObject ) : WaitHandle
serializableObject object The serializable object that is to be sent.
Результат System.Threading.WaitHandle

SendAsync() публичный Метод

Sends data to the server asynchronously.
public SendAsync ( string data ) : WaitHandle
data string The plain-text data that is to be sent.
Результат System.Threading.WaitHandle

SendDataAsync() защищенный абстрактный Метод

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 .
Результат System.Threading.WaitHandle

UpdateBytesReceived() защищенный Метод

Updates the Statistics pertaining to bytes received.
protected UpdateBytesReceived ( int bytes ) : void
bytes int
Результат void

UpdateBytesSent() защищенный Метод

Updates the Statistics pertaining to bytes sent.
protected UpdateBytesSent ( int bytes ) : void
bytes int
Результат void

ValidateConnectionString() защищенный абстрактный Метод

When overridden in a derived class, validates the specified connectionString.
protected abstract ValidateConnectionString ( string connectionString ) : void
connectionString string The connection string to be validated.
Результат void