Example #1
0
        GlowContainer Model.IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(Model.Function element, ElementToGlowOptions state)
        {
            var glow         = new GlowQualifiedFunction(element.Path);
            var dirFieldMask = state.DirFieldMask;

            if (dirFieldMask.HasBits(GlowFieldFlags.Identifier))
            {
                glow.Identifier = element.Identifier;
            }

            if (dirFieldMask.HasBits(GlowFieldFlags.Description) &&
                String.IsNullOrEmpty(element.Description) == false)
            {
                glow.Description = element.Description;
            }

            if (dirFieldMask == GlowFieldFlags.All)
            {
                if (element.Arguments != null)
                {
                    var tupleItemDescs = from tuple in element.Arguments
                                         select new GlowTupleItemDescription(tuple.Item2)
                    {
                        Name = tuple.Item1
                    };
                    var arguments = glow.EnsureArguments();

                    foreach (var tupleItemDesc in tupleItemDescs)
                    {
                        arguments.Insert(tupleItemDesc);
                    }
                }

                if (element.Result != null)
                {
                    var tupleItemDescs = from tuple in element.Result
                                         select new GlowTupleItemDescription(tuple.Item2)
                    {
                        Name = tuple.Item1
                    };
                    var result = glow.EnsureResult();

                    foreach (var tupleItemDesc in tupleItemDescs)
                    {
                        result.Insert(tupleItemDesc);
                    }
                }
            }

            return(glow);
        }
Example #2
0
        void Test_Functions()
        {
            Action <EmberSequence, string> fillTupleDescription =
                (sequence, namePrefix) =>
            {
                sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Integer)
                {
                    Name = namePrefix + "1:integer"
                });
                sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Boolean)
                {
                    Name = namePrefix + "2:boolean"
                });
                sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Octets)
                {
                    Name = namePrefix + "3:octets"
                });
                sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Real)
                {
                    Name = namePrefix + "4:real"
                });
                sequence.Insert(new GlowTupleItemDescription(GlowParameterType.String)
                {
                    Name = namePrefix + "5:string"
                });
            };

            // --------------- Invocation Command
            var glowCommand = new GlowCommand(GlowCommandType.Invoke)
            {
                Invocation = new GlowInvocation(GlowTags.Command.Invocation)
                {
                    InvocationId = 123,
                },
            };

            var argsTuple = glowCommand.Invocation.EnsureArguments();

            argsTuple.Insert(new IntegerEmberLeaf(GlowTags.CollectionItem, 456));
            argsTuple.Insert(new BooleanEmberLeaf(GlowTags.CollectionItem, true));
            argsTuple.Insert(new OctetStringEmberLeaf(GlowTags.CollectionItem, new byte[] { 250, 251, 253 }));
            argsTuple.Insert(new RealEmberLeaf(GlowTags.CollectionItem, 123.321));
            argsTuple.Insert(new StringEmberLeaf(GlowTags.CollectionItem, "hallo"));

            AssertCodecSanity(glowCommand);
            Console.WriteLine(GetGlowXml(glowCommand));

            // --------------- Function
            var glowFunction = new GlowFunction(100)
            {
                Identifier  = "testFunction",
                Description = "Test Function",
            };

            fillTupleDescription(glowFunction.EnsureArguments(), "arg");
            fillTupleDescription(glowFunction.EnsureResult(), "res");
            glowFunction.EnsureChildren().Insert(glowCommand);

            AssertCodecSanity(glowFunction);
            Console.WriteLine(GetXml(glowFunction));

            // --------------- QualifiedFunction
            var glowQualifiedFunction = new GlowQualifiedFunction(new[] { 1, 2, 3 })
            {
                Identifier  = "testFunction",
                Description = "Test Function",
            };

            fillTupleDescription(glowQualifiedFunction.EnsureArguments(), "arg");
            fillTupleDescription(glowQualifiedFunction.EnsureResult(), "res");
            glowQualifiedFunction.EnsureChildren().Insert(glowCommand);

            AssertCodecSanity(glowQualifiedFunction);
            Console.WriteLine(GetXml(glowQualifiedFunction));

            var glowRoot = GlowRootElementCollection.CreateRoot();

            glowRoot.Insert(glowQualifiedFunction);
            AssertGlowXmlSanity(glowRoot);

            // --------------- InvocationResult
            var glowInvocationResult = GlowInvocationResult.CreateRoot(glowCommand.Invocation.InvocationId.Value);
            var resTuple             = glowInvocationResult.EnsureResult();

            resTuple.Insert(new IntegerEmberLeaf(GlowTags.CollectionItem, 456));
            resTuple.Insert(new BooleanEmberLeaf(GlowTags.CollectionItem, true));
            resTuple.Insert(new OctetStringEmberLeaf(GlowTags.CollectionItem, new byte[] { 250, 251, 253 }));
            resTuple.Insert(new RealEmberLeaf(GlowTags.CollectionItem, 123.321));
            resTuple.Insert(new StringEmberLeaf(GlowTags.CollectionItem, "hallo"));

            AssertCodecSanity(glowInvocationResult);
            Console.WriteLine(GetXml(glowInvocationResult));

            AssertGlowXmlSanity(glowInvocationResult);
        }
