コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        ConversionEntry CreateEntry(string symbol1, string symbol2, double?value)
        {
            ConversionEntry entry = new ConversionEntry(symbol1, symbol2);

            if (value.HasValue)
            {
                entry.Update(value.Value);
            }

            lock (this)
            {
                if (_entries.ContainsKey(symbol1) == false)
                {
                    _entries.Add(symbol1, new Dictionary <string, ConversionEntry>());
                }

                if (_entries[symbol1].ContainsKey(symbol2))
                {
                    SystemMonitor.Warning("Entry already exists.");
                    return(_entries[symbol1][symbol2]);
                }

                _entries[symbol1].Add(symbol2, entry);
            }

            return(entry);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        void _currencyService_ConversionRateCompleted(object sender, ConversionRateCompletedEventArgs e)
        {
            Currency[] state = (Currency[])e.UserState;
            double     value = e.Result;

            if (value == 0)
            {
                SystemMonitor.Warning("Value 0 not accepted from service.");
                return;
            }

            ConversionEntry entry = null;

            lock (this)
            {
                if (_entries.ContainsKey(state[0].ToString()) &&
                    _entries[state[0].ToString()].ContainsKey(state[1].ToString()))
                {
                    entry = _entries[state[0].ToString()][state[1].ToString()];
                    entry.Update(value);
                }
            }

            if (EntryUpdateEvent != null && entry != null)
            {
                EntryUpdateEvent(this, entry);
            }
        }
コード例 #3
0
ファイル: ConversionSupport.cs プロジェクト: pl89/nms-amqp
        public static T ConvertNMSType <T, S>(S value)
        {
            ConversionKey          key       = ConversionKey.GetKey(typeof(T), value.GetType());
            ConversionEntry <T, S> converter = (ConversionEntry <T, S>)NMSTypeConversionTable[key];

            if (converter == null)
            {
                throw new NMSTypeConversionException("Cannot convert between type : " + (typeof(T)).Name + ", and type: " + value.GetType().Name);
            }
            return(converter.ConvertInstance(value));
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        public void UpdateValue(string symbol1, string symbol2, double value)
        {
            if (string.IsNullOrEmpty(symbol1) || string.IsNullOrEmpty(symbol2))
            {
                SystemMonitor.Warning("Invalid symbol name.");
                return;
            }

            if (value == 0)
            {
                SystemMonitor.Warning("Value 0 not accepted.");
                return;
            }

            symbol1 = symbol1.ToUpper();
            symbol2 = symbol2.ToUpper();

            if (symbol1 == symbol2)
            {
                return;
            }

            ConversionEntry entry       = null;
            double          updateValue = value;

            lock (this)
            {
                if (_entries.ContainsKey(symbol1) && _entries[symbol1].ContainsKey(symbol2))
                {// Straight.
                    entry       = _entries[symbol1][symbol2];
                    updateValue = value;
                }
                else if (_entries.ContainsKey(symbol2) && _entries[symbol2].ContainsKey(symbol1))
                {// Reverse.
                    entry       = _entries[symbol2][symbol1];
                    updateValue = 1 / value;
                }
            }

            if (entry != null)
            {
                entry.Update(updateValue);
            }
            else
            {
                entry = CreateEntry(symbol1, symbol2, value);
            }

            if (EntryUpdateEvent != null)
            {
                EntryUpdateEvent(this, entry);
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        void BeginServiceEntryUpdate(ConversionEntry entry)
        {
            Currency currency1, currency2;

            lock (this)
            {
                if (_serviceCurrencies.ContainsKey(entry.Symbol1) == false ||
                    _serviceCurrencies.ContainsKey(entry.Symbol2) == false)
                {
                    SystemMonitor.Warning("Symbol not supported.");
                    return;
                }

                entry.UpdateEvent.Reset();

                currency1 = _serviceCurrencies[entry.Symbol1];
                currency2 = _serviceCurrencies[entry.Symbol2];

                // Begin operation.
                _currencyService.ConversionRateAsync(currency1, currency2, new Currency[] { currency1, currency2 });
            }
        }
コード例 #6
0
        /// <summary>
        /// 
        /// </summary>
        ConversionEntry CreateEntry(string symbol1, string symbol2, double? value)
        {
            ConversionEntry entry = new ConversionEntry(symbol1, symbol2);
            if (value.HasValue)
            {
                entry.Update(value.Value);
            }

            lock (this)
            {
                if (_entries.ContainsKey(symbol1) == false)
                {
                    _entries.Add(symbol1, new Dictionary<string,ConversionEntry>());
                }

                if (_entries[symbol1].ContainsKey(symbol2))
                {
                    SystemMonitor.Warning("Entry already exists.");
                    return _entries[symbol1][symbol2];
                }

                _entries[symbol1].Add(symbol2, entry);
            }

            return entry;
        }
コード例 #7
0
        /// <summary>
        /// 
        /// </summary>
        void BeginServiceEntryUpdate(ConversionEntry entry)
        {
            Currency currency1, currency2;

            lock(this)
            {
                if (_serviceCurrencies.ContainsKey(entry.Symbol1) == false ||
                    _serviceCurrencies.ContainsKey(entry.Symbol2) == false)
                {
                    SystemMonitor.Warning("Symbol not supported.");
                    return;
                }

                entry.UpdateEvent.Reset();

                currency1 = _serviceCurrencies[entry.Symbol1];
                currency2 = _serviceCurrencies[entry.Symbol2];

                // Begin operation.
                _currencyService.ConversionRateAsync(currency1, currency2, new Currency[] { currency1, currency2 });
            }
        }