Пример #1
0
        private void Validate(SqProgram program, SqRequirements capabilities, List <string> messages)
        {
            //bool hasTimer = (capabilities & SqRequirements.Timer) == SqRequirements.Timer;
            bool hasCM = (capabilities & SqRequirements.ControlModule) == SqRequirements.ControlModule;

            var repeatPos = program.Commands.FindIndex(x => x.Cmd == "repeat");

            if (repeatPos != -1 && repeatPos != program.Commands.Count - 1)
            {
                Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "Unreachable code found in @{0}: all commands after /repeat will never executed", program.Name);
            }

            if (repeatPos != -1 && !program.Commands.Take(repeatPos).Any(x => Commands.CmdDefs[x.Cmd].IsWait))
            {
                Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "Where is no any wait command before /repeat in @{0}. Script will wait 1 tock to prevent \"Script Too Complex\" exception", program.Name);
            }

            /*
             * SqCommand cmd = null;
             * if (!hasTimer && (cmd = program.Commands.FirstOrDefault(x => (Commands.CmdDefs[x.Cmd].Requirements & SqRequirements.Timer) != 0)) != null)
             * {
             *  Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "@{0} contains /{1} command, but where is no timer to execute it", program.Name, cmd.Cmd);
             * }*/

            SqCommand cmd = null;

            if (!hasCM && (cmd = program.Commands.FirstOrDefault(x => (Commands.CmdDefs[x.Cmd].Requirements & SqRequirements.ControlModule) != 0)) != null)
            {
                Log.WriteFormat(Parser.LOG_CAT, LogLevel.Warning, "@{0} contains /{1} command, but Control Module mod is not loaded", program.Name, cmd.Cmd);
            }

            // if (!hasCM && program.Commands)
        }
Пример #2
0
        internal void Validate(List <SqProgram> programs, SqRequirements capabilities)
        {
            List <string> messages = new List <string>();

            foreach (var program in programs)
            {
                Validate(program, capabilities, messages);
            }
        }
Пример #3
0
 public CommandRef(string name, ParamRef[] arguments, Action <IList, IMethodContext> implementation,
                   SqRequirements requirements = SqRequirements.None, bool isWait = false, bool hidden = false)
 {
     Name           = name;
     Arguments      = arguments;
     Implementation = implementation;
     OptionalCount  = arguments.Count(x => x.Optional);
     Aggregative    = arguments.Any(x => x.Aggregative);
     Requirements   = requirements;
     IsWait         = isWait;
     Hidden         = hidden;
 }
Пример #4
0
        public override bool DoWork()
        {
            bool done = parser.Parse(Timeout);

            if (done)
            {
                if (parser.Finalize())
                {
                    var            validator = new SqValidator();
                    SqRequirements req       = SqRequirements.Timer;
                    if (CMMapper.Shared.IsAvailable())
                    {
                        req |= SqRequirements.ControlModule;
                    }

                    validator.Validate(parser.Programs, req);
                }

                result = new Tuple <List <SqProgram>, string>(parser.Programs, parser.ErrorMessage);
            }

            return(done);
        }