コード例 #1
0
ファイル: ResultMatch.cs プロジェクト: TinSyner/github_spider
        public static CmdResult MatchResultToCmdResult(byte[] resultBytes, Encoding encode)
        {
            string result  = GetResultFromInterval(resultBytes, encode);
            string pattern = @"(?<cmd>.*)\[S\]\s*(?<curdir>.*?)\s*\[E\]\s*(?<error>.*)";
            Regex  regex   = new Regex(pattern, RegexOptions.Singleline);
            Match  m       = regex.Match(result);

            if (!m.Success)
            {
                throw new ResponseCustomException(ExceptionTitle.MatchResultFailed.ToString(), "match result failed", result);
            }
            else
            {
                //存在一种情况,错误信息会跟在[E]之后
                string    cmd       = m.Groups["cmd"].Value + m.Groups["error"].Value;
                string    curdir    = m.Groups["curdir"].Value;
                CmdResult cmdResult = new CmdResult();
                cmdResult.Result     = cmd;
                cmdResult.CurrentDir = curdir;
                return(cmdResult);
            }
        }
コード例 #2
0
ファイル: ResultMatch.cs プロジェクト: kevins1022/Altman
 public static CmdResult MatchResultToCmdResult(byte[] resultBytes, Encoding encode)
 {
     string result = GetResultFromInterval(resultBytes, encode);
     string pattern = @"(?<cmd>.*)\[S\]\s*(?<curdir>.*?)\s*\[E\]\s*(?<error>.*)";
     Regex regex = new Regex(pattern, RegexOptions.Singleline);
     Match m = regex.Match(result);
     if (!m.Success)
     {
         throw new ResponseCustomException(ExceptionTitle.MatchResultFailed.ToString(), "match result failed", result);
     }
     else
     {
         //存在一种情况,错误信息会跟在[E]之后
         string cmd = m.Groups["cmd"].Value + m.Groups["error"].Value;
         string curdir = m.Groups["curdir"].Value;
         CmdResult cmdResult = new CmdResult();
         cmdResult.Result = cmd;
         cmdResult.CurrentDir = curdir;
         return cmdResult;
     }
 }