Click or drag to resize

FileClient Class

Represents a communication client based on FileStream.
Inheritance Hierarchy
SystemObject
  SystemMarshalByRefObject
    System.ComponentModelComponent
      GSF.CommunicationClientBase
        GSF.CommunicationFileClient

Namespace: GSF.Communication
Assembly: GSF.Communication (in GSF.Communication.dll) Version: 2.4.205-beta
Syntax
public class FileClient : ClientBase
View Source

The FileClient type exposes the following members.

Constructors
 NameDescription
Public methodFileClient Initializes a new instance of the FileClient class.
Public methodFileClient(IContainer) Initializes a new instance of the FileClient class.
Public methodFileClient(String) Initializes a new instance of the FileClient class.
Top
Properties
 NameDescription
Public propertyAtEOF Gets flags that determines if FileClient is positioned at the end of file.
Public propertyAutoRepeat Gets or sets a boolean value that indicates whether receiving (reading) of data is to be repeated endlessly.
Protected propertyCanRaiseEventsGets a value indicating whether the component can raise an event.
(Inherited from Component)
Public propertyClient Gets the FileStream object for the FileClient.
Public propertyConnectionString Gets or sets the data required by the client to connect to the server.
(Inherited from ClientBase)
Public propertyConnectionTime Gets the Time for which the client has been connected to the server.
(Inherited from ClientBase)
Public propertyContainerGets the IContainer that contains the Component.
(Inherited from Component)
Public propertyCurrentState Gets the current ClientState.
(Inherited from ClientBase)
Protected propertyDesignModeGets a value that indicates whether the Component is currently in design mode.
(Inherited from Component)
Public propertyDisconnectAtEOF Gets or sets flag that determines if client should disconnect when end of file has been reached.
Public propertyEnabled Gets or sets a boolean value that indicates whether the client is currently enabled.
(Inherited from ClientBase)
Protected propertyEventsGets the list of event handlers that are attached to this Component.
(Inherited from Component)
Public propertyFileAccessMode Gets or sets the FileAccess value to be used when opening the file.
Public propertyFileOpenMode Gets or sets the FileMode value to be used when opening the file.
Public propertyFileShareMode Gets or set the FileShare value to be used when opening the file.
Public propertyIsDisposed Gets a flag that indicates whether the object has been disposed.
(Inherited from ClientBase)
Public propertyMaxConnectionAttempts Gets or sets the maximum number of times the client will attempt to connect to the server.
(Inherited from ClientBase)
Public propertyName Gets the unique identifier of the client.
(Inherited from ClientBase)
Public propertyPersistSettings Gets or sets a boolean value that indicates whether the client settings are to be saved to the config file.
(Inherited from ClientBase)
Protected propertyReadIndex Gets or sets current read index for received data buffer incremented at each Read(Byte, Int32, Int32) call.
(Inherited from ClientBase)
Public propertyReceiveBufferSize Gets or sets the size of the buffer used by the client for receiving data from the server.
(Inherited from ClientBase)
Public propertyReceiveInterval Gets or sets the number of milliseconds to pause before receiving (reading) the next available set of data.
Public propertyReceiveOnDemand Gets or sets a boolean value that indicates whether receiving (reading) of data will be initiated manually by calling ReadNextBuffer.
Public propertySendBufferSize Gets or sets the size of the buffer used by the client for sending data to the server.
(Inherited from ClientBase)
Public propertyServerIndex Gets the current server index, when multiple server end points are defined.
(Inherited from ClientBase)
Public propertyServerUri Gets the server URI of the FileClient.
(Overrides ClientBaseServerUri)
Public propertySettingsCategory Gets or sets the category under which the client settings are to be saved to the config file if the PersistSettings property is set to true.
(Inherited from ClientBase)
Public propertySiteGets or sets the ISite of the Component.
(Inherited from Component)
Public propertyStartingOffset Gets or sets the starting point relative to the beginning of the file from where the data is to be received (read).
Public propertyStatistics Gets the TransportStatistics for the client connection.
(Inherited from ClientBase)
Public propertyStatus Gets the descriptive status of the client.
(Inherited from ClientBase)
Public propertyTextEncoding Gets or sets the Encoding to be used for the text sent to the server.
(Inherited from ClientBase)
Protected propertyTrackStatistics Determines whether the base class should track statistics.
(Inherited from ClientBase)
Public propertyTransportProtocol Gets the TransportProtocol used by the client for the transportation of data with the server.
(Inherited from ClientBase)
Top
Methods
 NameDescription
