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);
        }
Beispiel #2
0
        void Test_XmlImport()
        {
            var frame       = new EmberSequence(new BerTag(BerClass.Application, 1));
            var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
            var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);

            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

            Console.WriteLine("\r\n------------------------ XML Import");
            var xml1 = GetXml(frame);

            using (var stream = new StringReader(xml1))
                using (var reader = new XmlTextReader(stream))
                {
                    var root = XmlImport.Import(reader, this);
                    var xml2 = GetXml(root);

                    Console.WriteLine(xml2);

                    Debug.Assert(xml1 == xml2);
                }
        }
Beispiel #3
0
        void Test_XmlImport()
        {
            var frame       = new EmberSequence(new BerTag(BerClass.Application, 1));
            var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
            var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);

            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

            Console.WriteLine("\r\n------------------------ XML Import");
            DumpXml(frame);

            var buffer = new StringBuilder();

            using (var writer = XmlWriter.Create(buffer))
                XmlExport.Export(frame, writer);

            using (var stream = new StringReader(buffer.ToString()))
                using (var reader = new XmlTextReader(stream))
                {
                    var root = XmlImport.Import(reader, this);

                    DumpXml(root);
                }
        }
        /// <summary>
        /// Creates a container of an application-defined type with Sequence semantics
        /// </summary>
        /// <param name="type">Application-defined type. BerType.ApplicationFlag can be omitted.</param>
        public static EmberSequence CreateApplicationDefinedSequence(BerTag tag, uint type, EmberContainer parent, bool isOrdered = false)
        {
            var sequence = new EmberSequence(tag, parent)
             {
            BerTypeNumber = type | BerType.ApplicationFlag,
            IsOrdered = isOrdered,
             };

             return sequence;
        }
Beispiel #5
0
        /// <summary>
        /// Ensures that the "connections" field is present, creating a
        /// new EmberSequence and assigning it to the "connections" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "connections" field, never null.</returns>
        public EmberSequence EnsureConnections()
        {
            var connections = Connections;

            if (connections == null)
            {
                connections = new EmberSequence(ConnectionsTag);
                Insert(connections);
            }

            return(connections);
        }
Beispiel #6
0
        /// <summary>
        /// Ensures that the "targets" field is present, creating a
        /// new EmberSequence and assigning it to the "targets" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "targets" field, never null.</returns>
        public EmberSequence EnsureTargets()
        {
            var targets = Targets;

            if (targets == null)
            {
                targets = new EmberSequence(TargetsTag);
                Insert(targets);
            }

            return(targets);
        }
Beispiel #7
0
        /// <summary>
        /// Ensures that the "arguments" field is present, creating a
        /// new EmberSequence and assigning it to the "arguments" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "arguments" field, never null.</returns>
        public EmberSequence EnsureArguments()
        {
            var arguments = Arguments;

            if (arguments == null)
            {
                arguments = new EmberSequence(GlowTags.Invocation.Arguments);
                Insert(arguments);
            }

            return(arguments);
        }
        /// <summary>
        /// Ensures that the "result" field is present, creating a
        /// new EmberSequence and assigning it to the "result" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "result" field, never null.</returns>
        public EmberSequence EnsureResult()
        {
            var result = Result;

            if (result == null)
            {
                result = new EmberSequence(GlowTags.FunctionContents.Result);
                Result = result;
            }

            return(result);
        }
        /// <summary>
        /// Ensures that the "arguments" field is present, creating a
        /// new EmberSequence and assigning it to the "arguments" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "arguments" field, never null.</returns>
        public EmberSequence EnsureArguments()
        {
            var arguments = Arguments;

            if (arguments == null)
            {
                arguments = new EmberSequence(GlowTags.FunctionContents.Arguments);
                Arguments = arguments;
            }

            return(arguments);
        }
Beispiel #10
0
        /// <summary>
        /// Ensures that the "contents.labels" field is present, creating a
        /// new EmberSequence and assigning it to the "contents.labels" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "contents.labels" field, never null.</returns>
        public EmberSequence EnsureLabels()
        {
            var labels = Labels;

            if (labels == null)
            {
                labels = new EmberSequence(GlowTags.MatrixContents.Labels);
                EnsureContents().Insert(labels);
            }

            return(labels);
        }
Beispiel #11
0
        /// <summary>
        /// Ensures that the "sources" field is present, creating a
        /// new EmberSequence and assigning it to the "sources" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "sources" field, never null.</returns>
        public EmberSequence EnsureSources()
        {
            var sources = Sources;

            if (sources == null)
            {
                sources = new EmberSequence(SourcesTag);
                Insert(sources);
            }

            return(sources);
        }
Beispiel #12
0
        /// <summary>
        /// Ensures that the "result" field is present, creating a
        /// new EmberSequence and assigning it to the "result" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "result" field, never null.</returns>
        public EmberSequence EnsureResult()
        {
            var result = Result;

            if (result == null)
            {
                result = new EmberSequence(GlowTags.InvocationResult.Result);
                Insert(result);
            }

            return(result);
        }
        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);
        }
