示例#1
0
 private void SetupRandom(string cmd)
 {
     if (cmd.IndexOf(RAND_TAG) != -1)
     {
         randTags = Command.GetNameTags(cmd, RAND_TAG + BRACKET_LEFT_TAG,
                                        BRACKET_RIGHT_TAG);
         if (randTags != null)
         {
             for (IEnumerator it = randTags.GetEnumerator(); it.MoveNext();)
             {
                 string key       = (string)it.Current;
                 object value_ren = CollectionUtils.Get(setEnvironmentList, key);
                 if (value_ren != null)
                 {
                     cmd = StringUtils
                           .ReplaceMatch(cmd, (RAND_TAG + BRACKET_LEFT_TAG
                                               + key + BRACKET_RIGHT_TAG),
                                         value_ren.ToString());
                 }
                 else if (MathUtils.IsNan(key))
                 {
                     cmd = StringUtils
                           .ReplaceMatch(
                         cmd,
                         (RAND_TAG + BRACKET_LEFT_TAG + key + BRACKET_RIGHT_TAG)
                         ,
                         LSystem.random.Next(Int32.Parse(key)).ToString());
                 }
                 else
                 {
                     cmd = StringUtils
                           .ReplaceMatch(cmd, (RAND_TAG + BRACKET_LEFT_TAG
                                               + key + BRACKET_RIGHT_TAG),
                                         LSystem.random.Next().ToString());
                 }
             }
         }
     }
 }