Public methodBeginInit Performs necessary operations before the client properties are initialized.
(Inherited from ClientBase)
Public methodConnect Connects the client to the server synchronously.
(Inherited from ClientBase)
Public methodConnectAsync Connects the FileClient to the FileStream asynchronously.
(Overrides ClientBaseConnectAsync)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject)
Public methodDisconnect Disconnects the FileClient from the FileStream.
(Overrides ClientBaseDisconnect)
Public methodDisposeReleases all resources used by the Component.
(Inherited from Component)
Protected methodDispose(Boolean) Releases the unmanaged resources used by the FileClient and optionally releases the managed resources.
(Overrides ClientBaseDispose(Boolean))
Public methodEndInit Performs necessary operations after the client properties are initialized.
(Inherited from ClientBase)
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.
(Inherited from Component)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Protected methodGetServiceReturns an object that represents a service provided by the Component or by its Container.
(Inherited from Component)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodInitialize Initializes the client.
(Inherited from ClientBase)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Public methodLoadSettings Loads saved FileClient settings from the config file if the PersistSettings property is set to true.
(Overrides ClientBaseLoadSettings)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject)
Protected methodOnConnectionAttempt Raises the ConnectionAttempt event.
(Inherited from ClientBase)
Protected methodOnConnectionEstablished Raises the ConnectionEstablished event.
(Inherited from ClientBase)
Protected methodOnConnectionException Raises the ConnectionException event.
(Overrides ClientBaseOnConnectionException(Exception))
Protected methodOnConnectionTerminated Raises the ConnectionTerminated event.
(Inherited from ClientBase)
Protected methodOnEndOfFile Raises the EndOfFile event.
Protected methodOnReceiveData Raises the ReceiveData event.
(Inherited from ClientBase)
Protected methodOnReceiveDataComplete Raises the ReceiveDataComplete event.
(Inherited from ClientBase)
Protected methodOnReceiveDataException Raises the ReceiveDataException event.
(Inherited from ClientBase)
Protected methodOnSendDataComplete Raises the SendDataComplete event.
(Inherited from ClientBase)
Protected methodOnSendDataException Raises the SendDataException event.
(Inherited from ClientBase)
Protected methodOnSendDataStart Raises the SendDataStart event.
(Inherited from ClientBase)
Protected methodOnUnhandledUserException Raises the UnhandledUserException event.
(Inherited from ClientBase)
Public methodRead Reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset.
(Overrides ClientBaseRead(Byte, Int32, Int32))
Public methodReadNextBuffer Reads next data buffer from the FileStream.
Public methodRequestNextServerIndex Requests that the client attempt to move to the next ServerIndex.
(Inherited from ClientBase)
Public methodSaveSettings Saves FileClient settings to the config file if the PersistSettings property is set to true.
(Overrides ClientBaseSaveSettings)
Public methodSend(Byte) Sends data to the server synchronously.
(Inherited from ClientBase)
Public methodSend(Object) Sends data to the server synchronously.
(Inherited from ClientBase)
Public methodSend(String) Sends data to the server synchronously.
(Inherited from ClientBase)
Public methodSend(Byte, Int32, Int32) Sends data to the server synchronously.
(Inherited from ClientBase)
Public methodSendAsync(Byte) Sends data to the server asynchronously.
(Inherited from ClientBase)
Public methodSendAsync(Object) Sends data to the server asynchronously.
(Inherited from ClientBase)
Public methodSendAsync(String) Sends data to the server asynchronously.
(Inherited from ClientBase)
Public methodSendAsync(Byte, Int32, Int32) Sends data to the server asynchronously.
(Inherited from ClientBase)
Protected methodSendDataAsync Sends (writes) data to the file asynchronously.
(Overrides ClientBaseSendDataAsync(Byte, Int32, Int32))
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden.
(Inherited from Component)
Protected methodUpdateBytesReceived Updates the Statistics pertaining to bytes received.
(Inherited from ClientBase)
Protected methodUpdateBytesSent Updates the Statistics pertaining to bytes sent.
(Inherited from ClientBase)
Protected methodValidateConnectionString Validates the specified connectionString.
(Overrides ClientBaseValidateConnectionString(String))
Top
Events
 NameDescription
