public override IEnumerable <CAN.Message> ParseLines(IEnumerable <string> lines, IPluginLineFilterV1 filter = null)
        {
            foreach (var line in lines)
            {
                var parsedLine = KvaserLine.Parse(line);
                // If we have a problem with the parsed line, just forget about it
                if (parsedLine == null)
                {
                    continue;
                }

                // If we've got a filter
                if (filter != null)
                {
                    // use it
                    if (filter.ShouldAcceptLine(parsedLine.Message))
                    {
                        var parsedMessage = parsedLine.Message;
                        yield return(parsedMessage);
                    }
                    else
                    {
                        // This message didn't meet the filter
                        continue;
                    }
                }
                else
                {
                    // no filter, yield this element
                    yield return(parsedLine.Message);
                }
            }
            yield break;
        }
Exemple #2
0
        /*/ Unused currently
         *      public static async Task<List<KvaserLine>> ParseStream(Stream s)
         *      {
         *              var ret = new List<KvaserLine>();
         *
         *              var streamLength = s.Length;
         *              using (StreamReader sr = new StreamReader(s))
         *              {
         *                      while (!sr.EndOfStream)
         *                      {
         *                              var progress = ((double)sr.BaseStream.Position / (double)sr.BaseStream.Length) * 100.0d;
         *                              var currentLineStr = await sr.ReadLineAsync();
         *                              var currentLine = KvaserLine.Parse(currentLineStr);
         *                              Debug.WriteLine(currentLine);
         *                              ret.Add(currentLine);
         *                      }
         *              }
         *
         *              return ret;
         *      }
         * //*/

        public static List <KvaserLine> ParseLines(string[] lines, IPluginLineFilterV1 filter = null)
        {
            // first strip the header out
            StripHeader(ref lines);

            var ret          = new List <KvaserLine>();
            var pastProgress = 0;

            for (int i = 0; i < lines.Length; i++)
            {
                var curProgress = ((i * 100) / lines.Length);
                if (curProgress != pastProgress)
                {
                    pastProgress = curProgress;
                    //Debug.WriteLine(curProgress);
                }

                var currentLineStr = lines[i];
                var currentLine    = KvaserLine.Parse(currentLineStr);
                if (currentLine.Message != null)
                {
                    if (filter != null)
                    {
                        if (filter.ShouldAcceptLine(currentLine.Message))
                        {
                            ret.Add(currentLine);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        // we have no filter, accept all
                        ret.Add(currentLine);
                    }
                }
            }

            return(ret);
        }
 public override CAN.Message ParseLine(string line)
 {
     return(KvaserLine.Parse(line).Message);
 }