Ejemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private static IReadOnlyList <MatrixLabel> ReadLabels(EmberReader reader)
        {
            reader.AssertInnerNumber(GlowLabelCollection.InnerNumber);
            var result = new List <MatrixLabel>();

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowLabelCollection.Label.OuterNumber:
                    reader.AssertInnerNumber(GlowLabel.InnerNumber);

                    int[]  basePath    = null;
                    string description = null;

                    while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
                    {
                        switch (reader.GetContextSpecificOuterNumber())
                        {
                        case GlowLabel.BasePath.OuterNumber:
                            basePath = reader.AssertAndReadContentsAsInt32Array();
                            break;

                        case GlowLabel.Description.OuterNumber:
                            description = reader.AssertAndReadContentsAsString();
                            break;

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

                    if ((basePath != null) && (description != null))
                    {
                        result.Add(new MatrixLabel(basePath, description));
                    }

                    break;

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

            return(result);
        }
Ejemplo n.º 2
0
        internal override RetrievalState ReadContents(EmberReader reader, ElementType actualType)
        {
            this.AssertElementType(ElementType.Node, actualType);

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowNodeContents.Description.OuterNumber:
                    this.Description = reader.AssertAndReadContentsAsString();
                    break;

                case GlowNodeContents.IsRoot.OuterNumber:
                    this.IsRoot = reader.AssertAndReadContentsAsBoolean();
                    break;

                case GlowNodeContents.IsOnline.OuterNumber:
                    this.IsOnline        = reader.AssertAndReadContentsAsBoolean();
                    this.RetrievalState &= RetrievalState.Complete;
                    break;

                case GlowNodeContents.SchemaIdentifiers.OuterNumber:
                    this.ReadSchemaIdentifiers(reader);
                    break;

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

            return(this.RetrievalState);
        }
        private void ReadResult(EmberReader reader)
        {
            int index;

            for (index = 0; reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer);)
            {
                if (reader.GetContextSpecificOuterNumber() == GlowTuple.Value.OuterNumber)
                {
                    if (index >= this.valueReaders.Length)
                    {
                        throw this.CreateSignatureMismatchException();
                    }

                    this.valueReaders[index].ReadValue(reader);
                    ++index;
                }
                else
                {
                    reader.Skip();
                }
            }

            if (index < this.valueReaders.Length)
            {
                throw this.CreateSignatureMismatchException();
            }
        }
Ejemplo n.º 4
0
        private IReadOnlyList <int> ReadSignals(
            EmberReader reader,
            IReadOnlyList <int> signals,
            int outerNumber,
            int innerNumber,
            int numberOuterNumber,
            string numberName)
        {
            List <int> result = new List <int>();

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                if (reader.GetContextSpecificOuterNumber() == outerNumber)
                {
                    reader.AssertInnerNumber(innerNumber);

                    while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
                    {
                        if (reader.GetContextSpecificOuterNumber() == numberOuterNumber)
                        {
                            result.Add(this.ReadInt(reader, numberName));
                        }
                        else
                        {
                            reader.Skip();
                        }
                    }
                }
                else
                {
                    reader.Skip();
                }
            }

            if (signals.Count != result.Count)
            {
                throw new ModelException("Inconsistent source or target counts in matrix.");
            }

            return(result);
        }
Ejemplo n.º 5
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);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void ReadStreamCollection(
            EmberReader reader, IReadOnlyDictionary <int, IEnumerable <IStreamedParameter> > streamedParameters)
        {
            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowStreamCollection.StreamEntry.OuterNumber:
                    ReadStreamEntry(reader, streamedParameters);
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
        }
        private void ReadChild(EmberReader reader, ElementType actualType, int number)
        {
            var     childRetrievalState = RetrievalState.Complete;
            Element child;

            this.children.TryGetValue(number, out child);

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                var contextSpecificOuterNumber = reader.GetContextSpecificOuterNumber();

                if (contextSpecificOuterNumber == GlowNode.Contents.OuterNumber)
                {
                    this.ReadChildContents(reader, actualType, number, ref child, out childRetrievalState);
                }
                else
                {
                    if (child == null)
                    {
                        reader.Skip();
                    }
                    else
                    {
                        if (contextSpecificOuterNumber == GlowNode.Children.OuterNumber)
                        {
                            reader.AssertInnerNumber(GlowElementCollection.InnerNumber);
                            childRetrievalState = child.ReadChildren(reader);
                        }
                        else
                        {
                            childRetrievalState = child.ReadAdditionalField(reader, contextSpecificOuterNumber);
                        }
                    }
                }
            }

            if (child != null)
            {
                child.RetrievalState = childRetrievalState;
            }

            this.RetrievalState =
                (this.children.Count == 0 ? RetrievalState.Complete : this.RetrievalState) & childRetrievalState;
        }
