Ejemplo n.º 1
0
        /// <summary>
        /// Evaluate user-variable with IEvaluator by using unique identification.
        /// An evaluated value should be updated for variable.
        /// </summary>
        /// <param name="ident">Unique identificator</param>
        /// <param name="evaluator">IEvaluator objects for evaluating</param>
        /// <param name="resetting">To reset IEvaluator chain to initial state if true. Otherwise, evaluation can be in the chain of other evaluators.</param>
        public void Evaluate(string ident, IEvaluator evaluator, bool resetting)
        {
            if (evaluator == null)
            {
                throw new ArgumentNullException(nameof(evaluator));
            }

            lock (sync)
            {
                if (!definitions.ContainsKey(ident))
                {
                    throw new DefinitionNotFoundException(ident);
                }

                TVariable var = new TVariable(definitions[ident])
                {
                    status = ValStatus.Started
                };
                definitions[ident] = var;

                if (resetting)
                {
                    var.evaluated = evaluator.Evaluate(var.unevaluated);
                }
                else
                {
                    var.evaluated = evaluator.Evaluate(var.evaluated);
                }
                var.status         = ValStatus.Evaluated;
                definitions[ident] = var;
                LSender.Send(this, $"IEvaluator '{evaluator.GetType().ToString()}': Evaluation of variable '{ident}' is completed.", MsgLevel.Trace);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Defines user-variable.
        /// Value setted as unevaluated.
        /// </summary>
        /// <param name="name">Variable name.</param>
        /// <param name="scope">Specified scope for this variable.</param>
        /// <param name="unevaluated">Mixed string with unevaluated data.</param>
        public void SetVariable(string name, string scope, string unevaluated)
        {
            if (!IsValidName(name) || !IsValidScope(scope))
            {
                throw new ArgumentException($"name - '{name}' or scope - '{scope}' is not valid for variable");
            }
            string defindex = DefIndex(name, scope);

            if (unevaluated == null)
            {
                unevaluated = String.Empty;
            }

            lock (sync)
            {
                definitions[defindex] = new TVariable()
                {
                    unevaluated = unevaluated,
                    ident       = defindex,
                    name        = name,
                    scope       = scope,
                    status      = ValStatus.Unevaluated,
                    prev        = (definitions.ContainsKey(defindex))? definitions[defindex] : new TVariable(),
                    evaluated   = null
                };
                LSender.Send(this, $"User-variable: defined '{defindex}' = '{unevaluated}'");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Re/Defines user-variable with evaluated value.
        /// </summary>
        /// <param name="ident">Unique identificator</param>
        /// <param name="evaluated">mixed string with evaluated data</param>
        public void SetEvaluated(string ident, string evaluated)
        {
            if (evaluated == null)
            {
                evaluated = String.Empty;
            }

            lock (sync)
            {
                definitions[ident] = new TVariable()
                {
                    unevaluated = evaluated,
                    ident       = ident,
                    status      = ValStatus.Evaluated,
                    prev        = (definitions.ContainsKey(ident))? definitions[ident] : new TVariable(),
                    evaluated   = evaluated
                };
                LSender.Send(this, $"User-variable(Debug service): updated '{ident}' with evaluated value '{evaluated}'");
            }
        }