Beispiel #14
0
        /// <summary>
        /// Ensures that the "contents.labels" field is present, creating a
        /// new EmberSequence and assigning it to the "contents.labels" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "contents.labels" field, never null.</returns>
        public EmberSequence EnsureLabels()
        {
            var labels = Labels;

             if(labels == null)
             {
            labels = new EmberSequence(GlowTags.MatrixContents.Labels);
            EnsureContents().Insert(labels);
             }

             return labels;
        }
Beispiel #15
0
        /// <summary>
        /// Ensures that the "connections" field is present, creating a
        /// new EmberSequence and assigning it to the "connections" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "connections" field, never null.</returns>
        public EmberSequence EnsureConnections()
        {
            var connections = Connections;

             if(connections == null)
             {
            connections = new EmberSequence(ConnectionsTag);
            Insert(connections);
             }

             return connections;
        }
Beispiel #16
0
        /// <summary>
        /// Ensures that the "result" field is present, creating a
        /// new EmberSequence and assigning it to the "result" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "result" field, never null.</returns>
        public EmberSequence EnsureResult()
        {
            var result = Result;

             if (result == null)
             {
            result = new EmberSequence(GlowTags.FunctionContents.Result);
            Result = result;
             }

             return result;
        }
Beispiel #17
0
        /// <summary>
        /// Ensures that the "arguments" field is present, creating a
        /// new EmberSequence and assigning it to the "arguments" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "arguments" field, never null.</returns>
        public EmberSequence EnsureArguments()
        {
            var arguments = Arguments;

             if (arguments == null)
             {
            arguments = new EmberSequence(GlowTags.FunctionContents.Arguments);
            Arguments = arguments;
             }

             return arguments;
        }
Beispiel #18
0
        EmberNode CreateNode(string tagName, string typeName)
        {
            BerTag tag;
             EmberNode node = null;

             if(BerTag.TryParse(tagName, out tag)
             && typeName != null)
             {
            uint type;

            if(BerDefinitions.GetTypeFromName(typeName, true, out type))
            {
               switch(type)
               {
                  case BerType.Boolean:
                  {
                     bool value;

                     if(bool.TryParse(_reader.ReadContentAsString(), out value))
                        node = new BooleanEmberLeaf(tag, value);

                     break;
                  }

                  case BerType.Integer:
                  {
                     long value;

                     if(long.TryParse(_reader.ReadContentAsString(), out value))
                     {
                        if((ulong)value > int.MaxValue)
                           node = new LongEmberLeaf(tag, value);
                        else
                           node = new IntegerEmberLeaf(tag, (int)value);
                     }

                     break;
                  }

                  case BerType.Real:
                  {
                     double value;

                     if(double.TryParse(_reader.ReadContentAsString(), NumberStyles.Float, XmlExport.FormatProvider, out value))
                        node = new RealEmberLeaf(tag, value);

                     break;
                  }

                  case BerType.UTF8String:
                  {
                     node = new StringEmberLeaf(tag, _reader.ReadContentAsString());
                     break;
                  }

                  case BerType.OctetString:
                  {
                     var octets = System.Convert.FromBase64String(_reader.ReadContentAsString());
                     node = new OctetStringEmberLeaf(tag, octets);
                     break;
                  }

            #pragma warning disable 618 // EmberFrame is obsolete
                  case BerType.Sequence:
                  {
                     if(tag == Legacy.EmberFrame.FrameTag)
                        node = new Legacy.EmberFrame();
                     else
                        node = new EmberSequence(tag);

                     break;
                  }
            #pragma warning restore 618

                  case BerType.Set:
                  {
                     node = new EmberSet(tag);
                     break;
                  }

                  default:
                  {
                     if(_application != null)
                        node = _application.CreateNodeFromXml(type, tag, _reader);

                     if(node == null)
                     {
                        Debug.WriteLine("Unknown BER value type: " + type);

                        node = new EmberContainer(tag, null, type);
                     }

                     break;
                  }
               }
            }
             }

             return node;
        }
        /// <summary>
        /// Creates an EmberSequence object with the passed BerType. Convenience method
        /// to be called from an overridden CreateNodeFromXml method.
        /// </summary>
        protected EmberNode CreateSequence(uint type, BerTag tag, XmlReader reader)
        {
            var node = new EmberSequence(tag, null)
             {
            BerTypeNumber = type
             };

             return node;
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        void Test_XmlImport()
        {
            var frame = new EmberSequence(new BerTag(BerClass.Application, 1));
             var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
             var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

             Console.WriteLine("\r\n------------------------ XML Import");
             DumpXml(frame);

             var buffer = new StringBuilder();
             using(var writer = XmlWriter.Create(buffer))
            XmlExport.Export(frame, writer);

             using(var stream = new StringReader(buffer.ToString()))
             using(var reader = new XmlTextReader(stream))
             {
            var root = XmlImport.Import(reader, this);

            DumpXml(root);
             }
        }
Beispiel #22
0
        EmberNode CreateNode(string tagName, string typeName)
        {
            BerTag    tag;
            EmberNode node = null;

            if (BerTag.TryParse(tagName, out tag) &&
                typeName != null)
            {
                uint type;

                if (BerDefinitions.GetTypeFromName(typeName, true, out type))
                {
                    switch (type)
                    {
                    case BerType.Null:
                    {
                        node = new NullEmberLeaf(tag);
                        break;
                    }

                    case BerType.Boolean:
                    {
                        bool value;

                        if (bool.TryParse(_reader.ReadContentAsString(), out value))
                        {
                            node = new BooleanEmberLeaf(tag, value);
                        }

                        break;
                    }

                    case BerType.Integer:
                    {
                        long value;

                        if (long.TryParse(_reader.ReadContentAsString(), out value))
                        {
                            if ((ulong)value > int.MaxValue)
                            {
                                node = new LongEmberLeaf(tag, value);
                            }
                            else
                            {
                                node = new IntegerEmberLeaf(tag, (int)value);
                            }
                        }

                        break;
                    }

                    case BerType.Real:
                    {
                        double value;

                        if (double.TryParse(_reader.ReadContentAsString(), NumberStyles.Float, XmlExport.FormatProvider, out value))
                        {
                            node = new RealEmberLeaf(tag, value);
                        }

                        break;
                    }

                    case BerType.UTF8String:
                    {
                        node = new StringEmberLeaf(tag, _reader.ReadContentAsString());
                        break;
                    }

                    case BerType.OctetString:
                    {
                        var octets = System.Convert.FromBase64String(_reader.ReadContentAsString());
                        node = new OctetStringEmberLeaf(tag, octets);
                        break;
                    }

#pragma warning disable 618 // EmberFrame is obsolete
                    case BerType.Sequence:
                    {
                        if (tag == Legacy.EmberFrame.FrameTag)
                        {
                            node = new Legacy.EmberFrame();
                        }
                        else
                        {
                            node = new EmberSequence(tag);
                        }

                        break;
                    }
#pragma warning restore 618

                    case BerType.Set:
                    {
                        node = new EmberSet(tag);
                        break;
                    }

                    default:
                    {
                        if (_application != null)
                        {
                            node = _application.CreateNodeFromXml(type, tag, _reader);
                        }

                        if (node == null)
                        {
                            Debug.WriteLine("Unknown BER value type: " + type);

                            node = new EmberContainer(tag, null, type);
                        }

                        break;
                    }
                    }
                }
            }

            return(node);
        }
        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);
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// Ensures that the "sources" field is present, creating a
        /// new EmberSequence and assigning it to the "sources" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "sources" field, never null.</returns>
        public EmberSequence EnsureSources()
        {
            var sources = Sources;

             if(sources == null)
             {
            sources = new EmberSequence(SourcesTag);
            Insert(sources);
             }

             return sources;
        }