Public eventConnectionAttempt Occurs when client is attempting connection to the server.
(Inherited from ClientBase)
Public eventConnectionEstablished Occurs when client connection to the server is established.
(Inherited from ClientBase)
Public eventConnectionException Occurs when an Exception is encountered during connection attempt to the server.
(Inherited from ClientBase)
Public eventConnectionTerminated Occurs when client connection to the server is terminated.
(Inherited from ClientBase)
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method.
(Inherited from Component)
Public eventEndOfFile Occurs when the end of a file has been reached.
Public eventReceiveData Occurs when unprocessed data has been received from the server.
(Inherited from ClientBase)
Public eventReceiveDataComplete Occurs when data received from the server has been processed and is ready for consumption.
(Inherited from ClientBase)
Public eventReceiveDataException Occurs when an Exception is encountered when receiving data from the server.
(Inherited from ClientBase)
Public eventSendDataComplete Occurs when the client has successfully sent data to the server.
(Inherited from ClientBase)
Public eventSendDataException Occurs when an Exception is encountered when sending data to the server.
(Inherited from ClientBase)
Public eventSendDataStart Occurs when the client begins sending data to the server.
(Inherited from ClientBase)
Public eventUnhandledUserException Occurs when an Exception is encountered in a user-defined function via an event dispatch.
(Inherited from ClientBase)
Top
Fields
 NameDescription
Public fieldStatic memberDefaultAutoRepeat Specifies the default value for the AutoRepeat property.
Public fieldStatic memberDefaultConnectionString Specifies the default value for the ConnectionString property.
Public fieldStatic memberDefaultDisconnectAtEOF Specifies the default value for the DisconnectAtEOF property.
Public fieldStatic memberDefaultFileAccessMode Specifies the default value for the FileAccessMode property.
Public fieldStatic memberDefaultFileOpenMode Specifies the default value for the FileOpenMode property.
Public fieldStatic memberDefaultFileShareMode Specifies the default value for the FileShareMode property.
Public fieldStatic memberDefaultReceiveInterval Specifies the default value for the ReceiveInterval property.
Public fieldStatic memberDefaultReceiveOnDemand Specifies the default value for the ReceiveOnDemand property.
Public fieldStatic memberDefaultStartingOffset Specifies the default value for the StartingOffset property.
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Example
This example shows how to use FileClient for writing data to a file:
C#
using System;
using GSF.Communication;

class Program
{
    static FileClient s_client;

    static void Main(string[] args)
    {
        // Initialize the client.
        s_client = new FileClient(@"File=c:\File.txt");
        s_client.Initialize();
        // Register event handlers.
        s_client.ConnectionAttempt += s_client_ConnectionAttempt;
        s_client.ConnectionEstablished += s_client_ConnectionEstablished;
        s_client.ConnectionTerminated += s_client_ConnectionTerminated;
        s_client.SendDataComplete += s_client_SendDataComplete;
        // Connect the client.
        s_client.Connect();

        // Write user input to the file.
        string input;
        while (string.Compare(input = Console.ReadLine(), "Exit", true) != 0)
        {
            s_client.Send(input + "\r\n");
        }

        // Disconnect the client on shutdown.
        s_client.Dispose();
    }

    static void s_client_ConnectionAttempt(object sender, EventArgs e)
    {
        Console.WriteLine("Client is connecting to file.");
    }

    static void s_client_ConnectionEstablished(object sender, EventArgs e)
    {
        Console.WriteLine("Client connected to file.");
    }

    static void s_client_ConnectionTerminated(object sender, EventArgs e)
    {
        Console.WriteLine("Client disconnected from file.");
    }

    static void s_client_SendDataComplete(object sender, EventArgs e)
    {
        Console.WriteLine(string.Format("Sent data - {0}", s_client.TextEncoding.GetString(s_client.Client.SendBuffer)));
    }
}
This example shows how to use FileClient for reading data to a file:
C#
using System;
using GSF;
using GSF.Communication;

class Program
{
    static FileClient s_client;

    static void Main(string[] args)
    {
        // Initialize the client.
        s_client = new FileClient(@"File=c:\File.txt");
        s_client.Initialize();
        // Register event handlers.
        s_client.ConnectionAttempt += s_client_ConnectionAttempt;
        s_client.ConnectionEstablished += s_client_ConnectionEstablished;
        s_client.ConnectionTerminated += s_client_ConnectionTerminated;
        s_client.ReceiveDataComplete += s_client_ReceiveDataComplete;
        // Connect the client.
        s_client.Connect();

        // Wait for client to read data.
        Console.ReadLine();

        // Disconnect the client on shutdown.
        s_client.Dispose();
    }

    static void s_client_ConnectionAttempt(object sender, EventArgs e)
    {
        Console.WriteLine("Client is connecting to file.");
    }

    static void s_client_ConnectionEstablished(object sender, EventArgs e)
    {
        Console.WriteLine("Client connected to file.");
    }

    static void s_client_ConnectionTerminated(object sender, EventArgs e)
    {
        Console.WriteLine("Client disconnected from file.");
    }

    static void s_client_ReceiveDataComplete(object sender, EventArgs<byte[], int> e)
    {
        Console.WriteLine(string.Format("Received data - {0}", s_client.TextEncoding.GetString(e.Argument1, 0, e.Argument2)));
    }
}
See Also