//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 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); }
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); }
void EmberToXml(EmberReader reader, XmlWriter writer) { if (reader.Read()) { EmberToXml_ProcessNode(reader, writer, 0); } }
void EmberToXml_Recurse(EmberReader reader, XmlWriter writer, int indent) { while (reader.Read()) { EmberToXml_ProcessNode(reader, writer, indent); } }
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(); } }
internal sealed override bool ReadChildrenCore(EmberReader reader) { var isEmpty = true; while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer)) { switch (reader.InnerNumber) { case GlowParameter.InnerNumber: isEmpty = false; this.ReadChild(reader, ElementType.Parameter); break; case GlowNode.InnerNumber: isEmpty = false; this.ReadChild(reader, ElementType.Node); break; case GlowFunction.InnerNumber: isEmpty = false; this.ReadChild(reader, ElementType.Function); break; case GlowMatrix.InnerNumber: isEmpty = false; this.ReadChild(reader, ElementType.Matrix); break; case GlowQualifiedParameter.InnerNumber: isEmpty = false; this.ReadQualifiedChild(reader, ElementType.Parameter); break; case GlowQualifiedNode.InnerNumber: isEmpty = false; this.ReadQualifiedChild(reader, ElementType.Node); break; case GlowQualifiedFunction.InnerNumber: isEmpty = false; this.ReadQualifiedChild(reader, ElementType.Function); break; case GlowQualifiedMatrix.InnerNumber: isEmpty = false; this.ReadQualifiedChild(reader, ElementType.Matrix); break; default: reader.Skip(); break; } } return(isEmpty); }
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); }
private void ReadChildContents( EmberReader reader, ElementType actualType, int number, ref Element child, out RetrievalState childRetrievalState) { reader.AssertInnerNumber(InnerNumber.Set); if (child != null) { childRetrievalState = child.ReadContents(reader, actualType); } else { using (var stream = new MemoryStream()) using (var writer = new EmberWriter(stream)) { // Since EmberReader checks that every end of a container is matched by a start, we need to write // this dummy here. writer.WriteStartSet(GlowNode.Contents.OuterId); var identifier = reader.CopyToEndContainer(writer, GlowNodeContents.Identifier.OuterId) as string; if (identifier != null) { writer.Flush(); stream.Position = 0; using (var contentsReader = new EmberReader(stream)) { contentsReader.Read(); // Read what we have written with WriteStartSet above var newPolicy = this.childrenRetrievalPolicy == ChildrenRetrievalPolicy.All ? ChildrenRetrievalPolicy.All : ChildrenRetrievalPolicy.None; var context = new Context(this, number, identifier, newPolicy); child = this.ReadNewChildContents(contentsReader, actualType, context, out childRetrievalState); if (child != null) { this.children.Add(number, child); } } } else { childRetrievalState = RetrievalState.Complete; child = null; } } } }
private List <KeyValuePair <string, int> > ReadEnumMap(EmberReader reader) { reader.AssertInnerNumber(GlowStringIntegerCollection.InnerNumber); var result = new List <KeyValuePair <string, int> >(); while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer)) { reader.AssertInnerNumber(GlowStringIntegerPair.InnerNumber); reader.ReadAndAssertOuter(GlowStringIntegerPair.EntryString.OuterId); var entryString = reader.AssertAndReadContentsAsString(); reader.ReadAndAssertOuter(GlowStringIntegerPair.EntryInteger.OuterId); var entryInteger = this.ReadInt(reader, GlowStringIntegerPair.EntryInteger.Name); while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer)) { reader.Skip(); } result.Add(new KeyValuePair <string, int>(entryString, entryInteger)); } return(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static void AssertRead(EmberReader reader, EmberId?expectedOuter) { try { if (!reader.Read()) { const string Format = "Encountered end of stream while expecting outer identifier{0}."; throw new ModelException(string.Format(CultureInfo.InvariantCulture, Format, GetId(expectedOuter))); } } catch (EmberException ex) { const string Format = "Encountered invalid EmBER data while expecting outer identifier{0}."; throw new ModelException(string.Format(CultureInfo.InvariantCulture, Format, GetId(expectedOuter)), ex); } }
private StreamDescription ReadStreamDescriptor(EmberReader reader) { reader.AssertInnerNumber(GlowStreamDescription.InnerNumber); reader.ReadAndAssertOuter(GlowStreamDescription.Format.OuterId); var streamFormat = this.ReadEnum <StreamFormat>(reader, GlowStreamDescription.Format.Name); reader.ReadAndAssertOuter(GlowStreamDescription.Offset.OuterId); var offset = this.ReadInt(reader, GlowStreamDescription.Offset.Name); while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer)) { reader.Skip(); } return(new StreamDescription(streamFormat, offset)); }
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); } } } }
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; }
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); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 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); }
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); }
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)); }
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); }
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); }
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; } } }