예제 #1
0
 internal int ReadInt(EmberReader reader, string fieldName)
 {
     try
     {
         return(reader.AssertAndReadContentsAsInt32());
     }
     catch (ModelException ex)
     {
         const string Format =
             "The value of the field {0} is out of the allowed range for the element with the path {1}.";
         throw new ModelException(
                   string.Format(CultureInfo.InvariantCulture, Format, fieldName, this.GetPath()), ex);
     }
 }
예제 #2
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);
                    }
                }
            }
        }
예제 #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private static void ReadInvocationResult(
            EmberReader reader, IDictionary <int, IInvocationResult> pendingInvocations)
        {
            var success = true;
            IInvocationResult result = null;

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowInvocationResult.InvocationId.OuterNumber:
                    var invocationId = reader.AssertAndReadContentsAsInt32();
                    pendingInvocations.TryGetValue(invocationId, out result);
                    pendingInvocations.Remove(invocationId);
                    break;

                case GlowInvocationResult.Success.OuterNumber:
                    success = reader.ReadContentsAsBoolean();
                    break;

                case GlowInvocationResult.Result.OuterNumber:
                    if (result != null)
                    {
                        result.Read(reader);
                    }
                    else
                    {
                        reader.Skip();
                    }

                    break;

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

            result?.Publish(success);
        }
예제 #4
0
        internal T ReadEnum <T>(EmberReader reader, string fieldName)
            where T : struct
        {
            Exception exception = null;

            try
            {
                var result = FastEnum.ToEnum <T>(reader.AssertAndReadContentsAsInt32());

                if (FastEnum.IsDefined(result))
                {
                    return(result);
                }
            }
            catch (ModelException ex)
            {
                exception = ex;
            }

            const string Format = "The field {0} has an unexpected value for the element with the path {1}.";

            throw new ModelException(
                      string.Format(CultureInfo.InvariantCulture, Format, fieldName, this.GetPath()), exception);
        }
 internal void ReadChild(EmberReader reader, ElementType actualType)
 {
     reader.ReadAndAssertOuter(GlowNode.Number.OuterId);
     this.ReadChild(reader, actualType, reader.AssertAndReadContentsAsInt32());
 }