示例#1
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (string.IsNullOrEmpty(Value) || SelectedUnit is null)
            {
                return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) }
            }
            ;

            var expression = AstFactory.BuildStringNode(Value);

            var unitID =
                AstFactory.BuildStringNode(SelectedUnit?.TypeId);

            var node = AstFactory.BuildFunctionCall(
                new Func <string, string, double>(DynamoUnits.Utilities.ParseExpressionByUnitId),
                new List <AssociativeNode> {
                unitID, expression
            });

            var node2 = AstFactory.BuildFunctionCall(
                new Func <string, DynamoUnits.Unit>(DynamoUnits.Unit.ByTypeID),
                new List <AssociativeNode> {
                unitID
            });

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node), AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(1), node2) });
        }
示例#2
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode node;

            if (SelectedIndex < 0 || SelectedIndex >= Items.Count)
            {
                node = AstFactory.BuildNullNode();
            }
            else
            {
                var typeName     = AstFactory.BuildStringNode(Items[SelectedIndex].Name);
                var assemblyName = AstFactory.BuildStringNode("DynamoUnits");
                node = AstFactory.BuildFunctionCall(new Func <string, string, object>(Types.FindTypeByNameInAssembly), new List <AssociativeNode>()
                {
                    typeName, assemblyName
                });
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
示例#3
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode node;

            if (SelectedIndex < 0 || SelectedIndex >= Items.Count)
            {
                node = AstFactory.BuildNullNode();
            }
            else
            {
                var args = new List <AssociativeNode>
                {
                    AstFactory.BuildStringNode((string)Items[SelectedIndex].Item)
                };

                var func = new Func <string, DynamoUnits.Symbol>(DynamoUnits.Symbol.ByTypeID);
                node = AstFactory.BuildFunctionCall(func, args);
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
示例#4
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(
            List <AssociativeNode> inputAstNodes)
        {
            if (null == inputAstNodes || inputAstNodes.Count == 0 || inputAstNodes[0] is ProtoCore.AST.AssociativeAST.NullNode || SelectedToConversion is null || SelectedFromConversion is null)
            {
                return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) }
            }
            ;

            var conversionToNode =
                AstFactory.BuildStringNode(SelectedToConversion?.TypeId);

            var conversionFromNode =
                AstFactory.BuildStringNode(SelectedFromConversion?.TypeId);
            AssociativeNode node = null;

            node = AstFactory.BuildFunctionCall(
                new Func <double, string, string, double>(DynamoUnits.Utilities.ConvertByUnitIds),
                new List <AssociativeNode> {
                inputAstNodes[0], conversionFromNode, conversionToNode
            });

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }