Example #1
0
        public static ScriptMethod GetScriptMethod(string name, string code)
        {
            ScriptMethod method = new ScriptMethod(name, code);

            if (string.IsNullOrEmpty(code))
            {
                method.Type = methodType.None;
            }
            if (code.Contains("DECLARE"))
            {
                method.Type = methodType.Declaration;
                code        = code.Replace("DECLARE", "");
            }
            if (code.Contains("EVENT"))
            {
                method.Type = methodType.Event;
                code        = code.Replace("EVENT", "");
            }

            //var lines = code.Split(CODE_INFO.LineSeparator);
            //var lines = StringUtils.CustomSplit(code,CODE_INFO.LineSeparator,')');
            var lines = CODE_READER.GetScriptLines(code);

            foreach (var line in lines)
            {
                CODE_READER.CheckLanguageRoutines(line, 1);
                ScriptEvent e = ScriptEvent.GetEvent(line);
                if (e != null && e.Conditions.Count > 0)
                {
                    method.Events.Add(e);
                }
            }
            return(method);
        }
Example #2
0
        public static ScriptEvent GetEvent(string code)
        {
            ScriptEvent e = new ScriptEvent(code);

            string[] lines = new string[0];
            if (code.Contains("loop"))
            {
                var    loop     = ScriptLoopEventHandler.GetLoopHandler(code);
                string loopCode = StringUtils.GetInside(code, ")", "stop loop");
                lines     = loopCode.Split(CODE_INFO.LineSeparator);
                e.Handler = loop;
            }
            else
            {
                e.Handler = new ScriptNoneEventHandler();
                lines     = new string[] { code };
            }
            foreach (var line in lines)
            {
                ScriptCondition cond = ScriptCondition.GetCondition(line);
                if (cond != null && cond.Actions.Count > 0)
                {
                    e.Conditions.Add(cond);
                }
            }
            return(e);
        }