Beispiel #25
0
        /// <summary>
        /// Ensures that the "targets" field is present, creating a
        /// new EmberSequence and assigning it to the "targets" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "targets" field, never null.</returns>
        public EmberSequence EnsureTargets()
        {
            var targets = Targets;

             if(targets == null)
             {
            targets = new EmberSequence(TargetsTag);
            Insert(targets);
             }

             return targets;
        }
Beispiel #26
0
        /// <summary>
        /// Ensures that the "arguments" field is present, creating a
        /// new EmberSequence and assigning it to the "arguments" field
        /// if necessary.
        /// </summary>
        /// <returns>The value of the "arguments" field, never null.</returns>
        public EmberSequence EnsureArguments()
        {
            var arguments = Arguments;

             if(arguments == null)
             {
            arguments = new EmberSequence(GlowTags.Invocation.Arguments);
            Insert(arguments);
             }

             return arguments;
        }
 object IEmberVisitor <XmlExportState, object> .Visit(EmberSequence node, XmlExportState state)
 {
     return(WriteContainer(node, state));
 }
Beispiel #28
0
        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);
        }
Beispiel #29
0
        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;
        }
Beispiel #30
0
        void Test_XmlImport()
        {
            var frame = new EmberSequence(new BerTag(BerClass.Application, 1));
             var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
             var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
             appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

             Console.WriteLine("\r\n------------------------ XML Import");
             var xml1 = GetXml(frame);

             using(var stream = new StringReader(xml1))
             using(var reader = new XmlTextReader(stream))
             {
            var root = XmlImport.Import(reader, this);
            var xml2 = GetXml(root);

            Console.WriteLine(xml2);

            Debug.Assert(xml1 == xml2);
             }
        }
Beispiel #31
0
        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);
            }
             }
        }
        /// <summary>
        /// Creates an EmberSequence object with the passed BerType. Convenience method
        /// to be called from an overridden CreateNodeFromReader method.
        /// </summary>
        protected EmberNode CreateSequence(uint type, BerReaderBase reader)
        {
            var tag = reader.Tag;
             var node = new EmberSequence(tag, null);

             node.BerTypeNumber = type;
             return node;
        }