C# Class Examples.ClientConsumingRecordTopics

This demonstrates a client consuming record topics and reading the content using a structured reader. This makes use of the 'Topics' feature only. To subscribe to a topic, the client session must have the 'read_topic' permission for that branch of the topic tree. This example receives updates to currency conversion rates via a branch of the topic tree where the root topic is called 'FX'; beneath which is a topic for each base currency, and beneath each of those is a topic for each target currency which contains the bid and ask rates. So a topic 'FX/GBP/USD' would contain the rates for GBP to USD. This example maintains a local dictionary of the rates and also notifies a listener of any rates changes. The example shows the use of empty fields. Any of the rates can be empty (meaning the rate is not available in this example), so it can be an empty string in the topic value. Because delta updates use a zero-length string to indicate that a field has not changed, a special 'empty field' value is used to indicate that the field has changed to empty in deltas. The client application must therefore convert empty string values to "" for the local rate value.
显示文件 Open project: pushtechnology/diffusion-examples

Public Methods

Method Description
ApplyUpdate ( TopicUpdateType type, string currency, string targetCurrency, string bid, string ask ) : void

This is used to apply topic stream updates to the local dictionary.

ClientConsumingRecordTopics ( string serverUrl, IRatesListener listener ) : System.Collections.Generic
Close ( ) : void

Close session.

GetRates ( string currency, string targetCurrency ) : Rates

Returns the rates for a given base and target currency.

RemoveCurrency ( string currency ) : void

This is used by the topic stream when notified of the unsubscription from a base currency topic. It will remove the base currency and all of its rates from the local dictionary.

RemoveRate ( string currency, string targetCurrency ) : void

This is used by the topic stream when notification of the unsubscription from a target currency topic. It will remove the rates for the target currency under the base currency.

Method Details

ApplyUpdate() public static method

This is used to apply topic stream updates to the local dictionary.
public static ApplyUpdate ( TopicUpdateType type, string currency, string targetCurrency, string bid, string ask ) : void
type TopicUpdateType The update may be a snapshot or a delta.
currency string The base currency.
targetCurrency string The target currency.
bid string The bid rate.
ask string The ask rate.
return void

ClientConsumingRecordTopics() public method

public ClientConsumingRecordTopics ( string serverUrl, IRatesListener listener ) : System.Collections.Generic
serverUrl string
listener IRatesListener
return System.Collections.Generic

Close() public method

Close session.
public Close ( ) : void
return void

GetRates() public method

Returns the rates for a given base and target currency.
public GetRates ( string currency, string targetCurrency ) : Rates
currency string The base currency.
targetCurrency string The target currency.
return Rates

RemoveCurrency() public static method

This is used by the topic stream when notified of the unsubscription from a base currency topic. It will remove the base currency and all of its rates from the local dictionary.
public static RemoveCurrency ( string currency ) : void
currency string The currency to remove.
return void

RemoveRate() public static method

This is used by the topic stream when notification of the unsubscription from a target currency topic. It will remove the rates for the target currency under the base currency.
public static RemoveRate ( string currency, string targetCurrency ) : void
currency string The base currency.
targetCurrency string The target currency.
return void