コード例 #1
0
        public bool ExecuteStep(ParsingArguments modifiedArguments, out ParsingArguments parsingArguments)
        {
            parsingArguments = null;

            if (modifiedArguments != null && modifiedArguments.ArgumentsChanged)
            {
                UpdateModifiedCounters(modifiedArguments);
            }

            if (CurrentIndex >= html.Length)
            {
                return(false);
            }

            char currentCharacter = html[CurrentIndex];

            CharacterTypes characterType = currentCharacter.ToCharacterType();

            UpdateCounters(characterType);

            transitionManager.Move(characterType, out AdditionalOperations[] additionalOperations);

            HandleState(transitionManager.CurrentState);
            HandleAdditionalOperations(additionalOperations, currentCharacter, buffer);

            parsingArguments = new ParsingArguments(CurrentIndexInLine, CurrentIndex, CurrentLine, stack);

            return(true);
        }
コード例 #2
0
        public CANDatabase ParseFile(FileModel file, ParsingArguments arguments)
        {
            string      line;
            CANDatabase dbcObject = new CANDatabase();

            dbcObject.Name     = file.Name;
            dbcObject.Messages = new List <Message>();

            using FileStream fileStream = File.OpenRead(file.Location);
            using var streamReader      = new StreamReader(fileStream);

            while ((line = streamReader.ReadLine()) != null)
            {
                if (LinePrefix.CheckLine(line, "BU_"))
                {
                    dbcObject.NetworkNodes = NetworkNodeParser.ParseLine(line);
                }
                else if (LinePrefix.CheckLine(line, "BO_"))
                {
                    Message message = MessageParser.ParseLine(line, arguments.Messages);

                    dbcObject.Messages.Add(message);
                }
                else if (LinePrefix.CheckLine(line, " SG_"))
                {
                    Signal signal = SignalParser.ParseLine(line, arguments.Signals);

                    int indexOfLast = dbcObject.Messages.Count - 1;
                    dbcObject.Messages[indexOfLast].Signals.Add(signal);
                }
            }
            return(dbcObject);
        }
コード例 #3
0
 public void ExecuteAdditionalParsers(ParsingArguments parsingArguments)
 {
     foreach (var parser in parsers.OrderBy(par => par.ExecutionOrder))
     {
         parser.Parse(parsingArguments);
     }
 }
コード例 #4
0
        public ParsingResult Parse(string html, AdditionalParsersManager additionalParsersManager)
        {
            mainParser.Initialize(html);

            ParsingArguments parsingArguments = null;

            while (mainParser.ExecuteStep(parsingArguments, out parsingArguments))
            {
                additionalParsersManager.ExecuteAdditionalParsers(parsingArguments);
            }

            mainParser.Validate();
            return(mainParser.ParsingResult);
        }
コード例 #5
0
 public void Parse(ParsingArguments parsingArguments)
 {
     foreach (var script in Scripts)
     {
         if (script.StartIndex <= parsingArguments.CurrentIndex && script.EndIndex >= parsingArguments.CurrentIndex)
         {
             if (parsingArguments.Stack.TryPeek(out var topHtmlElement))
             {
                 topHtmlElement.Value = script.Value;
                 parsingArguments.ChangeIndexes(script.EndIndex, 0, parsingArguments.CurrentLine + script.Value.Count(c => c == '\n'));
                 break;
             }
         }
     }
 }
コード例 #6
0
        public void DbcParserShouldReturnCorrectValues()
        {
            var dbcParser = new DbcParser();

            string    location = "../../../DbcExamples/All_msg_types.dbc";
            FileModel file     = new FileModel("All_msg_types.dbc", location);

            ParsingArguments parsingArguments = new ParsingArguments()
            {
                Messages = { "MessageId", "Name" },
                Signals  = { "Name", "StartBit", "Length" }
            };

            var result = dbcParser.ParseFile(file, parsingArguments);

            int networkNodescount = result.NetworkNodes.Count;

            Assert.True(networkNodescount == 20);

            int totalMessageCount = result.Messages.Count;

            Assert.True(totalMessageCount == 21);

            int totalSignalCount = 0;

            foreach (Message message in result.Messages)
            {
                foreach (Signal signal in message.Signals)
                {
                    Assert.True(signal != null);
                    totalSignalCount++;
                }
            }
            Assert.True(totalSignalCount == 256);

            int lastMessageSignalCount = result.Messages[totalMessageCount - 1].Signals.Count;

            Assert.True(lastMessageSignalCount == 71);

            var firstSignal = result.Messages[0].Signals[0];

            Assert.True(firstSignal.Name == "Sig_BE_UInt_2" && firstSignal.StartBit == 0 && firstSignal.Length == 7);

            var lastSignal = result.Messages[totalMessageCount - 1].Signals[lastMessageSignalCount - 1];

            Assert.True(lastSignal.Name == "cell_voltage_070" && lastSignal.StartBit == 56 && lastSignal.Length == 8);
        }
コード例 #7
0
        public void Add(FileModel file)
        {
            ParsingArguments parsingArguments = new ParsingArguments()
            {
                Messages = { "MessageId", "Name" },
                Signals  = { "Name", "StartBit", "Length" }
            };

            try
            {
                CANDatabase canDb = _dbcParser.ParseFile(file, parsingArguments);
                _db.CANDatabases.Add(canDb);
                _db.SaveChanges();
                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
 private void UpdateModifiedCounters(ParsingArguments modifiedArguments)
 {
     CurrentIndex       = modifiedArguments.CurrentIndex;
     CurrentIndexInLine = modifiedArguments.CurrentIndexInLine;
     CurrentLine        = modifiedArguments.CurrentLine;
 }