private void TryDetectSchema(string[] lines)
        {
            if (colorSchemas == null || colorSchemas.Count == 0)
            {
                throw new InvalidOperationException("Cannot detect color schema when none have been made available");
            }

            int maxScore = 0;
            int indexOfMax = 0;

            for (int i = 0; i < colorSchemas.Count; i++)
            {
                var cs = colorSchemas[i];
                if (!string.IsNullOrEmpty(cs.SelectorPattern))
                {
                    int score = 0;
                    foreach (var line in lines)
                    {
                        if (line != null && cs.IsMatch(line))
                        {
                            score++;
                        }
                    }
                    if (maxScore < score)
                    {
                        maxScore = score;
                        indexOfMax = i;
                    }
                }
            }

            if (maxScore > 0)
            {
                colorSchema = colorSchemas[indexOfMax];
                autoDetectionPending = false;
                if (filterCounter != null)
                {
                    filterCounter.AnnounceColorSchema(colorSchema);
                }
            }
        }
Example #2
0
 public void AnnounceColorSchema(ColorSchema colorSchema)
 {
     this.colorSchema = colorSchema;
     SetUpTable();
 }