public void Update(Manager.Common.UpdateMetadataMessage message)
        {
            foreach (var item in message.UpdateDatas)
            {
                VmInstrument instrument;
                switch (item.MetadataType)
                {
                case MetadataType.QuotationSource:
                    VmQuotationSource source = this._QuotationSources.SingleOrDefault(s => s.Id == item.ObjectId);
                    if (source != null)
                    {
                        source.ApplyChangeToUI(item.FieldsAndValues);
                    }
                    break;

                case MetadataType.Instrument:
                    instrument = this._Instruments.SingleOrDefault(i => i.Id == item.ObjectId);
                    if (instrument != null)
                    {
                        instrument.ApplyChangeToUI(item.FieldsAndValues);
                    }
                    break;

                case MetadataType.InstrumentSourceRelation:
                    VmInstrumentSourceRelation relation;
                    if (this.FindVmInstrumentSourceRelation(item.ObjectId, out relation, out instrument))
                    {
                        relation.ApplyChangeToUI(item.FieldsAndValues);
                    }
                    break;

                case MetadataType.DerivativeRelation:
                    instrument = this._Instruments.SingleOrDefault(i => i.Id == item.ObjectId);
                    if (instrument != null)
                    {
                        instrument.VmDerivativeRelation.ApplyChangeToUI(item.FieldsAndValues);
                    }
                    break;

                case MetadataType.PriceRangeCheckRule:
                    instrument = this._Instruments.SingleOrDefault(i => i.Id == item.ObjectId);
                    if (instrument != null)
                    {
                        instrument.VmPriceRangeCheckRule.ApplyChangeToUI(item.FieldsAndValues);
                    }
                    break;

                case MetadataType.WeightedPriceRule:
                    instrument = this._Instruments.SingleOrDefault(i => i.Id == item.ObjectId);
                    if (instrument != null)
                    {
                        instrument.VmWeightedPriceRule.ApplyChangeToUI(item.FieldsAndValues);
                    }
                    break;

                default:
                    break;
                }
            }
        }
        public void Add(InstrumentSourceRelation relation)
        {
            VmInstrument      vmInstrument      = this._Instruments.Single(i => i.Id == relation.InstrumentId);
            VmQuotationSource vmQuotationSource = this._QuotationSources.Single(s => s.Id == relation.SourceId);

            vmInstrument.SourceRelations.Add(new VmInstrumentSourceRelation(relation, vmInstrument, vmQuotationSource));
        }
        public void RemoveQuotationSource(int id)
        {
            VmQuotationSource source = this._QuotationSources.SingleOrDefault(s => s.Id == id);

            if (source != null)
            {
                this._QuotationSources.Remove(source);
            }
        }
        public void Initialize()
        {
            try
            {
                //if (this._MetadataNotLoaded)
                //{
                ConfigMetadata metadata = ConsoleClient.Instance.GetConfigMetadata();

                this._QuotationSources.Clear();
                foreach (var source in metadata.QuotationSources.Values)
                {
                    this._QuotationSources.Add(new VmQuotationSource(source));
                }

                this._Instruments.Clear();
                foreach (var instrument in metadata.Instruments.Values)
                {
                    VmInstrument vmInstrument = new VmInstrument(instrument);
                    if (instrument.IsDerivative)
                    {
                        vmInstrument.VmDerivativeRelation = new VmDerivativeRelation(metadata.DerivativeRelations[instrument.Id]);
                    }
                    else
                    {
                        foreach (Dictionary <string, InstrumentSourceRelation> dict in metadata.InstrumentSourceRelations.Values)
                        {
                            var relation = dict.Values.SingleOrDefault(r => r.InstrumentId == instrument.Id);
                            if (relation != null)
                            {
                                VmQuotationSource vmQuotationSource = this._QuotationSources.Single(s => s.Id == relation.SourceId);
                                vmInstrument.SourceRelations.Add(new VmInstrumentSourceRelation(relation, vmInstrument, vmQuotationSource));
                            }
                        }

                        if (!instrument.IsDerivative)
                        {
                            vmInstrument.VmPriceRangeCheckRule = new VmPriceRangeCheckRule(metadata.PriceRangeCheckRules[instrument.Id]);
                            if (metadata.WeightedPriceRules.ContainsKey(instrument.Id))
                            {
                                vmInstrument.VmWeightedPriceRule = new VmWeightedPriceRule(metadata.WeightedPriceRules[instrument.Id]);
                            }
                            else
                            {
                                vmInstrument.VmWeightedPriceRule = new VmWeightedPriceRule(new WeightedPriceRule());
                            }
                        }
                    }

                    // set quotation
                    GeneralQuotation generalQuotation;
                    if (metadata.LastQuotations.TryGetValue(instrument.Id, out generalQuotation))
                    {
                        vmInstrument.SetQuotation(generalQuotation, vmInstrument.DecimalPlace);
                    }

                    this._Instruments.Add(vmInstrument);
                    //}
                    //this._MetadataNotLoaded = false;
                }
            }
            catch (Exception exception)
            {
                Logger.TraceEvent(TraceEventType.Error, "VmQuotationManager.LoadMetadata\r\n{0}", exception);
            }
        }