Beispiel #1
0
        protected override void SerializeCore(XmlElement element, SaveContext context)
        {
            base.SerializeCore(element, context); //Base implementation must be called
            if (context == SaveContext.Undo)
            {
                XmlElementHelper helper = new XmlElementHelper(element);
                helper.SetAttribute("functionId", Symbol);
                helper.SetAttribute("functionName", NickName);
                helper.SetAttribute("functionDesc", Description);

                XmlDocument xmlDoc = element.OwnerDocument;
                foreach (var input in InPortData.Select(x => x.NickName))
                {
                    var inputEl = xmlDoc.CreateElement("functionInput");
                    inputEl.SetAttribute("inputValue", input);
                    element.AppendChild(inputEl);
                }

                foreach (var input in OutPortData.Select(x => x.NickName))
                {
                    var outputEl = xmlDoc.CreateElement("functionOutput");
                    outputEl.SetAttribute("outputValue", input);
                    element.AppendChild(outputEl);
                }
            }
        }
Beispiel #2
0
            protected override void SaveNode(XmlDocument xmlDoc, XmlElement dynEl, SaveContext context)
            {
                //Debug.WriteLine(pd.Object.GetType().ToString());
                XmlElement outEl = xmlDoc.CreateElement("ID");

                outEl.SetAttribute("value", Symbol);
                dynEl.AppendChild(outEl);

                outEl = xmlDoc.CreateElement("Name");
                outEl.SetAttribute("value", NickName);
                dynEl.AppendChild(outEl);

                outEl = xmlDoc.CreateElement("Description");
                outEl.SetAttribute("value", Description);
                dynEl.AppendChild(outEl);

                outEl = xmlDoc.CreateElement("Inputs");
                foreach (var input in InPortData.Select(x => x.NickName))
                {
                    var inputEl = xmlDoc.CreateElement("Input");
                    inputEl.SetAttribute("value", input);
                    outEl.AppendChild(inputEl);
                }
                dynEl.AppendChild(outEl);

                outEl = xmlDoc.CreateElement("Outputs");
                foreach (var output in OutPortData.Select(x => x.NickName))
                {
                    var outputEl = xmlDoc.CreateElement("Output");
                    outputEl.SetAttribute("value", output);
                    outEl.AppendChild(outputEl);
                }
                dynEl.AppendChild(outEl);
            }
Beispiel #3
0
        internal override IEnumerable <AssociativeNode> BuildAst(List <AssociativeNode> inputAstNodes, CompilationContext context)
        {
            var paramDict = InPortData.Select(x => x.NickName)
                            .Zip <string, AssociativeNode, Tuple <string, AssociativeNode> >(inputAstNodes, Tuple.Create)
                            .ToDictionary(x => x.Item1, x => x.Item2);

            AssociativeNode rhs;

            if (null == _parsed)
            {
                rhs = AstFactory.BuildNullNode();
            }
            else
            {
                List <AssociativeNode> newInputs = _parsed.Count == 1
                    ? new List <AssociativeNode> {
                    _parsed[0].GetAstNode(paramDict)
                }
                    : _parsed.Select(x => x.GetAstNode(paramDict)).ToList();

                rhs = newInputs.Count == 1
                        ? newInputs[0]
                        : AstFactory.BuildExprList(newInputs);
            }

            var assignment = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), rhs);

            return(new[] { assignment });
        }
Beispiel #4
0
        protected override void SerializeCore(XmlElement element, SaveContext context)
        {
            base.SerializeCore(element, context); //Base implementation must be called

            Controller.SerializeCore(element, context);

            var xmlDoc = element.OwnerDocument;

            var outEl = xmlDoc.CreateElement("Name");

            outEl.SetAttribute("value", NickName);
            element.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Description");
            outEl.SetAttribute("value", Description);
            element.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Inputs");
            foreach (string input in InPortData.Select(x => x.NickName))
            {
                XmlElement inputEl = xmlDoc.CreateElement("Input");
                inputEl.SetAttribute("value", input);
                outEl.AppendChild(inputEl);
            }
            element.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Outputs");
            foreach (string output in OutPortData.Select(x => x.NickName))
            {
                XmlElement outputEl = xmlDoc.CreateElement("Output");
                outputEl.SetAttribute("value", output);
                outEl.AppendChild(outputEl);
            }
            element.AppendChild(outEl);
        }
