Пример #1
0
        /// <summary>
        /// Performs an action with static scope.
        /// </summary>
        public object PerformAction(IRSRuntimeEntity inEntity, string inActionId, params object[] inArgs)
        {
            RSActionInfo   actionInfo = Library.GetAction(inActionId);
            ExecutionScope scope      = CreateScope(inEntity, RSValue.Null, TableUtils.GetRuleFlags(actionInfo.Flags));

            using (new SharedRef <ExecutionScope>(scope))
            {
                return(PerformAction(inEntity, actionInfo, InternalScriptUtils.Convert(inArgs), scope).Value);
            }
        }
Пример #2
0
        public void Reset()
        {
            m_Self     = null;
            m_Argument = RSValue.Null;

            if (m_Registers != null)
            {
                for (int i = 0; i < RSRegisters.MaxRegisters; ++i)
                {
                    m_Registers[i] = default(RSValue);
                }
            }
        }
Пример #3
0
        internal void TriggerRS(IRSRuntimeEntity inEntity, RSTriggerId inTriggerId, RSValue inArgument, bool inbForce)
        {
            if (!inbForce && inEntity.IsLocked())
            {
                return;
            }

            ExecutionScope scope = CreateScope(inEntity, inArgument, 0);

            using (new SharedRef <ExecutionScope>(scope))
            {
                inEntity?.RuleTable?.EvaluateTrigger(inTriggerId, scope);
            }
        }
Пример #4
0
        static public bool IsListeningForTrigger(this IRSRuntimeEntity inEntity, RSTriggerId inTriggerId)
        {
            if (inTriggerId == RSTriggerId.Null)
            {
                return(false);
            }

            RSTriggerId[] triggers = (inEntity.RuleTable?.Data?.UniqueTriggers);
            if (triggers != null)
            {
                return(Array.IndexOf(triggers, inTriggerId) >= 0);
            }

            return(false);
        }
Пример #5
0
        private void Bind(InvocationTarget inTarget, IRSRuntimeEntity inEntity, IScriptContext inContext, ref object ioValue)
        {
            switch (inTarget)
            {
            case InvocationTarget.Entity:
                ioValue = inEntity;
                break;

            case InvocationTarget.Component:
                ioValue = inEntity?.GetRSComponent(ComponentType);
                break;

            case InvocationTarget.Context:
                ioValue = inContext;
                break;
            }
        }
Пример #6
0
        internal RSValue InvokeWithCachedArgs(IRSRuntimeEntity inTarget, ExecutionScope inContext)
        {
            object thisArg;
            bool   bValid = PrepContext(inTarget, inContext, out thisArg);

            if (!bValid)
            {
                if (m_MethodSettings.ComponentType != null)
                {
                    inContext.Logger?.Warn("Unable to evaluate query {0} on Entity \"{1}\" ({2}) - missing component type {3}", Id, inTarget?.Name, inTarget != null ? inTarget.Id : RSEntityId.Null, m_MethodSettings.ComponentType);
                }
                else
                {
                    inContext.Logger?.Warn("Unable to evaluate query {0} on Entity \"{1}\" ({2})", Id, inTarget?.Name, inTarget != null ? inTarget.Id : RSEntityId.Null);
                }
                return(m_DefaultValue);
            }

            object returnVal = m_MethodInfo.Invoke(thisArg, m_CachedArguments);

            return(RSInterop.ToRSValue(returnVal));
        }
Пример #7
0
        private IEnumerable <IRSRuntimeEntity> EnumerateEntityLinks(MultiReturn <IRSRuntimeEntity> inEntities, string inLinks, bool inbUseFirstLink)
        {
            using (PooledList <StringSlice> paths = PooledList <StringSlice> .Alloc())
            {
                int sliceCount = StringSlice.Split(inLinks, EntityLinkSplitChars, StringSplitOptions.None, paths);

                foreach (var entity in inEntities)
                {
                    IRSRuntimeEntity currentEntity = entity;
                    for (int i = 0; currentEntity != null && i < sliceCount - 1; ++i)
                    {
                        StringSlice path = paths[i];
                        currentEntity = currentEntity.Links?.EntityWithLink(path);
                    }

                    if (currentEntity != null)
                    {
                        var links = currentEntity.Links;
                        if (links == null)
                        {
                            continue;
                        }

                        if (inbUseFirstLink)
                        {
                            yield return(links.EntityWithLink(paths[sliceCount - 1]));
                        }
                        else
                        {
                            foreach (var linkedEntity in links.EntitiesWithLink(paths[sliceCount - 1]))
                            {
                                yield return(linkedEntity);
                            }
                        }
                    }
                }
            }
        }
Пример #8
0
        public bool Bind(IRSRuntimeEntity inEntity, object[] ioArguments, IScriptContext inContext, out object outThis)
        {
            if (IsExtension)
            {
                if (ioArguments.Length == 0)
                {
                    outThis = null;
                    return(false);
                }
            }

            if (ioArguments.Length > 0)
            {
                Bind(FirstParam, inEntity, inContext, ref ioArguments[0]);
                if (ioArguments.Length > 1)
                {
                    Bind(SecondParam, inEntity, inContext, ref ioArguments[1]);
                }
            }

            outThis = null;
            Bind(ThisParam, inEntity, inContext, ref outThis);

            if (IsExtension)
            {
                return(!FirstParam.MustBeNotNull() || ioArguments[0] != null);
            }
            else if (IsInstance)
            {
                return(outThis != null);
            }
            else
            {
                return(true);
            }
        }
