예제 #1
0
        public static Dictionary <TKey, TValue> FromFudgeMsg <TKey, TValue>(IFudgeFieldContainer ffc, Func <IFudgeField, TKey> keyFactory, Func <IFudgeField, TValue> valueFactory)
        {
            ArgumentChecker.NotNull(keyFactory, "keyFactory");
            ArgumentChecker.NotNull(valueFactory, "valueFactory");
            if (ffc == null)
            {
                return(new Dictionary <TKey, TValue>());
            }

            if (ffc.Any(f => f.Ordinal.GetValueOrDefault(0) > 2))
            {
                throw new ArgumentException();
            }

            var entries = ffc.GetAllByOrdinal(1).Zip(ffc.GetAllByOrdinal(2), Tuple.Create);

            return(entries.ToDictionary(t => keyFactory(t.Item1), t => valueFactory(t.Item2)));
        }
예제 #2
0
        public static ManageableUnstructuredMarketDataSnapshot FromFudgeMsg(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var dictionary = new Dictionary <MarketDataValueSpecification, IDictionary <string, ValueSnapshot> >();

            foreach (var entryField in ffc.GetAllByOrdinal(1))
            {
                var entryMsg = (IFudgeFieldContainer)entryField.Value;
                MarketDataValueSpecification valueSpec = null;
                string        valueName = null;
                ValueSnapshot value     = null;

                foreach (var field in entryMsg)
                {
                    switch (field.Name)
                    {
                    case "valueSpec":
                        valueSpec = deserializer.FromField <MarketDataValueSpecification>(field);
                        break;

                    case "valueName":
                        valueName = (string)field.Value;
                        break;

                    case "value":
                        value = deserializer.FromField <ValueSnapshot>(field);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                IDictionary <string, ValueSnapshot> innerDict;
                if (!dictionary.TryGetValue(valueSpec, out innerDict))
                {
                    innerDict = new Dictionary <string, ValueSnapshot>();
                    dictionary.Add(valueSpec, innerDict);
                }
                innerDict.Add(valueName, value);
            }
            return(new ManageableUnstructuredMarketDataSnapshot(dictionary));
        }