Ejemplo n.º 8
0
        internal override RetrievalState ReadContents(EmberReader reader, ElementType actualType)
        {
            this.AssertElementType(ElementType.Function, actualType);
            var isEmpty       = true;
            var argumentsRead = false;
            var resultRead    = false;

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                isEmpty = false;

                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowFunctionContents.Description.OuterNumber:
                    this.Description = reader.AssertAndReadContentsAsString();
                    break;

                case GlowFunctionContents.Arguments.OuterNumber:
                    this.arguments = this.ReadTupleDescription(reader, this.arguments);
                    argumentsRead  = true;
                    break;

                case GlowFunctionContents.Result.OuterNumber:
                    this.result = this.ReadTupleDescription(reader, this.result);
                    resultRead  = true;
                    break;

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

            if (!isEmpty &&
                ((!argumentsRead && (this.arguments.Length > 0)) || (!resultRead && (this.result.Length > 0))))
            {
                throw this.CreateSignatureMismatchException();
            }

            return(RetrievalState.Complete);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        internal int ReadTupleDescription(
            EmberReader reader,
            KeyValuePair <string, ParameterType>[] expectedTypes,
            Action <int, KeyValuePair <string, ParameterType> > addItem)
        {
            reader.AssertInnerNumber(GlowTupleDescription.InnerNumber);
            int index;

            for (index = 0; reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer);)
            {
                if (reader.GetContextSpecificOuterNumber() == GlowTupleDescription.TupleItemDescription.OuterNumber)
                {
                    addItem(index, this.ReadTupleItemDescription(reader, expectedTypes, index));
                    ++index;
                }
                else
                {
                    reader.Skip();
                }
            }

            return(index);
        }
Ejemplo n.º 11
0
        internal virtual KeyValuePair <string, ParameterType> ReadTupleItemDescription(
            EmberReader reader, KeyValuePair <string, ParameterType>[] expectedTypes, int index)
        {
            reader.AssertInnerNumber(GlowTupleItemDescription.InnerNumber);
            reader.ReadAndAssertOuter(GlowTupleItemDescription.Type.OuterId);
            var    type = this.ReadEnum <ParameterType>(reader, GlowTupleItemDescription.Type.Name);
            string name = null;

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowTupleItemDescription.TheName.OuterNumber:
                    name = reader.AssertAndReadContentsAsString();
                    break;

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

            return(new KeyValuePair <string, ParameterType>(name, type));
        }
Ejemplo n.º 12
0
        internal override RetrievalState ReadContents(EmberReader reader, ElementType actualType)
        {
            this.AssertElementType(ElementType.Parameter, actualType);

            ParameterType?valueType = null;
            ParameterType?enumType  = null;
            ParameterType?typeType  = null;

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                ParameterType?dummyType;

                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowParameterContents.Description.OuterNumber:
                    this.Description = reader.AssertAndReadContentsAsString();
                    break;

                case GlowParameterContents.Value.OuterNumber:
                    this.SetProviderValue(this.ReadValue(reader, out valueType));
                    break;

                case GlowParameterContents.Minimum.OuterNumber:
                    this.SetMinimum(this.ReadValue(reader, out dummyType));
                    break;

                case GlowParameterContents.Maximum.OuterNumber:
                    this.SetMaximum(this.ReadValue(reader, out dummyType));
                    break;

                case GlowParameterContents.Access.OuterNumber:
                    this.Access = this.ReadEnum <ParameterAccess>(reader, GlowParameterContents.Access.Name);
                    break;

                case GlowParameterContents.Format.OuterNumber:
                    this.Format = reader.AssertAndReadContentsAsString();
                    break;

                case GlowParameterContents.Enumeration.OuterNumber:
                    this.EnumMapCore = ReadEnumeration(reader);
                    enumType         = ParameterType.Enum;
                    break;

                case GlowParameterContents.Factor.OuterNumber:
                    this.FactorCore = this.ReadInt(reader, GlowParameterContents.Factor.Name);
                    break;

                case GlowParameterContents.IsOnline.OuterNumber:
                    this.IsOnline = reader.AssertAndReadContentsAsBoolean();
                    var send = (this.RetrieveDetailsChangeStatus == RetrieveDetailsChangeStatus.Changed) &&
                               this.RetrieveDetails && this.StreamIdentifier.HasValue;
                    this.RetrievalState &= send ? RetrievalState.None : RetrievalState.Complete;
                    break;

                case GlowParameterContents.Formula.OuterNumber:
                    this.FormulaCore = reader.AssertAndReadContentsAsString();
                    break;

                case GlowParameterContents.Step.OuterNumber:
                    this.ReadInt(reader, GlowParameterContents.Step.Name);
                    break;

                case GlowParameterContents.Default.OuterNumber:
                    this.DefaultValue = this.ReadValue(reader, out dummyType);
                    break;

                case GlowParameterContents.Type.OuterNumber:
                    typeType = this.ReadEnum <ParameterType>(reader, GlowParameterContents.Type.Name);
                    break;

                case GlowParameterContents.StreamIdentifier.OuterNumber:
                    this.StreamIdentifier = this.ReadInt(reader, GlowParameterContents.StreamIdentifier.Name);
                    break;

                case GlowParameterContents.EnumMap.OuterNumber:
                    this.EnumMapCore = this.ReadEnumMap(reader);
                    enumType         = ParameterType.Enum;
                    break;

                case GlowParameterContents.StreamDescriptor.OuterNumber:
                    this.StreamDescriptor = this.ReadStreamDescriptor(reader);
                    break;

                case GlowParameterContents.SchemaIdentifiers.OuterNumber:
                    this.ReadSchemaIdentifiers(reader);
                    break;

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

            this.SetFinalTytpe(valueType, enumType, typeType);
            return(this.RetrievalState);
        }
