Esempio n. 1
0
        /// <summary>
        ///     Updates this Custom Node's data to match its Definition.
        /// </summary>
        public void ResyncWithDefinition()
        {
            DisableReporting();

            if (Definition.Parameters != null)
            {
                InPortData.Clear();
                foreach (string arg in Definition.Parameters)
                {
                    InPortData.Add(new PortData(arg, "parameter"));
                }
            }

            OutPortData.Clear();
            if (Definition.ReturnKeys != null && Definition.ReturnKeys.Any())
            {
                foreach (string key in Definition.ReturnKeys)
                {
                    OutPortData.Add(new PortData(key, "return value"));
                }
            }
            else
            {
                OutPortData.Add(new PortData("", "return value"));
            }

            RegisterAllPorts();
            NickName = Definition.DisplayName;

            EnableReporting();
        }
Esempio n. 2
0
        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            InPortData.Clear();  // In/out ports are going to be recreated in
            OutPortData.Clear(); // LoadNode, clear them so they don't accumulate.

            base.DeserializeCore(element, context);
            this.LoadNode(element);
        }
Esempio n. 3
0
        private void ProcessFormula()
        {
            Expression e;

            try
            {
                e = new Expression(
                    FormulaString.ToLower()
                    .Replace(" and ", "+").Replace("&&", "+")
                    .Replace(" or ", "+").Replace("||", "+"),
                    EvaluateOptions.IgnoreCase);
            }
            catch (Exception ex)
            {
                Error(ex.Message);
                return;
            }

            if (e.HasErrors())
            {
                Error(e.Error);
                return;
            }

            var parameters = new List <string>();
            var paramSet   = new HashSet <string>();

            e.EvaluateParameter += delegate(string name, ParameterArgs args)
            {
                if (!paramSet.Contains(name) && !reservedParamNames.Contains(name))
                {
                    paramSet.Add(name);
                    parameters.Add(name);
                }

                args.Result = 0;
            };

            try
            {
                e.Evaluate();
            }
            catch { }

            InPortData.Clear();

            foreach (var p in parameters)
            {
                InPortData.Add(new PortData(p, "variable"));
            }

            RegisterInputPorts();
            ClearError();
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the inport and outport data based on
        /// the statements generated from the user code.
        /// </summary>
        ///
        private void CreateInputOutputPorts()
        {
            InPortData.Clear();
            OutPortData.Clear();
            if (codeStatements == null || (codeStatements.Count == 0))
            {
                RegisterAllPorts();
                return;
            }

            SetInputPorts();
            SetOutputPorts();

            RegisterAllPorts();
        }
Esempio n. 5
0
        /// <summary>
        /// Set the number of inputs.
        /// </summary>
        /// <param name="numInputs"></param>
        public void SetNumInputs(int numInputs)
        {
            if (numInputs <= 0)
            {
                return;
            }

            InPortData.Clear();

            for (var i = 0; i < numInputs; i++)
            {
                InPortData.Add(new PortData(GetInputRootName() + GetInputNameIndex(), "", typeof(object)));
            }

            RegisterAllPorts();
        }
Esempio n. 6
0
        private void UpdatePorts()
        {
            InPortData.Clear();
            for (int input = 0; input < InputCount; input++)
            {
                var name = string.Format("Port {0}", input + 1);
                InPortData.Add(new PortData(name, ""));
            }

            OutPortData.Clear();
            for (int output = 0; output < OutputCount; output++)
            {
                var name = string.Format("Port {0}", output + 1);
                OutPortData.Add(new PortData(name, ""));
            }

            RegisterAllPorts();
        }
Esempio n. 7
0
        private void ProcessFormula()
        {
            Expression e;

            try
            {
                e = new Expression(
                    FormulaString.ToLower()
                    .Replace(" and ", "+").Replace("&&", "+")
                    .Replace(" or ", "+").Replace("||", "+"),
                    EvaluateOptions.IgnoreCase);
            }
            catch (Exception ex)
            {
                Error(ex.Message);
                return;
            }

            if (e.HasErrors())
            {
                Error(e.Error);
                return;
            }

            var parameters = new List <Tuple <string, Type> >();
            var paramSet   = new HashSet <string>();

            e.EvaluateFunction += delegate(string name, FunctionArgs args)
            {
                if (!paramSet.Contains(name) && !ReservedFuncNames.Contains(name))
                {
                    paramSet.Add(name);
                    parameters.Add(Tuple.Create(name, typeof(Value.Function)));
                }

                foreach (var p in args.Parameters)
                {
                    p.Evaluate();
                }

                args.Result = 0;
            };

            e.EvaluateParameter += delegate(string name, ParameterArgs args)
            {
                if (!paramSet.Contains(name) && !ReservedParamNames.Contains(name))
                {
                    paramSet.Add(name);
                    parameters.Add(Tuple.Create(name, typeof(Value.Number)));
                }

                args.Result = 0;
            };

            try
            {
                e.Evaluate();
            }
            catch { }

            InPortData.Clear();

            foreach (var p in parameters)
            {
                InPortData.Add(new PortData(p.Item1, "variable", p.Item2));
            }

            RegisterInputs();
            ClearError();
        }