C# Class Examples.ControlClientUpdatingJSONTopics

This example shows a control client creating a JSON topic and sending updates to it. There will be a topic for each currency for which rates are provided. The topic will be created under the FX topic - so, for example FX/GBP will contain a map of all rate conversions from the base GBP currency. The rates are represented as string decimal values (e.g. "12.457"). The addRates method shows how to create a new rates topic, specifying its initial map of values. The changeRates method which takes a map shows how to completely replace the set of rates for a currency with a new map of rates. The changeRates method which takes a string shows an alternative mechanism where the new rates are simply supplied as a JSON string. Either of the changeRates methods could be used and after the first usage for any topic the values is cached, and so subsequent set calls can compare with the last value and send only the differences to the server.
ファイルを表示 Open project: pushtechnology/diffusion-examples

Public Methods

Method Description
AddRates ( string currency, string>.IDictionary values, ITopicControlAddContextCallback callback ) : void

Add a new rates topic.

ChangeRates ( string currency, string>.IDictionary values, ITopicUpdaterUpdateContextCallback callback ) : void

Update and existing rates topic, replacing the rates mappings with a new set of mappings.

ChangeRates ( string currency, string jsonString, ITopicUpdaterUpdateContextCallback callback ) : void

Update an existing rates topic, replacing the rates mappings with a new set of mappings specified as a JSON string, for example {"USD":"123.45","HKD":"456.3"}.

ControlClientUpdatingJSONTopics ( string serverUrl ) : System

Constructor.

close ( ) : void

Close the session.

removeRates ( string currency, ITopicControlRemoveContextCallback callback ) : void

Remove a rates entry (remove its topic) and clear cached value for the topic.

Private Methods

Method Description
MapToJSON ( string>.IDictionary values ) : IJSON

Convert a given map to a JSON object.

RateTopicName ( string currency ) : string

Generate a hierarchical topic name for a rates topic. e.g. for currency=GBP would return "FX/GBP".

Method Details

AddRates() public method

Add a new rates topic.
public AddRates ( string currency, string>.IDictionary values, ITopicControlAddContextCallback callback ) : void
currency string the base currency
values string>.IDictionary the full map of initial rates values
callback ITopicControlAddContextCallback reports outcome
return void

ChangeRates() public method

Update and existing rates topic, replacing the rates mappings with a new set of mappings.
public ChangeRates ( string currency, string>.IDictionary values, ITopicUpdaterUpdateContextCallback callback ) : void
currency string the base currency
values string>.IDictionary the mew rates values
callback ITopicUpdaterUpdateContextCallback reports outcome
return void

ChangeRates() public method

Update an existing rates topic, replacing the rates mappings with a new set of mappings specified as a JSON string, for example {"USD":"123.45","HKD":"456.3"}.
public ChangeRates ( string currency, string jsonString, ITopicUpdaterUpdateContextCallback callback ) : void
currency string the base currency
jsonString string a JSON string specifying the map of currency rates
callback ITopicUpdaterUpdateContextCallback reports outcome
return void

ControlClientUpdatingJSONTopics() public method

Constructor.
public ControlClientUpdatingJSONTopics ( string serverUrl ) : System
serverUrl string for example "ws://diffusion.example.com:80"
return System

close() public method

Close the session.
public close ( ) : void
return void

removeRates() public method

Remove a rates entry (remove its topic) and clear cached value for the topic.
public removeRates ( string currency, ITopicControlRemoveContextCallback callback ) : void
currency string the currency to be removed
callback ITopicControlRemoveContextCallback reports the outcome
return void