Esempio n. 1
0
        /// <summary>
        /// Update and existing rates topic, replacing the rates mappings with a new set of mappings.
        /// </summary>
        /// <param name="currency">the base currency</param>
        /// <param name="values">the mew rates values</param>
        /// <param name="callback">reports outcome</param>
        public void ChangeRates(string currency, IDictionary <string, string> values,
                                ITopicUpdaterUpdateContextCallback <string> callback)
        {
            if (valueUpdater == null)
            {
                throw new InvalidOperationException("Not registered as updater");
            }

            valueUpdater.Update(RateTopicName(currency), MapToJSON(values), currency, callback);
        }
Esempio n. 2
0
        /// <summary>
        /// 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"}.
        /// </summary>
        /// <param name="currency">the base currency</param>
        /// <param name="jsonString">a JSON string specifying the map of currency rates</param>
        /// <param name="callback">reports outcome</param>
        public void ChangeRates(string currency, string jsonString,
                                ITopicUpdaterUpdateContextCallback <string> callback)
        {
            if (valueUpdater == null)
            {
                throw new InvalidOperationException("Not registered as updater");
            }

            valueUpdater.Update(RateTopicName(currency), jsonDataType.FromJSONString(jsonString), currency,
                                callback);
        }
Esempio n. 3
0
        /// <summary>
        /// Update a rate.
        ///
        /// The rate in question must have been added first using <see cref="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.
        /// </summary>
        /// <param name="currency">The base currency.</param>
        /// <param name="targetCurrency">The target currency.</param>
        /// <param name="bid">The new bid rate.</param>
        /// <param name="ask">The new ask rate.</param>
        /// <param name="callback">A callback which will be called to report the outcome. The context in the callback
        /// will be currency/target currency (e.g. "GBP/USD").</param>
        public void ChangeRate(string currency, string targetCurrency, string bid, string ask,
                               ITopicUpdaterUpdateContextCallback <string> callback)
        {
            if (topicUpdater == null)
            {
                throw new InvalidOperationException("Not registered as an updater.");
            }

            topicUpdater.Update(RateTopicName(currency, targetCurrency),
                                updateFactory.Update(CreateRateContent(bid, ask)),
                                string.Format("{0}/{1}", currency, targetCurrency),
                                callback);
        }
Esempio n. 4
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="currency">The base currency.</param>
        /// <param name="targetCurrency">The target currency.</param>
        /// <param name="bid">The new bid rate which can be an empty string to set to 'not available'.</param>
        /// <param name="callback">A callback which will be called to report the outcome. The context in the callback
        /// will be currency/targetCurrency (e.g. "GBP/USD".</param>
        public void ChangeBidRate(string currency, string targetCurrency, string bid,
                                  ITopicUpdaterUpdateContextCallback <string> callback)
        {
            if (topicUpdater == null)
            {
                throw new InvalidOperationException("Not registered as an updater.");
            }

            var content = Diffusion.Content.NewBuilder <IRecordContentBuilder>()
                          .PutRecords(
                deltaRecordBuilder.Set("Bid", "".Equals(bid) ? Constants.EMPTY_FIELD_STRING : bid).Build())
                          .Build();

            topicUpdater.Update(RateTopicName(currency, targetCurrency), updateFactory.Apply(content),
                                string.Format("{0}/{1}", currency, targetCurrency), callback);
        }
        /// <summary>
        /// Update a rate.
        ///
        /// The rate in question must have been added first using <see cref="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.
        /// </summary>
        /// <param name="currency">The base currency.</param>
        /// <param name="targetCurrency">The target currency.</param>
        /// <param name="bid">The new bid rate.</param>
        /// <param name="ask">The new ask rate.</param>
        /// <param name="callback">A callback which will be called to report the outcome. The context in the callback
        /// will be currency/target currency (e.g. "GBP/USD").</param>
        public void ChangeRate( string currency, string targetCurrency, string bid, string ask,
            ITopicUpdaterUpdateContextCallback<string> callback )
        {
            if ( topicUpdater == null ) {
                throw new InvalidOperationException( "Not registered as an updater." );
            }

            topicUpdater.Update( RateTopicName( currency, targetCurrency ),
                updateFactory.Update( CreateRateContent( bid, ask ) ),
                string.Format( "{0}/{1}", currency, targetCurrency ),
                callback );
        }
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="currency">The base currency.</param>
        /// <param name="targetCurrency">The target currency.</param>
        /// <param name="bid">The new bid rate which can be an empty string to set to 'not available'.</param>
        /// <param name="callback">A callback which will be called to report the outcome. The context in the callback
        /// will be currency/targetCurrency (e.g. "GBP/USD".</param>
        public void ChangeBidRate( string currency, string targetCurrency, string bid,
            ITopicUpdaterUpdateContextCallback<string> callback )
        {
            if ( topicUpdater == null ) {
                throw new InvalidOperationException( "Not registered as an updater." );
            }

            var content = Diffusion.Content.NewBuilder<IRecordContentBuilder>()
                .PutRecords(
                    deltaRecordBuilder.Set( "Bid", "".Equals( bid ) ? Constants.EMPTY_FIELD_STRING : bid ).Build() )
                .Build();

            topicUpdater.Update( RateTopicName( currency, targetCurrency ), updateFactory.Apply( content ),
                string.Format( "{0}/{1}", currency, targetCurrency ), callback );
        }
        /// <summary>
        /// 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"}.
        /// </summary>
        /// <param name="currency">the base currency</param>
        /// <param name="jsonString">a JSON string specifying the map of currency rates</param>
        /// <param name="callback">reports outcome</param>
        public void ChangeRates( string currency, string jsonString,
            ITopicUpdaterUpdateContextCallback<string> callback )
        {
            if ( valueUpdater == null ) {
                throw new InvalidOperationException( "Not registered as updater" );
            }

            valueUpdater.Update( RateTopicName( currency ), jsonDataType.FromJSONString( jsonString ), currency,
                callback );
        }
        /// <summary>
        /// Update and existing rates topic, replacing the rates mappings with a new set of mappings.
        /// </summary>
        /// <param name="currency">the base currency</param>
        /// <param name="values">the mew rates values</param>
        /// <param name="callback">reports outcome</param>
        public void ChangeRates( string currency, IDictionary<string, string> values,
            ITopicUpdaterUpdateContextCallback<string> callback )
        {
            if ( valueUpdater == null ) {
                throw new InvalidOperationException( "Not registered as updater" );
            }

            valueUpdater.Update( RateTopicName( currency ), MapToJSON( values ), currency, callback );
        }