예제 #1
0
        public static ListVar getOrCreateListVar(String listVarName, List <String> list)
        {
            ListVar listVar = new ListVar();

            listVar.varName = listVarName;
            listVar.list    = list;
            LogProcessor.variables[listVar.varName] = listVar;
            return(listVar);
        }
예제 #2
0
 public static ListVar getOrCreateListVar(String listVarName)
 {
     if (LogProcessor.variables[listVarName] != null)
     {
         return((ListVar)LogProcessor.variables[listVarName]);
     }
     else
     {
         ListVar listVar = new ListVar();
         listVar.varName = listVarName;
         listVar.list    = new List <string>();
         LogProcessor.variables[listVar.varName] = listVar;
         return(listVar);
     }
 }
예제 #3
0
        public override string calculate(string input)
        {
            List <String> blocksParsed = new List <String>();
            List <String> firstLines   = new List <String>();

            String[] lines = input.Split(ProgramNode.NEWLINE, StringSplitOptions.None);

            //Start out by finding all indexes for matches for up and down counts
            List <int> indexsUp = input.AllIndexesOf(first);

            List <int> indexsDown = input.AllIndexesOf(last);

            List <int> indexsLine = input.AllIndexesOf(Environment.NewLine);
            //then use that to find what line the first block starts
            int count       = 0;
            int upCounter   = 0;
            int downCounter = 0;

            int upIndex, downIndex;

            while (upCounter < indexsUp.Count)
            {
                int    upCharLocation = indexsUp[upCounter];
                int    lineNumUp      = getLine(indexsLine, upCharLocation);
                String firstLine      = lines[lineNumUp];
                if (firstLine.Contains(first))
                {
                    //start parsing down counting
                    count++;
                    upCounter++;
                    while (count > 0 && downCounter < indexsDown.Count)
                    {
                        int nextDownCharLocation = indexsDown[downCounter];

                        int nextUpCharLocation;
                        if (upCounter < indexsUp.Count)
                        {
                            nextUpCharLocation = indexsUp[upCounter];
                        }
                        else
                        {
                            nextUpCharLocation = int.MaxValue;
                        }

                        if (nextDownCharLocation < nextUpCharLocation)
                        {
                            count--;
                            downCounter++;
                            if (count == 0)
                            {
                                int length = nextDownCharLocation - upCharLocation - first.Length;
                                blocksParsed.Add(input.Substring(upCharLocation + first.Length, length));
                                if (listFirstLines != null && listFirstLines.Length >= 1)
                                {
                                    firstLines.Add(firstLine);
                                }
                            }
                        }
                        else
                        {
                            upCounter++;
                            count++;
                        }
                    }
                }
            }
            //Once we find the first block, we must find the final block, for every extra first we find, we must increment the number of lasts we need



            if (listToPopulate != null && listToPopulate.Length >= 1)
            {
                //TODO populate the list
                ListVar listVar = new ListVar();
                listVar.varName = listToPopulate;
                listVar.list    = blocksParsed;
                LogProcessor.variables[listVar.varName] = listVar;
            }

            return(blocksParsed.Select(x => x.ToString()).Aggregate((x, y) => x + Environment.NewLine + y));
        }