예제 #1
0
        private static void ReadStreamEntry(
            EmberReader reader, IReadOnlyDictionary <int, IEnumerable <IStreamedParameter> > streamedParameters)
        {
            reader.AssertInnerNumber(GlowStreamEntry.InnerNumber);
            int?   identifier = null;
            object rawValue   = null;

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowStreamEntry.StreamIdentifier.OuterNumber:
                    identifier = reader.AssertAndReadContentsAsInt32();
                    break;

                case GlowStreamEntry.StreamValue.OuterNumber:
                    rawValue = reader.ReadContentsAsObject();
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }

            IEnumerable <IStreamedParameter> group;

            if (identifier.HasValue && streamedParameters.TryGetValue(identifier.Value, out group) &&
                (rawValue != null))
            {
                foreach (var parameter in group)
                {
                    var value = ExtractValue(parameter, rawValue);

                    try
                    {
                        parameter.SetProviderValue(value);
                    }
                    catch (ArgumentException ex)
                    {
                        const string Format = "Read unexpected stream value {0} for the parameter with the path {1}.";
                        throw new ModelException(
                                  string.Format(CultureInfo.InvariantCulture, Format, value, parameter.GetPath()), ex);
                    }
                }
            }
        }