Beispiel #5
0
        protected override void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context)
        {
            Controller.SaveNode(xmlDoc, nodeElement, context);

            var outEl = xmlDoc.CreateElement("Name");

            outEl.SetAttribute("value", NickName);
            nodeElement.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Description");
            outEl.SetAttribute("value", Description);
            nodeElement.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Inputs");
            foreach (string input in InPortData.Select(x => x.NickName))
            {
                XmlElement inputEl = xmlDoc.CreateElement("Input");
                inputEl.SetAttribute("value", input);
                outEl.AppendChild(inputEl);
            }
            nodeElement.AppendChild(outEl);

            outEl = xmlDoc.CreateElement("Outputs");
            foreach (string output in OutPortData.Select(x => x.NickName))
            {
                XmlElement outputEl = xmlDoc.CreateElement("Output");
                outputEl.SetAttribute("value", output);
                outEl.AppendChild(outputEl);
            }
            nodeElement.AppendChild(outEl);
        }
Beispiel #6
0
        private IEnumerable <KeyValuePair <string, Value> > MakeBindings(IEnumerable <Value> args)
        {
            //Zip up our inputs
            var bindings = InPortData
                           .Select(x => x.NickName)
                           .Zip(args, (s, v) => new KeyValuePair <string, Value>(s, v))
                           .ToList();

            //bindings.Add(new KeyValuePair<string, dynamic>("__persistent__", _stateDict));

            return(bindings);
        }
Beispiel #7
0
        private IEnumerable <KeyValuePair <string, dynamic> > makeBindings(IEnumerable <Value> args)
        {
            //Zip up our inputs
            var bindings = InPortData
                           .Select(x => x.NickName)
                           .Zip(args, (s, v) => new KeyValuePair <string, dynamic>(s, Converters.convertFromValue(v)))
                           .Concat(PythonBindings.Bindings)
                           .ToList();

            bindings.Add(new KeyValuePair <string, dynamic>("__persistent__", _stateDict));

            return(bindings);
        }
Beispiel #8
0
        /// <summary>
        ///   Return if the custom node instance is in sync with its definition.
        ///   It may be out of sync if .dyf file is opened and updated and then
        ///   .dyn file is opened.
        /// </summary>
        /// <returns></returns>
        public bool IsInSyncWithDefinition()
        {
            if (Definition.Parameters != null)
            {
                if (Definition.Parameters.Count() != InPortData.Count() ||
                    !Definition.Parameters.SequenceEqual(InPortData.Select(p => p.NickName)))
                {
                    return(false);
                }
            }

            if (Definition.ReturnKeys != null)
            {
                if (Definition.ReturnKeys.Count() != OutPortData.Count() ||
                    !Definition.ReturnKeys.SequenceEqual(OutPortData.Select(p => p.NickName)))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #9
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            Func <string, string[], object[], object> backingMethod = DSCore.Formula.Evaluate;

            // Format input names to be used as function parameters
            var inputs = InPortData.Select(x => x.NickName.Replace(' ', '_')).ToList();


            /*  def formula_partial(<params>) {
             *    return = DSCore.Formula.Evaluate(<FormulaString>, <InPortData Names>, <params>);
             *  }
             */

            var functionDef = new FunctionDefinitionNode
            {
                Name      = "__formula_" + GUID.ToString().Replace("-", string.Empty),
                Signature =
                    new ArgumentSignatureNode
                {
                    Arguments = inputs.Select(AstFactory.BuildParamNode).ToList()
                },
                ReturnType   = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar),
                FunctionBody =
                    new CodeBlockNode
                {
                    Body =
                        new List <AssociativeNode>
                    {
                        AstFactory.BuildReturnStatement(
                            AstFactory.BuildFunctionCall(
                                backingMethod,
                                new List <AssociativeNode>
                        {
                            AstFactory.BuildStringNode(FormulaString),
                            AstFactory.BuildExprList(
                                InPortData.Select(
                                    x =>
                                    AstFactory.BuildStringNode(x.NickName) as
                                    AssociativeNode).ToList()),
                            AstFactory.BuildExprList(
                                inputs.Select(AstFactory.BuildIdentifier)
                                .Cast <AssociativeNode>()
                                .ToList())
                        }))
                    }
                }
            };

            if (IsPartiallyApplied)
            {
                return(new AssociativeNode[]
                {
                    functionDef,
                    AstFactory.BuildAssignment(
                        GetAstIdentifierForOutputIndex(0),
                        AstFactory.BuildFunctionObject(
                            functionDef.Name,
                            InPortData.Count,
                            Enumerable.Range(0, InPortData.Count).Where(HasConnectedInput),
                            inputAstNodes))
                });
            }
            else
            {
                AppendReplicationGuides(inputAstNodes);

                return(new AssociativeNode[]
                {
                    functionDef,
                    AstFactory.BuildAssignment(
                        GetAstIdentifierForOutputIndex(0),
                        AstFactory.BuildFunctionCall(
                            functionDef.Name,
                            inputAstNodes))
                });
            }
        }
Beispiel #10
0
 protected override InputNode Compile(IEnumerable <string> portNames)
 {
     return(new TransactionProcedureNode(this, InPortData.Select(x => x.NickName)));
 }