EmberSequence ConvertTupleDescription(BerTag tag, XElement xml) { var ember = new EmberSequence(tag); foreach (var itemsXml in xml.Elements("TupleItemDescription")) { var glowItem = new GlowTupleItemDescription(0, GlowTags.CollectionItem); var typeXml = itemsXml.Element("type"); if (typeXml != null) { var type = ConvertParameterType(typeXml.Value); if (type != null) { glowItem.Type = type.Value; } } itemsXml.Element("name").Do(value => glowItem.Name = value); ember.Insert(glowItem); } return(ember); }
GlowMatrixBase MatrixToGlow(Matrix matrix, ElementToGlowOptions options) { var dirFieldMask = options.DirFieldMask; var glow = new GlowQualifiedMatrix(matrix.Path) { Identifier = matrix.Identifier, TargetCount = matrix.TargetCount, SourceCount = matrix.SourceCount, }; if (dirFieldMask.HasBits(GlowFieldFlags.Description) && String.IsNullOrEmpty(matrix.Description) == false) { glow.Description = matrix.Description; } if (matrix.LabelsNode != null && dirFieldMask == GlowFieldFlags.All) { var labels = new EmberSequence(GlowTags.MatrixContents.Labels); labels.Insert(new GlowLabel { BasePath = matrix.LabelsNode.Path, Description = "Primary" }); glow.Labels = labels; } if (dirFieldMask.HasBits(GlowFieldFlags.Connections) && options.IsCompleteMatrixEnquired) { var glowConnections = glow.EnsureConnections(); foreach (var signal in matrix.Targets) { var glowConnection = new GlowConnection(signal.Number); if (signal.ConnectedSources.Any()) { glowConnection.Sources = signal.ConnectedSources.Select(source => source.Number).ToArray(); } glowConnections.Insert(glowConnection); } } if ((dirFieldMask == GlowFieldFlags.All) && String.IsNullOrEmpty(matrix.SchemaIdentifier) == false) { glow.SchemaIdentifiers = matrix.SchemaIdentifier; } return(glow); }
void FillMatrix(GlowMatrixBase glow, XElement xml) { var contentsXml = xml.Element("contents"); if(contentsXml != null) { contentsXml.Element("identifier").Do(value => glow.Identifier = value); contentsXml.Element("description").Do(value => glow.Description = value); contentsXml.Element("type").Do(value => glow.MatrixType = XmlConvert.ToInt32(value)); contentsXml.Element("addressingMode").Do(value => glow.AddressingMode = XmlConvert.ToInt32(value)); contentsXml.Element("targetCount").Do(value => glow.TargetCount = XmlConvert.ToInt32(value)); contentsXml.Element("sourceCount").Do(value => glow.SourceCount = XmlConvert.ToInt32(value)); contentsXml.Element("maximumTotalConnects").Do(value => glow.MaximumTotalConnects = XmlConvert.ToInt32(value)); contentsXml.Element("maximumConnectsPerTarget").Do(value => glow.MaximumConnectsPerTarget = XmlConvert.ToInt32(value)); var parametersLocationXml = contentsXml.Element("parametersLocation"); if(parametersLocationXml != null) { var attrib = parametersLocationXml.Attribute("type"); if(attrib.Value == "RELATIVE-OID") { glow.ParametersLocation = new GlowParametersLocation(ConvertPath(parametersLocationXml.Value)); } else if(attrib.Value == "INTEGER") { glow.ParametersLocation = new GlowParametersLocation(XmlConvert.ToInt32(parametersLocationXml.Value)); } } contentsXml.Element("gainParameterNumber").Do(value => glow.GainParameterNumber = XmlConvert.ToInt32(value)); var labelsXml = contentsXml.Element("labels"); if(labelsXml != null) { var glowLabels = from xmlChild in labelsXml.Elements("Label") select new GlowLabel { BasePath = ConvertPath(xmlChild.Attribute("basePath").Value), Description = xmlChild.Attribute("description").Value, }; var glowLabelsCollection = new EmberSequence(GlowTags.MatrixContents.Labels); foreach(var glowLabel in glowLabels) glowLabelsCollection.Insert(glowLabel); glow.Labels = glowLabelsCollection; } } var childrenXml = xml.Element("children"); if(childrenXml != null) FillElementCollection(glow.EnsureChildren(), childrenXml); var targetsXml = xml.Element("targets"); if(targetsXml != null) { var glowTargets = from xmlChild in targetsXml.Elements("Target") select new GlowTarget(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureTargets(); foreach(var glowTarget in glowTargets) collection.Insert(glowTarget); } var sourcesXml = xml.Element("sources"); if(sourcesXml != null) { var glowSources = from xmlChild in sourcesXml.Elements("Source") select new GlowSource(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureSources(); foreach(var glowSource in glowSources) collection.Insert(glowSource); } var connectionsXml = xml.Element("connections"); if(connectionsXml != null) { var collection = glow.EnsureConnections(); foreach(var xmlChild in connectionsXml.Elements("Connection")) { var glowConnection = new GlowConnection(XmlConvert.ToInt32(xmlChild.Attribute("target").Value)); xmlChild.Element("sources").Do(value => glowConnection.Sources = ConvertPath(value)); xmlChild.Element("operation").Do(value => glowConnection.Operation = XmlConvert.ToInt32(value)); xmlChild.Element("disposition").Do(value => glowConnection.Disposition = XmlConvert.ToInt32(value)); collection.Insert(glowConnection); } } }
EmberSequence ConvertTupleDescription(BerTag tag, XElement xml) { var ember = new EmberSequence(tag); foreach(var itemsXml in xml.Elements("TupleItemDescription")) { var glowItem = new GlowTupleItemDescription(0, GlowTags.CollectionItem); var typeXml = itemsXml.Element("type"); if(typeXml != null) { var type = ConvertParameterType(typeXml.Value); if(type != null) glowItem.Type = type.Value; } itemsXml.Element("name").Do(value => glowItem.Name = value); ember.Insert(glowItem); } return ember; }
void Test_DOM() { Console.WriteLine("\r\n------------------------ DOM"); EmberContainer container1; EmberContainer frame = new EmberFrame(); container1 = new EmberSet(new BerTag(DefaultClass, 0)); container1.Insert(new BerTag(DefaultClass, 0), -1); container1.Insert(new BerTag(DefaultClass, 1), 128); container1.Insert(new BerTag(DefaultClass, 2), -128); container1.Insert(new BerTag(DefaultClass, 3), 255); container1.Insert(new BerTag(DefaultClass, 4), -255); container1.Insert(new BerTag(DefaultClass, 5), 12345); container1.Insert(new BerTag(DefaultClass, 6), -12345); container1.Insert(new BerTag(DefaultClass, 7), 16384); container1.Insert(new BerTag(DefaultClass, 8), -16384); container1.Insert(new BerTag(DefaultClass, 9), 65535); container1.Insert(new BerTag(DefaultClass, 10), -65535); container1.Insert(new BerTag(DefaultClass, 11), 0); container1.Insert(new BerTag(DefaultClass, 12), 127); container1.Insert(new BerTag(DefaultClass, 13), -127); container1.Insert(new BerTag(DefaultClass, 1111222), 0xFFFFFFFF); container1.InsertOid(new BerTag(DefaultClass, 14), new int[] { 1, 3, 6, 0 }); container1.InsertOid(new BerTag(DefaultClass, 15), new int[] { 1 }); container1.InsertRelativeOid(new BerTag(DefaultClass, 16), new int[] { 1, 2, 3, 4, 5, 6 }); frame.Insert(container1); container1 = new EmberSequence(new BerTag(DefaultClass, 1)); container1.Insert(new BerTag(DefaultClass, 3), -0.54321); container1.Insert(new BerTag(DefaultClass, 5), "Wuppdich"); var appDefined = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.Application, 889), 2, container1); appDefined.Insert(new BerTag(DefaultClass, 100), true); frame.Insert(container1); var xml1 = GetXml(frame); var output = new BerMemoryOutput(); frame.Encode(output); var memory = output.ToArray(); using (var stream = new FileStream(@"N:\Temp\test.ber", FileMode.Create, FileAccess.Write)) stream.Write(memory, 0, memory.Length); var input = new BerMemoryInput(memory); var stopwatch = new Stopwatch(); stopwatch.Start(); var asyncReader = new AsyncFrameReader(this); asyncReader.ReadBytes(output.Memory); var loadedFrame = asyncReader.DetachRoot(); stopwatch.Stop(); Console.WriteLine("load tree: {0}ms", stopwatch.ElapsedMilliseconds); var xml2 = GetXml(loadedFrame); Console.WriteLine(xml1); Console.WriteLine(xml2); Debug.Assert(xml1 == xml2); }
void FillMatrix(GlowMatrixBase glow, XElement xml) { var contentsXml = xml.Element("contents"); if (contentsXml != null) { contentsXml.Element("identifier").Do(value => glow.Identifier = value); contentsXml.Element("description").Do(value => glow.Description = value); contentsXml.Element("type").Do(value => glow.MatrixType = XmlConvert.ToInt32(value)); contentsXml.Element("addressingMode").Do(value => glow.AddressingMode = XmlConvert.ToInt32(value)); contentsXml.Element("targetCount").Do(value => glow.TargetCount = XmlConvert.ToInt32(value)); contentsXml.Element("sourceCount").Do(value => glow.SourceCount = XmlConvert.ToInt32(value)); contentsXml.Element("maximumTotalConnects").Do(value => glow.MaximumTotalConnects = XmlConvert.ToInt32(value)); contentsXml.Element("maximumConnectsPerTarget").Do(value => glow.MaximumConnectsPerTarget = XmlConvert.ToInt32(value)); var parametersLocationXml = contentsXml.Element("parametersLocation"); if (parametersLocationXml != null) { var attrib = parametersLocationXml.Attribute("type"); if (attrib.Value == "RELATIVE-OID") { glow.ParametersLocation = new GlowParametersLocation(ConvertPath(parametersLocationXml.Value)); } else if (attrib.Value == "INTEGER") { glow.ParametersLocation = new GlowParametersLocation(XmlConvert.ToInt32(parametersLocationXml.Value)); } } contentsXml.Element("gainParameterNumber").Do(value => glow.GainParameterNumber = XmlConvert.ToInt32(value)); var labelsXml = contentsXml.Element("labels"); if (labelsXml != null) { var glowLabels = from xmlChild in labelsXml.Elements("Label") select new GlowLabel { BasePath = ConvertPath(xmlChild.Attribute("basePath").Value), Description = xmlChild.Attribute("description").Value, }; var glowLabelsCollection = new EmberSequence(GlowTags.MatrixContents.Labels); foreach (var glowLabel in glowLabels) { glowLabelsCollection.Insert(glowLabel); } glow.Labels = glowLabelsCollection; } } var childrenXml = xml.Element("children"); if (childrenXml != null) { FillElementCollection(glow.EnsureChildren(), childrenXml); } var targetsXml = xml.Element("targets"); if (targetsXml != null) { var glowTargets = from xmlChild in targetsXml.Elements("Target") select new GlowTarget(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureTargets(); foreach (var glowTarget in glowTargets) { collection.Insert(glowTarget); } } var sourcesXml = xml.Element("sources"); if (sourcesXml != null) { var glowSources = from xmlChild in sourcesXml.Elements("Source") select new GlowSource(XmlConvert.ToInt32(xmlChild.Attribute("number").Value)); var collection = glow.EnsureSources(); foreach (var glowSource in glowSources) { collection.Insert(glowSource); } } var connectionsXml = xml.Element("connections"); if (connectionsXml != null) { var collection = glow.EnsureConnections(); foreach (var xmlChild in connectionsXml.Elements("Connection")) { var glowConnection = new GlowConnection(XmlConvert.ToInt32(xmlChild.Attribute("target").Value)); xmlChild.Element("sources").Do(value => glowConnection.Sources = ConvertPath(value)); xmlChild.Element("operation").Do(value => glowConnection.Operation = XmlConvert.ToInt32(value)); xmlChild.Element("disposition").Do(value => glowConnection.Disposition = XmlConvert.ToInt32(value)); collection.Insert(glowConnection); } } }
void Test_DOM() { Console.WriteLine("\r\n------------------------ DOM"); EmberContainer container1; EmberContainer frame = new EmberFrame(); container1 = new EmberSet(new BerTag(DefaultClass, 0)); container1.Insert(new BerTag(DefaultClass, 0), -1); container1.Insert(new BerTag(DefaultClass, 1), 128); container1.Insert(new BerTag(DefaultClass, 2), -128); container1.Insert(new BerTag(DefaultClass, 3), 255); container1.Insert(new BerTag(DefaultClass, 4), -255); container1.Insert(new BerTag(DefaultClass, 5), 12345); container1.Insert(new BerTag(DefaultClass, 6), -12345); container1.Insert(new BerTag(DefaultClass, 7), 16384); container1.Insert(new BerTag(DefaultClass, 8), -16384); container1.Insert(new BerTag(DefaultClass, 9), 65535); container1.Insert(new BerTag(DefaultClass, 10), -65535); container1.Insert(new BerTag(DefaultClass, 11), 0); container1.Insert(new BerTag(DefaultClass, 12), 127); container1.Insert(new BerTag(DefaultClass, 13), -127); container1.Insert(new BerTag(DefaultClass, 1111222), 0xFFFFFFFF); container1.InsertOid(new BerTag(DefaultClass, 14), new int[] { 1, 3, 6, 0 }); container1.InsertOid(new BerTag(DefaultClass, 15), new int[] { 1 }); container1.InsertRelativeOid(new BerTag(DefaultClass, 16), new int[] { 1, 2, 3, 4, 5, 6 }); frame.Insert(container1); container1 = new EmberSequence(new BerTag(DefaultClass, 1)); container1.Insert(new BerTag(DefaultClass, 3), -0.54321); container1.Insert(new BerTag(DefaultClass, 5), "Wuppdich"); var appDefined = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.Application, 889), 2, container1); appDefined.Insert(new BerTag(DefaultClass, 100), true); frame.Insert(container1); var xml1 = GetXml(frame); var output = new BerMemoryOutput(); frame.Encode(output); var memory = output.ToArray(); using(var stream = new FileStream(@"N:\Temp\test.ber", FileMode.Create, FileAccess.Write)) stream.Write(memory, 0, memory.Length); var input = new BerMemoryInput(memory); var stopwatch = new Stopwatch(); stopwatch.Start(); var asyncReader = new AsyncFrameReader(this); asyncReader.ReadBytes(output.Memory); var loadedFrame = asyncReader.DetachRoot(); stopwatch.Stop(); Console.WriteLine("load tree: {0}ms", stopwatch.ElapsedMilliseconds); var xml2 = GetXml(loadedFrame); Console.WriteLine(xml1); Console.WriteLine(xml2); Debug.Assert(xml1 == xml2); }