C# Класс CSReportWebServer.NativeMessaging.Port

Google Chrome Native Messaging Port.
This class partially implements Google Chrome Native Messaging Protocol as described here https://developer.chrome.com/extensions/nativeMessaging . Partial implementation means that parsing input messages into JSON objects and JSON object into output messages is up to you.
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
BeginRead ( AsyncCallback callback, object state ) : IAsyncResult

Begins a native message asynchronous read from the input stream.

BeginWrite ( string message, AsyncCallback callback, object state ) : IAsyncResult

Begins a native message asynchronous write to the output stream.

EndRead ( IAsyncResult asyncResult ) : string

Ends the native message asynchronous read started by BeginRead method.

The EndRead method must be called for each asynchronous operation started by BeginRead method. If any exception was thrown during asynchronous read, it is re-thrown in this method.

EndWrite ( IAsyncResult asyncResult ) : void

Ends the native message asynchronous write started by BeginWrite method. The EndWrite method must be called for each asynchronous operation started by BeginWrite method.

If any exception was thrown during asynchronous write, it is re-thrown in this method.

Port ( ) : System

Creates a new native messaging port for stdandard input and output streams.

Port ( Stream istream, Stream ostream ) : System

Creates a new native messaging port for given input and output streams.

Read ( ) : string

Reads a native message from input stream synchronously.

This method actually starts an asynchronous operation an the waits until it is finished.

Write ( string message ) : void

Writes the native message to output stream synchronously.

This method actually starts an asynchronous operation an the waits until it is finished.

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

Метод Описание
ReadLengthCallback ( AsyncResult ar, IAsyncResult lengthAsyncResult ) : void

Ends the asynchronous read of a native message length started by BeginRead method. Then begins an asynchronous read of a native message content.

Any exception thrown in the method is saved and then is re-thrown in EndRead method.

ReadMessageCallback ( AsyncResult ar, IAsyncResult messageAsyncResult ) : void

Ends the asynchronous read of a native message content started by ReadLengthCallback method. Then calls the callback specified for the operation.

Any exception thrown in the method is saved and then is re-thrown in EndRead method.

WriteLengthCallback ( AsyncResult ar, IAsyncResult lengthAsyncResult ) : void

Ends the asynchronous write of a native message length started by BeginWrite method. Then begins an asynchronous write of a native message content.

Any exception thrown in the method is saved and then is re-thrown in EndWrite method.

WriteMessageCallback ( AsyncResult ar, IAsyncResult messageAsyncResult ) : void

Ends the asynchronous write of a native message content started by WriteLengthCallback method. Then calls the callback specified for the operation.

Any exception thrown in the method is saved and then is re-thrown in EndRead method.

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

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

Begins a native message asynchronous read from the input stream.
The input stream IO exception. The input stream was closed. The input stream does not support read operation.
public BeginRead ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback An AsyncCallback delegate that is executed when a native message is read or an error has occured.
state object An user-defined object that is passed to the callback inside its IAsyncResult parameter.
Результат IAsyncResult

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

Begins a native message asynchronous write to the output stream.
The message parameter is null. The output stream IO exception. The output stream was closed. The output stream does not support write operation. The native message that is to be written is not of UTF-8 encoding. The allocation of the native message buffer has failed.
public BeginWrite ( string message, AsyncCallback callback, object state ) : IAsyncResult
message string A native message that is to be written.
callback AsyncCallback An AsyncCallback delegate that is executed when a native message is written or an error has occured.
state object An user-defined object that is passed to the callback inside its IAsyncResult parameter.
Результат IAsyncResult

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

Ends the native message asynchronous read started by BeginRead method.
The EndRead method must be called for each asynchronous operation started by BeginRead method. If any exception was thrown during asynchronous read, it is re-thrown in this method.
The asyncResult parameter is null. The asyncResult parameter is of improper type. The input stream IO exception. The input stream was closed. The input stream does not support read operation. The end of input stream was reached before a native message was read. The end of input stream was reached after a part of native message was read. Negative or zero length of a native message was read. The native message read is not of UTF-8 encoding. The allocation of a native message buffer has failed.
public EndRead ( IAsyncResult asyncResult ) : string
asyncResult IAsyncResult The IAsyncResult object that represents the asynchronous operation started by BeginRead method.
Результат string

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

Ends the native message asynchronous write started by BeginWrite method. The EndWrite method must be called for each asynchronous operation started by BeginWrite method.
If any exception was thrown during asynchronous write, it is re-thrown in this method.
The asyncResult parameter is null. The asyncResult parameter is of improper type. The output stream IO exception. The output stream was closed. The output stream does not support write operation.
public EndWrite ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult The IAsyncResult object that represents the asynchronous operation started by BeginWrite method.
Результат void

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

Creates a new native messaging port for stdandard input and output streams.
public Port ( ) : System
Результат System

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

Creates a new native messaging port for given input and output streams.
The istream parameter is null. The ostream parameter is null.
public Port ( Stream istream, Stream ostream ) : System
istream Stream The input stream.
ostream Stream The output stream.
Результат System

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

Reads a native message from input stream synchronously.
This method actually starts an asynchronous operation an the waits until it is finished.
The input stream IO exception. The input stream was closed. The input stream does not support read operation. The end of input stream was reached before a native message was read. The end of input stream was reached after a part of native message was read. Negative or zero length of a native message was read. The native message read is not of UTF-8 encoding. The allocation of a native message buffer has failed.
public Read ( ) : string
Результат string

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

Writes the native message to output stream synchronously.
This method actually starts an asynchronous operation an the waits until it is finished.
The message parameter is null. The output stream IO exception. The output stream was closed. The output stream does not support write operation. The native message that is to be written is not of UTF-8 encoding. The allocation of the native message buffer has failed.
public Write ( string message ) : void
message string The native message that is to be written to the output stream.
Результат void