Example #3
0
        void Test_Functions()
        {
            Action<EmberSequence, string> fillTupleDescription =
            (sequence, namePrefix) =>
            {
               sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Integer) { Name = namePrefix + "1:integer" });
               sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Boolean) { Name = namePrefix + "2:boolean" });
               sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Octets) { Name = namePrefix + "3:octets" });
               sequence.Insert(new GlowTupleItemDescription(GlowParameterType.Real) { Name = namePrefix + "4:real" });
               sequence.Insert(new GlowTupleItemDescription(GlowParameterType.String) { Name = namePrefix + "5:string" });
            };

             // --------------- Invocation Command
             var glowCommand = new GlowCommand(GlowCommandType.Invoke)
             {
            Invocation = new GlowInvocation(GlowTags.Command.Invocation)
            {
               InvocationId = 123,
            },
             };

             var argsTuple = glowCommand.Invocation.EnsureArguments();
             argsTuple.Insert(new IntegerEmberLeaf(GlowTags.CollectionItem, 456));
             argsTuple.Insert(new BooleanEmberLeaf(GlowTags.CollectionItem, true));
             argsTuple.Insert(new OctetStringEmberLeaf(GlowTags.CollectionItem, new byte[] { 250, 251, 253 }));
             argsTuple.Insert(new RealEmberLeaf(GlowTags.CollectionItem, 123.321));
             argsTuple.Insert(new StringEmberLeaf(GlowTags.CollectionItem, "hallo"));

             AssertCodecSanity(glowCommand);
             Console.WriteLine(GetGlowXml(glowCommand));

             // --------------- Function
             var glowFunction = new GlowFunction(100)
             {
            Identifier = "testFunction",
            Description = "Test Function",
             };

             fillTupleDescription(glowFunction.EnsureArguments(), "arg");
             fillTupleDescription(glowFunction.EnsureResult(), "res");
             glowFunction.EnsureChildren().Insert(glowCommand);

             AssertCodecSanity(glowFunction);
             Console.WriteLine(GetXml(glowFunction));

             // --------------- QualifiedFunction
             var glowQualifiedFunction = new GlowQualifiedFunction(new[] { 1, 2, 3 })
             {
            Identifier = "testFunction",
            Description = "Test Function",
             };

             fillTupleDescription(glowQualifiedFunction.EnsureArguments(), "arg");
             fillTupleDescription(glowQualifiedFunction.EnsureResult(), "res");
             glowQualifiedFunction.EnsureChildren().Insert(glowCommand);

             AssertCodecSanity(glowQualifiedFunction);
             Console.WriteLine(GetXml(glowQualifiedFunction));

             var glowRoot = GlowRootElementCollection.CreateRoot();
             glowRoot.Insert(glowQualifiedFunction);
             AssertGlowXmlSanity(glowRoot);

             // --------------- InvocationResult
             var glowInvocationResult = GlowInvocationResult.CreateRoot(glowCommand.Invocation.InvocationId.Value);
             var resTuple = glowInvocationResult.EnsureResult();
             resTuple.Insert(new IntegerEmberLeaf(GlowTags.CollectionItem, 456));
             resTuple.Insert(new BooleanEmberLeaf(GlowTags.CollectionItem, true));
             resTuple.Insert(new OctetStringEmberLeaf(GlowTags.CollectionItem, new byte[] { 250, 251, 253 }));
             resTuple.Insert(new RealEmberLeaf(GlowTags.CollectionItem, 123.321));
             resTuple.Insert(new StringEmberLeaf(GlowTags.CollectionItem, "hallo"));

             AssertCodecSanity(glowInvocationResult);
             Console.WriteLine(GetXml(glowInvocationResult));

             AssertGlowXmlSanity(glowInvocationResult);
        }