Ejemplo n.º 1
0
        /// <summary>
        /// 执行宏新建指令
        /// </summary>
        /// <exception cref="UnauthorizedAccessException"></exception>
        private void ExecuteMacroNew()
        {
            List <string> macroInstructionParameters = GetMacroInstructionParametersList();

            // Handle [in] sytex
            string inWhere = AFile.ATEMP_PATH;

            if (macroInstructionParameters.Count >= 3 && "in" == macroInstructionParameters[macroInstructionParameters.Count - 2])
            {
                string lastParam = macroInstructionParameters[macroInstructionParameters.Count - 1];
                if (AFile.Exists(lastParam))
                {
                    // If the item is already a directory
                    string itemPath = AFile.GetFullPath(lastParam);
                    if (Directory.Exists(itemPath))
                    {
                        inWhere = itemPath;
                    }
                    // If the item is exist
                    else if (File.Exists(itemPath))
                    {
                        inWhere = Path.GetDirectoryName(itemPath);
                    }
                    else
                    {
                        throw new NotImplementedException("The startup item [" + lastParam + "] is not found in disk.");
                    }
                }
                else if (Directory.Exists(lastParam))
                {
                    inWhere = lastParam;
                }
                else
                {
                    throw new NotImplementedException("The directory [" + lastParam + "] is not exist.");
                }
                macroInstructionParameters.RemoveRange(macroInstructionParameters.Count - 2, 2);
            }
            // Remove the last '\'
            if (inWhere.Last() == '\\')
            {
                inWhere = inWhere.Substring(0, inWhere.Length - 1);
            }

            foreach (string newFileName in macroInstructionParameters)
            {
                string fileName = AConstQuote.ConstQuoteParse(newFileName);
                string filePath = inWhere + @"\" + fileName;
                using (StreamWriter streamWriter = new StreamWriter(filePath, false)) { }
                AFile.StartupProcess(filePath);
                //AFile.LaunchTempFile(fileName);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取可执行的Alterful指令
        /// </summary>
        /// <param name="instruction"></param>
        /// <returns></returns>
        public static AInstruction GetInstruction(string instruction)
        {
            switch (GetType(instruction))
            {
            case InstructionType.MACRO: return(new AInstruction_Macro(instruction));

            case InstructionType.STARTUP: return(new AInstruction_Startup(AConstQuote.ConstQuoteParse(instruction)));

            case InstructionType.CONST: return(new AInstruction_Const(instruction));

            case InstructionType.CMD: return(new AInstruction_CMD(instruction));

            default: return(new AInstruction_Startup(AConstQuote.ConstQuoteParse(instruction)));
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 执行宏启动项添加指令
 /// </summary>
 /// <param name="macroInstructionParameters">宏添加指令参数列表</param>
 /// <exception cref="FileNotFoundException"></exception>
 /// <exception cref="ConstQuoteParseError"></exception>
 private void ExecuteMacroAddStartup(List <string> macroInstructionParameters)
 {
     try
     {
         string startupName = AConstQuote.ConstQuoteParse(macroInstructionParameters[0]);
         string targetPath  = AConstQuote.ConstQuoteParse(macroInstructionParameters[1]);
         if (AFile.Exists(startupName))
         {
             //throw new NotImplementedException("添加失败,因为启动名 [" + startupName + "] 已经存在。");
             throw new NotImplementedException("Failed to add, because item [" + startupName + "] is already exist.");
         }
         AFile.Add(startupName, targetPath);
         reportType = ReportType.OK;
     }
     catch (FileNotFoundException)
     {
         throw;
     }
     catch (ConstQuoteParseError)
     {
         throw;
     }
 }