Beispiel #1
0
        public void SetBlockList(List <PatternBlock> flatBlockList, PatternArgs patternArgs)
        {
            this.patternArgs = patternArgs;
            blockList.Clear();
            List <PatternBlock> singeList = new List <PatternBlock>();

            //int blockId = -1;
            for (int i = 0; i < flatBlockList.Count; ++i)
            {
                PatternBlock block = flatBlockList[i];
                singeList.Add(block);
                //if (block.blockId != blockId)
                //{
                //  singeList = new List<PatternBlock>();
                //  PatternBlock selfRefBlock = new PatternBlock();
                //  selfRefBlock.targetStart = block.startLine;
                //  selfRefBlock.targetEnd = block.endLine;
                //  selfRefBlock.blockId = block.blockId;
                //  singeList.Add(selfRefBlock);
                //  singeList.Add(block);
                //  this.blockList.Add(singeList);
                //  blockId = block.blockId;
                //}
                //else
                //{
                //  singeList.Add(block);
                //}
            }
            this.blockList.Add(singeList);
            this.Invoke(new MethodInvoker(SetBlockListGuiStuff));
        }
		private void AddBlockTargetLinesToDict(Dictionary<int, int> dict, PatternBlock block)
		{
			foreach (int lineNum in block.targetLines.Keys)
			{
				if (!dict.ContainsKey(lineNum))
				{
					dict.Add(lineNum, lineNum);
				}
			}
		}
