Example #1
0
        public ICompiledScript Compile(IAdvancedScript script)
        {
            ICompiledScript compiledScript = _factory.CreateInstance <ICompiledScript>();

            compiledScript.OriginalScript = script;
            Inputs   = new();
            AllNodes = new();

            foreach (InputNode scriptInput in script.Editor.Inputs.InputNodes)
            {
                ILaminarValue myInputValue = _valueFactory.Get(scriptInput.Value, true);
                myInputValue.Name = scriptInput.GetNameLabel().LabelText.Value;
                compiledScript.Inputs.Add(myInputValue);
                Inputs.Add(scriptInput, myInputValue);
            }

            foreach (INodeContainer triggerNode in script.Editor.TriggerNodes)
            {
                if (triggerNode.Name.OutputConnector.ExclusiveConnection is not null)
                {
                    CompiledNodeWrapper wrappedTrigger = CompiledNodeWrapper.Get(triggerNode, this);
                    compiledScript.AllTriggerNodes.Add(wrappedTrigger);
                    wrappedTrigger.flowOutChains.Add(new CompiledNodeChain(triggerNode.Name, wrappedTrigger.CoreNode.GetNameLabel().FlowOutput, this));
                }
            }

            return(compiledScript);
        }
Example #2
0
        public void Evaluate(ICompiledScript script, IDictionary <string, object> parameters = null)
        {
            ScriptContext.Items = parameters;

            object res = null;

            ((MonoCSharpCompiledScript)script).CompiledMethod.Invoke(ref res);
        }
 public void SetInstance(ICompiledScript script)
 {
     NodeName = script.OriginalScript.Name.Value;
     foreach (ILaminarValue input in script.Inputs)
     {
         AllInputs.Add(Constructor.NodeField(input.Name).WithValue("Display", input));
     }
 }
Example #4
0
        public T Evaluate <T>(ICompiledScript script, IDictionary <string, object> parameters = null)
        {
            ScriptContext.Items = parameters;

            object res = null;

            ((MonoCSharpCompiledScript)script).CompiledMethod.Invoke(ref res);

            return((T)ScriptContext.Result);
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkQueueItem"/> class.
        /// </summary>
        /// <param name="compiledScript">The compiled script.</param>
        /// <param name="script">The script.</param>
        /// <param name="scalarSet">The scalar set.</param>
        public WorkQueueItem(ICompiledScript compiledScript, IScript script, ScalarSet scalarSet)
        {
            if (compiledScript == null)
                throw new ArgumentNullException("compiledScript");

            if (script == null)
                throw new ArgumentNullException("script");

            if (scalarSet == null)
                throw new ArgumentNullException("scalarSet");

            m_CompiledScript = compiledScript;
            m_InputSet = scalarSet;
            m_Script = script;
        }
Example #6
0
        /// <summary>
        /// Cancels the evaluation of a script.
        /// </summary>
        /// <param name="compiledScript">The compiled script.</param>
        /// <returns>All the sets that were cancelled.</returns>
        public ScalarSet[] CancelEvaluation(ICompiledScript compiledScript)
        {
            if (compiledScript == null)
                throw new ArgumentNullException("compiledScript");

            List<ScalarSet> toCancel = new List<ScalarSet>();

            lock (m_SyncRoot)
            {
                foreach (WorkQueueItem eg in m_Queue)
                {
                    if (eg.CompiledScript == compiledScript)
                    {
                        /* Cancel me! */
                        eg.Cancelled = true;
                        toCancel.Add(eg.InputSet);
                    }
                }
            }

            return toCancel.ToArray();
        }
Example #7
0
        /// <summary>
        /// Queues the evaluation of a script.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="compiledScript">The compiled script.</param>
        /// <param name="inputSet">The input set.</param>
        public void QueueEvaluation(IScript script, ICompiledScript compiledScript, ScalarSet inputSet)
        {
            if (script == null)
                throw new ArgumentNullException("script");

            if (compiledScript == null)
                throw new ArgumentNullException("compiledScript");

            if (inputSet == null)
                throw new ArgumentNullException("inputSet");

            lock (m_SyncRoot)
            {
                m_Queue.Add(new WorkQueueItem(compiledScript, script, inputSet));
            }
        }