예제 #1
0
        public override string Execute()
        {
            ReportInfo.Clear();
            AHelper.InstructionHistory.Insert(0, Instruction);
            try
            {
                string output = AHelper.ExecuteCommand(Instruction.Substring(1).Trim());

                // cd detect
                List <string> cmdParts = new List <string>(Instruction.Split(' '));
                cmdParts.RemoveAt(0); // Remove symbol '>'
                if (cmdParts.Count > 1 && "cd" == cmdParts[0])
                {
                    System.IO.Directory.SetCurrentDirectory(cmdParts[1]);
                }

                reportType = ReportType.OK;
                return(output);
            }
            catch (Exception exception)
            {
                reportType = ReportType.ERROR;
                return(exception.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// 执行宏指令
        /// </summary>
        /// <exception cref="MacroFormatException"></exception>
        /// <exception cref="FileNotFoundException"></exception>
        /// <exception cref="AFile.StartupItemNotFoundException"></exception>
        /// <exception cref="UnauthorizedAccessException"></exception>
        public override string Execute()
        {
            ReportInfo.Clear();
            AHelper.InstructionHistory.Insert(0, Instruction);
            try
            {
                switch (GetMacroType())
                {
                case MacroType.ADD: ExecuteMacroAdd(); break;

                case MacroType.DEL: ExecuteMacroDel(); break;

                case MacroType.NEW: ExecuteMacroNew(); break;

                case MacroType.SET: ExecuteMacroSet(); break;

                case MacroType.UPDATE: ExecuteMacroUpdate(); break;

                case MacroType.RESTART: ExecuteMacroRestart(); break;

                case MacroType.LOCATE: ExecuteMacroLocate(); break;
                }
            }
            catch (Exception)
            {
                reportType = ReportType.ERROR;
                throw;
            }
            reportType = ReportType.OK;
            return(MSG_EXECUTE_SUCCESSFULLY);
        }
예제 #3
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);
            }
        }