Beispiel #3
0
 private void patternHitsDataGridView_CurrentCellChanged(object sender, EventArgs e)
 {
     if (this.currentList == null || patternHitsDataGridView.CurrentRow == null)
     {
         return;
     }
     if (patternHitsDataGridView.CurrentRow.Index > this.currentList.Count - 1)
     {
         return;
     }
     this.contentDataGridView.RowCount = 0;
     this.currentBlock = this.currentList[patternHitsDataGridView.CurrentRow.Index];
     this.contentDataGridView.RowCount = this.currentBlock.targetEnd - this.currentBlock.targetStart + 1;
     this.contentDataGridView.Refresh();
     this.contentDataGridView.CurrentCell = this.contentDataGridView.Rows[0].Cells[0];
     this.blockLinesLabel.Text            = "" + this.contentDataGridView.RowCount;
 }
        /// <summary>
        /// Write the current data stored into this object into a specific file
        /// </summary>
        /// <param name="Filename">Name of the file to use for storing data</param>
        /// <returns>True if the file has been written, false otherwise</returns>
        public bool WriteFile(String OutputFilename, String PatternFilename)
        {
            bool          Ret              = false;
            String        ReadPatternLine  = null;
            String        CheckPatternLine = null;
            int           CurrentLoop      = -1;
            List <String> PatternBlock     = null;

            if ((OutputFilename != null) && (PatternFilename != null) && (_Items.Count() > 0))
            {
                // Create the output file and open the pattern file
                TextFile PatternFile = new TextFile(PatternFilename);
                _File = new TextFile();

                if (_File != null)
                {
                    for (int i = 1; i <= PatternFile.GetSize(); i++)
                    {
                        // Check all line to change patterns into real value
                        ReadPatternLine = PatternFile.GetLine(i);

                        if (ReadPatternLine != null)
                        {
                            // Check line to remove unused char
                            CheckPatternLine = ReadPatternLine;
                            CheckPatternLine = CheckPatternLine.Replace("\t", "");

                            if (CheckPatternLine == "// LoopID = 'LOOPID'")
                            {
                                // Create the pattern block
                                PatternBlock = new List <string>();
                                CurrentLoop++;  // Update the current LoopID
                                _File.AddLine(ReadPatternLine.Replace("'LOOPID'", CurrentLoop.ToString()));
                            }

                            if (CheckPatternLine == "// StructuredFileLoopEnd")
                            {
                                if ((PatternBlock != null) && (PatternBlock.Count() > 1))
                                {
                                    // Extact values ordered by GID
                                    List <StructValueList> KeyValues = ExtractValues(CurrentLoop);
                                    if (KeyValues != null)
                                    {
                                        int PatternIterator = 1;    // The first line contains the LOOPID

                                        // Check all items and write only items from current Loop
                                        foreach (StructValueList Values in KeyValues)
                                        {
                                            // Create pattern line
                                            if (PatternIterator >= PatternBlock.Count())
                                            {
                                                PatternIterator = 1;    // The first line contains the LOOPID
                                            }
                                            string ExportLine = PatternBlock[PatternIterator];

                                            // We have found value for the current GID, we split it to add them to the specific loop
                                            string[] KeyToAdd   = Values.KeyList.Split('|');
                                            string[] ValueToAdd = Values.ValueList.Split('|');

                                            // Change the 'PATTERN_COUNTER' value
                                            ExportLine = ExportLine.Replace("'PATTERN_COUNTER'", Values.CaseID.ToString());

                                            // Write values into final string
                                            for (int j = 0; j < KeyToAdd.Length; j++)
                                            {
                                                ExportLine = ExportLine.Replace("'" + KeyToAdd[j] + "'", ValueToAdd[j]);
                                            }

                                            // Write final line
                                            _File.AddLine(ExportLine);
                                        }
                                    }
                                }

                                // Clear PatternBlock
                                PatternBlock = null;
                            }

                            if (PatternBlock == null)
                            {
                                foreach (StructuredFileKey PatternKey in _Items)
                                {
                                    if (PatternKey.GetLoopID() == -1)
                                    {
                                        ReadPatternLine = ReadPatternLine.Replace("'" + PatternKey.GetName() + "'", PatternKey.GetValue());
                                    }
                                }

                                _File.AddLine(ReadPatternLine);
                            }
                            else
                            {
                                // We are reading a pattern block, we add this line into PatternBlock
                                PatternBlock.Add(ReadPatternLine);
                            }
                        }
                    }
                }
            }

            _File.Save(OutputFilename);
            return(Ret);
        }
		private PatternBlock DetectBlock(int startNum, int startLineToSearch, int maxBlockLen, int maxDiffInBlock, int maxMisses, Dictionary<int, int> processedLinesDict, ILogWindowSearch logWindow)
		{
			int targetLine = FindSimilarLine(startNum, startLineToSearch, processedLinesDict, logWindow);
			if (targetLine == -1)
			{
				return null;
			}

			PatternBlock block = new PatternBlock();
			block.startLine = startNum;
			int srcLine = block.startLine;
			block.targetStart = targetLine;
			int srcMisses = 0;
			block.srcLines.Add(srcLine, srcLine);
			int len = 0;
			QualityInfo qi = new QualityInfo();
			qi.Quality = block.weigth;
			block.qualityInfoList[targetLine] = qi;

			while (!logWindow.ShouldCancel)
			{
				srcLine++;
				len++;
				if (maxBlockLen > 0 && len > maxBlockLen)
				{
					break;
				}
				int nextTargetLine = FindSimilarLine(srcLine, targetLine + 1, processedLinesDict, logWindow);
				if (nextTargetLine > -1 && nextTargetLine - targetLine - 1 <= maxDiffInBlock)
				{
					block.weigth += maxDiffInBlock - (nextTargetLine - targetLine - 1) + 1;
					block.endLine = srcLine;
					block.srcLines.Add(srcLine, srcLine);
					if (nextTargetLine - targetLine > 1)
					{
						int tempWeight = block.weigth;
						for (int tl = targetLine + 1; tl < nextTargetLine; ++tl)
						{
							qi = new QualityInfo();
							qi.Quality = --tempWeight;
							block.qualityInfoList[tl] = qi;
						}
					}
					targetLine = nextTargetLine;
					qi = new QualityInfo();
					qi.Quality = block.weigth;
					block.qualityInfoList[targetLine] = qi;
				}
				else
				{
					srcMisses++;
					block.weigth--;
					targetLine++;
					qi = new QualityInfo();
					qi.Quality = block.weigth;
					block.qualityInfoList[targetLine] = qi;
					if (srcMisses > maxMisses)
					{
						break;
					}
				}
			}
			block.targetEnd = targetLine;
			qi = new QualityInfo();
			qi.Quality = block.weigth;
			block.qualityInfoList[targetLine] = qi;
			for (int k = block.targetStart; k <= block.targetEnd; ++k)
			{
				block.targetLines.Add(k, k);
			}
			return block;
		}
            private List<PatternBlock> CreateDetailedPattern()
            {
                var pattern = new List<PatternBlock>();

                var patternBlock = new PatternBlock();

                for (var i = 0; i < _patternSequence.Length; i++)
                {
                    if (patternBlock.Type == PatternBlockType.Undefined)
                    {
                        if (_patternSequence[i] == Any)
                        {
                            patternBlock.Type = PatternBlockType.Gap;
                            patternBlock.Start = 1;
                            patternBlock.Stop = 1;
                        }
                        else if (_patternSequence[i] == ZeroOrMany)
                        {
                            patternBlock.Type = PatternBlockType.Gap;
                            patternBlock.Start = 0;
                            patternBlock.Stop = long.MaxValue;
                        }
                        else
                        {
                            patternBlock.Type = PatternBlockType.Elements;
                            patternBlock.Start = i;
                            patternBlock.Stop = i;
                        }
                    }
                    else if (patternBlock.Type == PatternBlockType.Elements)
                    {
                        if (_patternSequence[i] == Any)
                        {
                            pattern.Add(patternBlock);

                            patternBlock = new PatternBlock
                            {
                                Type = PatternBlockType.Gap,
                                Start = 1,
                                Stop = 1
                            };
                        }
                        else if (_patternSequence[i] == ZeroOrMany)
                        {
                            pattern.Add(patternBlock);

                            patternBlock = new PatternBlock
                            {
                                Type = PatternBlockType.Gap,
                                Start = 0,
                                Stop = long.MaxValue
                            };
                        }
                        else
                        {
                            patternBlock.Stop = i;
                        }
                    }
                    else // patternBlock.Type == PatternBlockType.Gap
                    {
                        if (_patternSequence[i] == Any)
                        {
                            patternBlock.Start++;

                            if (patternBlock.Stop < patternBlock.Start)
                                patternBlock.Stop = patternBlock.Start;
                        }
                        else if (_patternSequence[i] == ZeroOrMany)
                        {
                            patternBlock.Stop = long.MaxValue;
                        }
                        else
                        {
                            pattern.Add(patternBlock);

                            patternBlock = new PatternBlock
                            {
                                Type = PatternBlockType.Elements,
                                Start = i,
                                Stop = i
                            };
                        }
                    }
                }

                if (patternBlock.Type != PatternBlockType.Undefined)
                    pattern.Add(patternBlock);

                return pattern;
            }