Пример #9
0
 static private void SetActive(this IRSRuntimeEntity inEntity, [RSParameter("Active")] bool inbActive)
 {
     inEntity.SetActive(inbActive);
 }
Пример #10
0
 static private void Deactivate(this IRSRuntimeEntity inEntity)
 {
     inEntity.SetActive(false);
 }
Пример #11
0
 static private void ToggleActive(this IRSRuntimeEntity inEntity)
 {
     inEntity.SetActive(!inEntity.IsActive());
 }
Пример #12
0
 static private void LoadRegisterEntity(IScriptContext inContext, [RSParameter("Register")] RegisterIndex inRegister, [RSParameter("Value")] IRSRuntimeEntity inValue)
 {
     inContext?.Logger?.Log("Loading register {0} with value {1}", inRegister, inValue);
     inContext.LoadRegister(inRegister, inValue);
 }
Пример #13
0
 static private void StopRule(this IRSRuntimeEntity inEntity, [RSParameter("Rule Name")] string inRuleName)
 {
     inEntity.RuleTable.StopRule(inRuleName);
 }
Пример #14
0
 internal ActionResult PerformAction(IRSRuntimeEntity inEntity, RSActionInfo inAction, RSValue[] inArguments, ExecutionScope inContext)
 {
     return(inAction.Invoke(inEntity, inArguments, inContext));
 }
Пример #15
0
 static private void Activate(this IRSRuntimeEntity inEntity)
 {
     inEntity.SetActive(true);
 }
Пример #16
0
 static private bool IsActive(this IRSRuntimeEntity inEntity)
 {
     return(inEntity.IsActive());
 }
Пример #17
0
 static private bool IsLocked(this IRSRuntimeEntity inEntity)
 {
     return(inEntity.IsLocked());
 }
Пример #18
0
 static private void ToggleLocked(this IRSRuntimeEntity inEntity)
 {
     inEntity.SetLocked(!inEntity.IsLocked());
 }
Пример #19
0
 static private void DispatchTrigger(this IRSRuntimeEntity inEntity, IScriptContext inContext, [RSParameter("Trigger", TriggerParameterType = typeof(void))] RSTriggerId inTrigger)
 {
     inContext?.Trigger(inEntity, inTrigger);
 }
Пример #20
0
 void IScriptContext.Trigger(IRSRuntimeEntity inEntity, RSTriggerId inTriggerId, object inArgument, bool inbForce)
 {
     m_Environment.Trigger(inEntity, inTriggerId, RSInterop.ToRSValue(inArgument), inbForce);
 }
Пример #21
0
 internal RSValue EvaluateQuery(IRSRuntimeEntity inEntity, RSQueryInfo inQuery, RSValue[] inArgs, ExecutionScope inContext)
 {
     return(inQuery.Invoke(inEntity, inArgs, inContext));
 }
Пример #22
0
 public void Initialize(IRSRuntimeEntity inSelf, RSValue inArgument)
 {
     m_Self     = inSelf;
     m_Argument = inArgument;
 }
Пример #23
0
 static private void Lock(this IRSRuntimeEntity inEntity)
 {
     inEntity.SetLocked(true);
 }
Пример #24
0
 public RSRuntimeRuleTable(IRSRuntimeEntity inOwner)
 {
     m_Entity = inOwner;
 }
Пример #25
0
 static private void Unlock(this IRSRuntimeEntity inEntity)
 {
     inEntity.SetLocked(false);
 }
Пример #26
0
 public void Trigger(IRSRuntimeEntity inEntity, string inTriggerId, bool inbForce = false)
 {
     Trigger(inEntity, new RSTriggerId(ScriptUtils.Hash(inTriggerId)), RSValue.Null, inbForce);
 }
Пример #27
0
 static private void SetLocked(this IRSRuntimeEntity inEntity, [RSParameter("Locked")] bool inbLocked)
 {
     inEntity.SetLocked(inbLocked);
 }
Пример #28
0
 internal bool PrepContext(IRSRuntimeEntity inTarget, ExecutionScope inScope, out object outThis)
 {
     return(m_MethodSettings.Bind(inTarget, m_CachedArguments, inScope, out outThis));
 }
Пример #29
0
 static private void DispatchTriggerWithString(this IRSRuntimeEntity inEntity, IScriptContext inContext, [RSParameter("Trigger", TriggerParameterType = typeof(string))] RSTriggerId inTrigger, [RSParameter("Trigger Parameter")] string inArgument)
 {
     inContext?.Trigger(inEntity, inTrigger, inArgument);
 }
Пример #30
0
 static private RSGroupId Group(this IRSRuntimeEntity inEntity)
 {
     return(inEntity.Group);
 }