Example #1
0
        /// <summary>
        /// 执行指令,启动失败的启动项在ReportInfo中查看
        /// </summary>
        /// <exception cref="ConstInstructionParameterParseException"></exception>
        public override string Execute()
        {
            ReportInfo.Clear();
            AHelper.InstructionHistory.Insert(0, Instruction);

            ConstInstruction ci = new ConstInstruction();

            if (AConstInstruction.GetConstInstructionFrame(Instruction, ref ci))
            {
                bool allRight = true;
                try
                {
                    foreach (string instructionLine in ci.instructionLines)
                    {
                        // Instruction here firstly need to be parse (const quote / parameter parse).
                        // Const quote parse.
                        string instructionLine_cqp = AConstQuote.ConstQuoteParse(instructionLine);
                        // Parameter parse
                        ConstInstruction instructionAttribute   = AConstInstruction.ConstInstructionFileNameParse(Instruction, false);
                        string           instructionLine_cpq_pp = AConstInstruction.ConstInstructionParameterParse(ci, instructionLine_cqp, instructionAttribute.parameterList);
                        // Execute
                        AInstruction.GetInstruction(instructionLine_cpq_pp).Execute();
                        if (reportType != ReportType.OK)
                        {
                            allRight = false;
                        }
                    }
                }
                catch (Exception exception) { throw exception; }
                finally { if (!allRight)
                          {
                              reportType = ReportType.WARNING;
                          }
                }
                return(AInstruction.MSG_EXECUTE_SUCCESSFULLY);
            }
            else
            {
                reportType = ReportType.ERROR;
                throw new ConstInstructionNotFoundException(Instruction);
            }
        }
        public void ConstInstructionParameterParseTest()
        {
            ConstInstruction ci = new ConstInstruction
            {
                constInstructionName = "test",
                instructionLines     = new List <string> {
                    "param1 param2 param3"
                },
                parameterList = new List <string> {
                    "param1",
                    "param2"
                }
            };
            List <string> valueList = new List <string> {
                "a", "b"
            };
            string parseAcutual = AConstInstruction.ConstInstructionParameterParse(ci, "param1 param2 param3", valueList);

            Assert.AreEqual("a b param3", parseAcutual);
        }