示例#2
0
        public string DoExecute()
        {
            if (isClose)
            {
                return(null);
            }
            this.executeCommand = null;
            this.addCommand     = true;
            this.isInnerCommand = (innerCommand != null);
            this.if_bool        = false;
            this.elseif_bool    = false;

            try
            {
                if (isInnerCommand && isCall)
                {
                    SetVariables(innerCommand.GetVariables());
                    if (innerCommand.Next())
                    {
                        return(innerCommand.DoExecute());
                    }
                    else
                    {
                        InnerCallFalse();
                        return(executeCommand);
                    }
                }
                else if (isInnerCommand && !isCall)
                {
                    SetVariables(innerCommand.GetVariables());
                    if (innerCommand.Next())
                    {
                        return(innerCommand.DoExecute());
                    }
                    else
                    {
                        innerCommand   = null;
                        isInnerCommand = false;
                        return(executeCommand);
                    }
                }

                nowPosFlagName = offsetPos.ToString();
                int length = conditionEnvironmentList.Size();
                if (length > 0)
                {
                    object ifResult = conditionEnvironmentList.Get(length - 1);
                    if (ifResult != null)
                    {
                        backIfBool = (bool)(((Boolean)ifResult));
                    }
                }

                if (scriptList == null)
                {
                    ResetCache();
                    return(executeCommand);
                }
                else if (scriptList.Length - 1 < offsetPos)
                {
                    ResetCache();
                    return(executeCommand);
                }

                string cmd = scriptList[offsetPos];

                if (cmd.StartsWith(RESET_CACHE_TAG))
                {
                    ResetCache();
                    return(executeCommand);
                }

                if (isCache)
                {
                    cacheCommandName = NowCacheOffsetName(cmd);

                    object cache = CollectionUtils.Get(scriptContext, cacheCommandName);
                    if (cache != null)
                    {
                        return((string)cache);
                    }
                }

                if (flaging)
                {
                    flaging = !(cmd.StartsWith(FLAG_LS_E_TAG) || cmd
                                .EndsWith(FLAG_LS_E_TAG));
                    return(executeCommand);
                }

                if (!flaging)
                {
                    if (cmd.StartsWith(FLAG_LS_B_TAG) &&
                        !cmd.EndsWith(FLAG_LS_E_TAG))
                    {
                        flaging = true;
                        return(executeCommand);
                    }
                    else if (cmd.StartsWith(FLAG_LS_B_TAG) &&
                             cmd.EndsWith(FLAG_LS_E_TAG))
                    {
                        return(executeCommand);
                    }
                }

                SetupRandom(cmd);

                SetupSET(cmd);

                if (cmd.EndsWith(END_TAG))
                {
                    functioning = false;
                    return(executeCommand);
                }

                if (cmd.StartsWith(BEGIN_TAG))
                {
                    temps = CommandSplit(cmd);
                    if (temps.Count == 2)
                    {
                        functioning = true;
                        functions.Put(temps[1], new string[0]);
                        return(executeCommand);
                    }
                }

                if (functioning)
                {
                    int      size     = functions.Size() - 1;
                    string[] function = (string[])functions.Get(size);
                    int      index    = function.Length;
                    function        = (string[])CollectionUtils.Expand(function, 1);
                    function[index] = cmd;
                    functions.Set(size, function);
                    return(executeCommand);
                }

                if (((!esleflag && !ifing) || (esleflag && ifing)) &&
                    cmd.StartsWith(CALL_TAG) && !isCall)
                {
                    temps = CommandSplit(cmd);
                    if (temps.Count == 2)
                    {
                        string   functionName = (string)temps[1];
                        string[] funs         = (string[])functions.Get(functionName);
                        if (funs != null)
                        {
                            innerCommand = new Command(scriptName + FLAG
                                                       + functionName, funs);
                            innerCommand.CloseCache();
                            innerCommand.SetVariables(GetVariables());
                            InnerCallTrue();
                            return(null);
                        }
                    }
                }

                if (!if_bool && !elseif_bool)
                {
                    if_bool     = cmd.StartsWith(IF_TAG);
                    elseif_bool = cmd.StartsWith(ELSE_TAG);
                }

                if (if_bool)
                {
                    esleover = esleflag = SetupIF(cmd, nowPosFlagName,
                                                  setEnvironmentList, conditionEnvironmentList);
                    addCommand = false;
                    ifing      = true;
                }
                else if (elseif_bool)
                {
                    string[] value_ren = StringUtils.Split(cmd, " ");
                    if (!backIfBool && !esleflag)
                    {
                        if (value_ren.Length > 1 && IF_TAG.Equals(value_ren[1]))
                        {
                            esleover = esleflag = SetupIF(
                                cmd.Replace(ELSE_TAG, "").Trim(),
                                nowPosFlagName, setEnvironmentList,
                                conditionEnvironmentList);
                            addCommand = false;
                        }
                        else if (value_ren.Length == 1 && ELSE_TAG.Equals(value_ren[0]))
                        {
                            if (!esleover)
                            {
                                esleover = esleflag = SetupIF("if 1==1",
                                                              nowPosFlagName, setEnvironmentList,
                                                              conditionEnvironmentList);
                                addCommand = false;
                            }
                        }
                    }
                    else
                    {
                        esleflag   = false;
                        addCommand = false;
                        conditionEnvironmentList.Put(nowPosFlagName, (bool)(false));
                    }
                }

                if (cmd.StartsWith(IF_END_TAG))
                {
                    conditionEnvironmentList.Clear();
                    backIfBool  = false;
                    addCommand  = false;
                    ifing       = false;
                    if_bool     = false;
                    elseif_bool = false;
                    esleover    = false;
                    return(null);
                }
                if (backIfBool)
                {
                    if (cmd.StartsWith(INCLUDE_TAG))
                    {
                        if (IncludeCommand(cmd))
                        {
                            return(null);
                        }
                    }
                }
                else if (cmd.StartsWith(INCLUDE_TAG) && !ifing && !backIfBool &&
                         !esleflag)
                {
                    if (IncludeCommand(cmd))
                    {
                        return(null);
                    }
                }

                if (cmd.StartsWith(OUT_TAG))
                {
                    isRead         = false;
                    addCommand     = false;
                    executeCommand = (SELECTS_TAG + " " + readBuffer.ToString());
                }

                if (isRead)
                {
                    readBuffer.Append(cmd);
                    readBuffer.Append(FLAG);
                    addCommand = false;
                }

                if (cmd.StartsWith(IN_TAG))
                {
                    readBuffer.Remove(0, readBuffer.Length - (0));
                    isRead = true;
                    return(executeCommand);
                }

                if (addCommand && ifing)
                {
                    if (backIfBool && esleflag)
                    {
                        executeCommand = cmd;
                    }
                }
                else if (addCommand)
                {
                    executeCommand = cmd;
                }

                if (cmd.StartsWith(FLAG_SAVE_TAG))
                {
                    temps = CommandSplit(cmd);
                    if (temps != null && temps.Count == 2)
                    {
                        executeCommand = cmd;
                        SaveCommand(null, null);
                        return(executeCommand);
                    }
                }
                else if (cmd.StartsWith(FLAG_LOAD_TAG))
                {
                    temps = CommandSplit(cmd);
                    if (temps != null && temps.Count == 2)
                    {
                        executeCommand = cmd;
                        LoadCommand(null, -1);
                        return(executeCommand);
                    }
                }

                if (executeCommand != null)
                {
                    printTags = Command.GetNameTags(executeCommand, PRINT_TAG
                                                    + BRACKET_LEFT_TAG, BRACKET_RIGHT_TAG);
                    if (printTags != null)
                    {
                        for (IEnumerator it = printTags.GetEnumerator(); it.MoveNext();)
                        {
                            string key       = (string)it.Current;
                            object value_ren = CollectionUtils.Get(setEnvironmentList, key);
                            if (value_ren != null)
                            {
                                executeCommand = StringUtils
                                                 .ReplaceMatch(
                                    executeCommand,
                                    (PRINT_TAG + BRACKET_LEFT_TAG + key + BRACKET_RIGHT_TAG)
                                    , value_ren.ToString());
                            }
                            else
                            {
                                executeCommand = StringUtils
                                                 .ReplaceMatch(
                                    executeCommand,
                                    (PRINT_TAG + BRACKET_LEFT_TAG + key + BRACKET_RIGHT_TAG)
                                    , key);
                            }
                        }
                    }

                    if (isCache)
                    {
                        CollectionUtils.Put(scriptContext, cacheCommandName, executeCommand);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (!isInnerCommand)
                {
                    offsetPos++;
                }
            }

            return(executeCommand);
        }
示例#3
0
 public static IList GetNameTags(string messages, string startString,
                                 string endString)
 {
     return(Command.GetNameTags(messages.ToCharArray(),
                                startString.ToCharArray(), endString.ToCharArray()));
 }