Exemple #1
0
    //void SetParamData()
    //{
    //   // SetParamName();
    //    SetChildParam();
    //}

    private void SetParamName()
    {
        if (Arg == null)
        {
            return;
        }

        if (Arg.Length >= 2)//形式如:a(b)  最少是4个字符
        {
            if (Arg.StartsWith("“") || Arg.StartsWith("”"))
            {
                Arg = Arg.Substring(1);
            }
            if (Arg.EndsWith("“") || Arg.EndsWith("”"))
            {
                Arg = Arg.Substring(0, Arg.Length - 1);
            }
            int leftBracketIndex = Arg.IndexOf(ParamNameLeft);
            // int rightBracketIndex = paramString.LastIndexOf(')');

            ParamName = Arg.Substring(0, leftBracketIndex);
        }
        else
        {
            ParamName = null;
        }
    }
Exemple #2
0
        public static void Explode(string[] Args)
        {
            foreach (string Arg in Args)
            {
                if (Arg.StartsWith(StartChar.ToString()) && Arg.EndsWith(EndBrackets.ToString()) && Arg.Count(C => C == StartChar) == 1 && Arg.Count(C => C == StartBrackets) == 1 && Arg.Count(C => C == EndBrackets) == 1)
                {
                    foreach (string Type in ArgType)
                    {
                        string Val1 = Arg.Substring(Arg.IndexOf(StartChar) + 1, Arg.IndexOf(StartBrackets) - 1);
                        if (Val1 == Type)
                        {
                            string Val2 = Arg.Substring(Arg.IndexOf(StartBrackets) + 1, Arg.IndexOf(EndBrackets) - Arg.IndexOf(StartBrackets) - 1);
                            if (Val1 == "user" && string.IsNullOrEmpty(ArgUser))
                            {
                                ArgUser = Val2;
                            }

                            break;
                        }
                    }
                }
            }
        }
Exemple #3
0
    private void SetChildParam(int i)
    {
        if (Arg == null)
        {
            return;
        }

        AppLog.Log(string.Format("检查参数:{0}", Arg), ConsoleColor.Green);

        if (Arg.Length >= 2)//形式如:a(b)  最少是4个字符
        {
            if (Arg.StartsWith("“") || Arg.StartsWith("”"))
            {
                Arg = Arg.Substring(1);
            }
            if (Arg.EndsWith("“") || Arg.EndsWith("”"))
            {
                Arg = Arg.Substring(0, Arg.Length - 1);
            }
            int leftBracketIndex = Arg.IndexOf(ParamNameLeft);
            // int rightBracketIndex = paramString.LastIndexOf(')');

            ParamName = Arg.Substring(0, leftBracketIndex);
        }
        else
        {
            ParamName = null;
            AppLog.LogErrorAndExit(string.Format("第{0}个参数错误,{1}", i, Arg));
        }


        if (Arg.Length >= 4)//形式如:a(b)  最少是4个字符
        {
            int leftBracketIndex  = Arg.IndexOf(ParamNameLeft);
            int rightBracketIndex = Arg.LastIndexOf(ParamNameRight);
            if (rightBracketIndex == -1)
            {
                AppLog.LogErrorAndExit(string.Format("参数{0}错误,应形如:类型(参数1=值1)", Arg));
            }

            string paramStringAll = Arg.Substring(leftBracketIndex + 1, rightBracketIndex - leftBracketIndex - 1);

            // 通过|分隔各个参数,但因为用户设置的TXT文件中的字段分隔符本身可能为|,本工具采用\|配置进行转义,故需要自行从头遍历查找真正的参数分隔符
            // 记录参数分隔符的下标位置
            List <int> splitParamCharIndex = new List <int>();

            for (int index = 0; index < paramStringAll.Length; ++index)
            {
                char c = paramStringAll[index];
                if (c == ChildParamSplit && (index < 1 || (index > 1 && paramStringAll[index - 1] != '\\')))
                {
                    splitParamCharIndex.Add(index);
                }
            }

            // 通过识别的参数分隔符,分隔各个参数
            List <string> paramStringList         = new List <string>();
            int           lastSplitParamChatIndex = -1;
            foreach (int index in splitParamCharIndex)
            {
                paramStringList.Add(paramStringAll.Substring(lastSplitParamChatIndex + 1, index - lastSplitParamChatIndex - 1));
                lastSplitParamChatIndex = index;
            }
            // 还要加上最后一个|后面的参数
            if (lastSplitParamChatIndex == -1)
            {
                paramStringList.Add(paramStringAll);
            }
            else if (lastSplitParamChatIndex + 1 < paramStringAll.Length - 1)
            {
                paramStringList.Add(paramStringAll.Substring(lastSplitParamChatIndex + 1));
            }


            string[] param = null;
            foreach (string s in paramStringList)
            {
                if (!s.Contains(ChildParamValueSplit.ToString()))
                {
                    AppLog.LogErrorAndExit(string.Format("错误:BAT参数{0}\n中的{1}设置有错误,应该是形如:参数1=值1", Arg, s));
                }

                param = s.Split(new char[] { ChildParamValueSplit }, StringSplitOptions.RemoveEmptyEntries);
                //是否需要判断param[0], param[1]不为空???

                if (param.Length < 2)
                {
                    AppLog.LogErrorAndExit(string.Format("错误:BAT参数{0}\n中的{1}设置有错误,应该是形如:参数1=值1", Arg, s));
                }

                BatChildParam batChildParam = new BatChildParam(param[1].Trim(), ChildParamListSplit);

                if (!ChildParam.ContainsKey(param[0].Trim()))
                {
                    ChildParam.Add(param[0].Trim(), batChildParam);
                }
                else
                {
                    AppLog.LogErrorAndExit(string.Format("bat参数错误,存在2个以上同名子参数,{0}", Arg));
                }
            }
        }
        else
        {
            AppLog.LogErrorAndExit(string.Format("bat参数错误,应该为形式如:a(b)  最少是4个字符,{0}", Arg));
        }

        AppLog.Log("检查完成,正确");
    }