Ejemplo n.º 13
0
        private void ReadConnections(EmberReader reader)
        {
            reader.AssertInnerNumber(GlowConnectionCollection.InnerNumber);

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowConnectionCollection.Connection.OuterNumber:
                    reader.AssertInnerNumber(GlowConnection.InnerNumber);
                    int?  target                      = null;
                    int[] connectedSources            = new int[0];
                    ConnectionOperation   operation   = ConnectionOperation.Absolute;
                    ConnectionDisposition disposition = ConnectionDisposition.Tally;

                    while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
                    {
                        switch (reader.GetContextSpecificOuterNumber())
                        {
                        case GlowConnection.Target.OuterNumber:
                            target = this.ReadInt(reader, GlowConnection.Target.Name);
                            break;

                        case GlowConnection.Sources.OuterNumber:
                            connectedSources = reader.AssertAndReadContentsAsInt32Array();
                            break;

                        case GlowConnection.Operation.OuterNumber:
                            operation =
                                this.ReadEnum <ConnectionOperation>(reader, GlowConnection.Operation.Name);
                            break;

                        case GlowConnection.Disposition.OuterNumber:
                            disposition =
                                this.ReadEnum <ConnectionDisposition>(reader, GlowConnection.Disposition.Name);
                            break;

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

                    if (target.HasValue && (disposition != ConnectionDisposition.Pending) && !this.HasChanges)
                    {
                        var existingConnectedSources = this.Connections[target.Value];

                        switch (operation)
                        {
                        case ConnectionOperation.Absolute:
                            Insert(existingConnectedSources, connectedSources, true);
                            break;

                        case ConnectionOperation.Connect:
                            Insert(existingConnectedSources, connectedSources, false);
                            break;

                        case ConnectionOperation.Disconnect:
                            foreach (var source in connectedSources)
                            {
                                existingConnectedSources.Remove(source);
                            }

                            break;
                        }
                    }

                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
        }
Ejemplo n.º 14
0
        internal sealed override RetrievalState ReadContents(EmberReader reader, ElementType actualType)
        {
            this.AssertElementType(ElementType.Matrix, actualType);
            var addressingMode = MatrixAddressingMode.Linear;

            while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
            {
                switch (reader.GetContextSpecificOuterNumber())
                {
                case GlowMatrixContents.Description.OuterNumber:
                    this.Description = reader.AssertAndReadContentsAsString();
                    break;

                case GlowMatrixContents.Type.OuterNumber:
                    this.type = this.ReadEnum <MatrixType>(reader, GlowMatrixContents.Type.Name);
                    break;

                case GlowMatrixContents.AddressingMode.OuterNumber:
                    addressingMode =
                        this.ReadEnum <MatrixAddressingMode>(reader, GlowMatrixContents.AddressingMode.Name);
                    break;

                case GlowMatrixContents.TargetCount.OuterNumber:
                    this.Targets =
                        Enumerable.Range(0, this.ReadInt(reader, GlowMatrixContents.TargetCount.Name)).ToList();
                    break;

                case GlowMatrixContents.SourceCount.OuterNumber:
                    this.Sources =
                        Enumerable.Range(0, this.ReadInt(reader, GlowMatrixContents.SourceCount.Name)).ToList();
                    break;

                case GlowMatrixContents.MaximumTotalConnects.OuterNumber:
                    this.MaximumTotalConnects = this.ReadInt(reader, GlowMatrixContents.MaximumTotalConnects.Name);
                    break;

                case GlowMatrixContents.MaximumConnectsPerTarget.OuterNumber:
                    this.MaximumConnectsPerTarget =
                        this.ReadInt(reader, GlowMatrixContents.MaximumConnectsPerTarget.Name);
                    break;

                case GlowMatrixContents.ParametersLocation.OuterNumber:
                    this.ParametersLocation = this.ReadParametersLocation(reader);
                    break;

                case GlowMatrixContents.GainParameterNumber.OuterNumber:
                    this.GainParameterNumber = this.ReadInt(reader, GlowMatrixContents.GainParameterNumber.Name);
                    break;

                case GlowMatrixContents.Labels.OuterNumber:
                    this.Labels = ReadLabels(reader);
                    break;

                case GlowMatrixContents.SchemaIdentifiers.OuterNumber:
                    this.ReadSchemaIdentifiers(reader);
                    break;

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

            return(this.RetrievalState);
        }