C# Класс Examples.ControlClientUpdatingRecordTopics

An example of using a control client to create and update a record topic in exclusive mode. This uses the topic control feature to create a topic and the topic update control feature to send updates to it. Both 'full' and 'patch' updating techniques are demonstrated. Full updates involve sending the whole topic state to the server; this will be compared with the current state and a delta of any differences published to subscribed clients. With patch updates it is only necessary to send the values of the fields that have changed to the server where they will be applied to the current topic state and published to subscribers. The latter mechanism is not so well suited to this example where there are only 2 fields, but for topics with many fields this could represent considerable savings in the amount of data sent to the server. To send updates to a topic, the client session requires the 'update_topic' permission for that branch of the topic tree. The example also demonstrates a simple usage of a structured record builder for generating content as such a builder validates the input against the metadata.
Показать файл Открыть проект

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

Метод Описание
AddRate ( string currency, string targetCurrency, string bid, string ask, ITopicControlAddContextCallback callback ) : void

Adds a new conversion rate in terms of base currency and target currency. The bid and ask rates are entered as strings which may be a decimal value; this will be parsed and validated, rounding to 5 decimal places. If a zero-length string ("") is supplied, the rate will be set to 'empty' and clients will receive a zero-length string in the initial load.

ChangeBidRate ( string currency, string targetCurrency, string bid, ITopicUpdaterUpdateContextCallback callback ) : void

Updates just the 'bid' value for a specified rate. This method demonstrates the alternative 'delta' mechanism of updating. In this example it does not make much sense, but for records with many fields where you know only one is changing, this negates the need to send the whole topic state in each update.

ChangeRate ( string currency, string targetCurrency, string bid, string ask, ITopicUpdaterUpdateContextCallback callback ) : void

Update a rate. The rate in question must have been added first using AddRate otherwise this will fail. The bid and ask rates are entered as strings which may be a decimal value; this will be parsed and validated, rounding to 5 decimal places. A zero-length string may be supplied to indicate 'no rate available'. The server will compare the supplied values with the current values, and if different will notify clients of a delta of change. Only changed fields are notified to clients - unchanged fields are passed as a zero-length string. If a field has changed to zero length, the client will receive the special empty field value in the delta.

Close ( ) : void

Close the session.

ControlClientUpdatingRecordTopics ( string serverUrl ) : System

Constructor.

RemoveCurrency ( string currency, ITopicControlRemoveContextCallback callback ) : void

Removes a currency (removes its topics and all subordinate rate topics).

RemoveRate ( string currency, string targetCurrency, ITopicControlRemoveContextCallback callback ) : void

Remove a rate (removes its topic).

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

Метод Описание
CreateRateContent ( string bid, string ask ) : IContent

Create rate contents for a full update.

RateTopicName ( string currency, string targetCurrency ) : string

Generates a hierarchical topic name for a rate topic. e.g. for currency=GBP and targetCurrency=USD, this would return "FX/GBP/USD".

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

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

Adds a new conversion rate in terms of base currency and target currency. The bid and ask rates are entered as strings which may be a decimal value; this will be parsed and validated, rounding to 5 decimal places. If a zero-length string ("") is supplied, the rate will be set to 'empty' and clients will receive a zero-length string in the initial load.
public AddRate ( string currency, string targetCurrency, string bid, string ask, ITopicControlAddContextCallback callback ) : void
currency string The base currency (e.g. GBP).
targetCurrency string The target current (e.g. USD).
bid string The 'bid' rate.
ask string The 'ask' rate.
callback ITopicControlAddContextCallback A callback which will be called to report the outcome. The context in the callback /// wil be currency/target currency (e.g. "GBP/USD").
Результат void

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

Updates just the 'bid' value for a specified rate. This method demonstrates the alternative 'delta' mechanism of updating. In this example it does not make much sense, but for records with many fields where you know only one is changing, this negates the need to send the whole topic state in each update.
public ChangeBidRate ( string currency, string targetCurrency, string bid, ITopicUpdaterUpdateContextCallback callback ) : void
currency string The base currency.
targetCurrency string The target currency.
bid string The new bid rate which can be an empty string to set to 'not available'.
callback ITopicUpdaterUpdateContextCallback A callback which will be called to report the outcome. The context in the callback /// will be currency/targetCurrency (e.g. "GBP/USD".
Результат void

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

Update a rate. The rate in question must have been added first using AddRate otherwise this will fail. The bid and ask rates are entered as strings which may be a decimal value; this will be parsed and validated, rounding to 5 decimal places. A zero-length string may be supplied to indicate 'no rate available'. The server will compare the supplied values with the current values, and if different will notify clients of a delta of change. Only changed fields are notified to clients - unchanged fields are passed as a zero-length string. If a field has changed to zero length, the client will receive the special empty field value in the delta.
public ChangeRate ( string currency, string targetCurrency, string bid, string ask, ITopicUpdaterUpdateContextCallback callback ) : void
currency string The base currency.
targetCurrency string The target currency.
bid string The new bid rate.
ask string The new ask rate.
callback ITopicUpdaterUpdateContextCallback A callback which will be called to report the outcome. The context in the callback /// will be currency/target currency (e.g. "GBP/USD").
Результат void

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

Close the session.
public Close ( ) : void
Результат void

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

Constructor.
public ControlClientUpdatingRecordTopics ( string serverUrl ) : System
serverUrl string The server url, for example "ws://diffusion.example.com:80".
Результат System

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

Removes a currency (removes its topics and all subordinate rate topics).
public RemoveCurrency ( string currency, ITopicControlRemoveContextCallback callback ) : void
currency string The base currency.
callback ITopicControlRemoveContextCallback Reports the outcome.
Результат void

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

Remove a rate (removes its topic).
public RemoveRate ( string currency, string targetCurrency, ITopicControlRemoveContextCallback callback ) : void
currency string The base currency.
targetCurrency string The target currency.
callback ITopicControlRemoveContextCallback Reports the outcome.
Результат void