Esempio n. 1
0
        GlowContainer Model.IElementVisitor <ElementToGlowOptions, GlowContainer> .Visit(Model.IntegerParameter element, ElementToGlowOptions state)
        {
            var glow         = new GlowQualifiedParameter(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.HasBits(GlowFieldFlags.Value))
            {
                glow.Value = new GlowValue(element.Value);
            }

            if (dirFieldMask == GlowFieldFlags.All)
            {
                glow.Minimum = new GlowMinMax(element.Minimum);
                glow.Maximum = new GlowMinMax(element.Maximum);

                if (element.IsWriteable)
                {
                    glow.Access = GlowAccess.ReadWrite;
                }
            }

            if ((dirFieldMask == GlowFieldFlags.All) &&
                String.IsNullOrEmpty(element.SchemaIdentifier) == false)
            {
                glow.SchemaIdentifiers = element.SchemaIdentifier;
            }

            return(glow);
        }
Esempio n. 2
0
        static void CreateIdentity(Model.Node router, int nodeNumber, Dispatcher dispatcher)
        {
            var identity      = new Model.Node(nodeNumber, router, "identity");
            var licensedParam = new Model.IntegerParameter(1, identity, "isLicensed", dispatcher, 0, 1, isWriteable: false)
            {
                Value = 0
            };

            new Model.Function(2,
                               identity,
                               "enterLicenseKey",
                               new[] { Tuple.Create("licenseKey", GlowParameterType.String) },
                               new[] { Tuple.Create("isKeyValid", GlowParameterType.Boolean) },
                               args =>
            {
                var isLicensed = args[0].String == "123456";

                if (isLicensed)
                {
                    licensedParam.Value = 1;
                }

                return(new[] { new GlowValue(isLicensed) });
            })
            {
                SchemaIdentifier = "de.l-s-b.emberplus.samples.licensingParameter",
            };

            new Model.Function(3,
                               identity,
                               "add",
                               new[] { Tuple.Create("arg1", GlowParameterType.Integer), Tuple.Create("arg2", GlowParameterType.Integer) },
                               new[] { Tuple.Create("sum", GlowParameterType.Integer) },
                               args =>
            {
                var sum = args[0].Integer + args[1].Integer;
                if (sum > 1000)
                {
                    throw new Exception();
                }
                return(new[] { new GlowValue(sum) });
            });

            new Model.Function(4,
                               identity,
                               "nothing",
                               null,
                               null,
                               _ =>
            {
                Console.WriteLine("Doing Nothing!");
                return(null);
            });

            new Model.Function(5,
                               identity,
                               "manyArgs",
                               new[]
            {
                Tuple.Create("arg1", GlowParameterType.Integer),
                Tuple.Create("arg2", GlowParameterType.Integer),
                Tuple.Create("arg3", GlowParameterType.Integer),
                Tuple.Create("arg4", GlowParameterType.Integer),
                Tuple.Create("arg5", GlowParameterType.Integer),
            },
                               null,
                               _ =>
            {
                Console.WriteLine("Many args but nothing to do!");
                return(null);
            });
        }