コード例 #1
0
ファイル: App.xaml.cs プロジェクト: LadislavBohm/IptSimulator
        private void UpdateHighlightingFile(XDocument syntaxXml)
        {
            _logger.Info("Updating syntax file for custom TCL commands and events");

            if (syntaxXml.Root == null)
            {
                throw new ArgumentException("TCL syntax file does not contain root node.");
            }
            var keywords = syntaxXml.Root.Descendants().First(e => e.Name.LocalName == "Keywords");
            var ns       = syntaxXml.Root.GetDefaultNamespace();

            _logger.Debug("Adding TCL keywords.");
            foreach (var keyword in TclKeywords.All)
            {
                _logger.Trace($"Adding TCL keyword {keyword} to keywords.");
                keywords.Add(new XElement(ns + "Word", keyword));
            }

            _logger.Debug("Adding custom TCL commands.");
            foreach (var tclCommand in TclCommandProvider.GetCustomCommands())
            {
                _logger.Debug($"Adding {tclCommand} TCL command to keywords.");
                keywords.Add(new XElement(ns + "Word", tclCommand.Name));
            }

            _logger.Info("Syntax file successfully updated.");
        }
コード例 #2
0
        private TclVoiceInterpreter(Interpreter interpreter)
        {
            _interpreter = interpreter;
            Result result = null;

            var customCommands = TclCommandProvider.GetCustomCommands();

            Logger.Info("Adding custom TCL commands.");
            foreach (var customCommand in customCommands)
            {
                long token = 0;
                Logger.Debug($"Adding {customCommand.Name} command.");
                var code = interpreter.AddCommand(customCommand, null, ref token, ref result);

                if (code != ReturnCode.Ok)
                {
                    Logger.Warn($"Failed to add {customCommand.Name} command. Error: {result}");
                }

                SubscribeToInputCommand(customCommand as CiscoTclCommand);
                SubscribeToBreakpointCommand(customCommand as Breakpoint);
                SubscribeToFsmCommand(customCommand as Fsm);
            }

            void SubscribeToFsmCommand(Fsm fsmCommand)
            {
                if (fsmCommand == null)
                {
                    return;
                }
                fsmCommand.FsmGenerated += (sender, args) => RaiseFsmGeneratedEvent(args);
                fsmCommand.StateChanged += (sender, args) => RaiseFsmStateChangedEvent(args);
            }

            void SubscribeToBreakpointCommand(Breakpoint breakpoint)
            {
                if (breakpoint == null)
                {
                    return;
                }
                breakpoint.BreakpointHit += OnBreakpointHit;
            }

            void SubscribeToInputCommand(CiscoTclCommand command)
            {
                if (command == null)
                {
                    return;
                }
                if (command is IInputRequestingCommand <DigitsInputData> digitInput)
                {
                    digitInput.OnInputRequested += DigitInputOnOnInputRequested;
                }
                foreach (var subCommand in command.TclSubCommands.OfType <IInputRequestingCommand <DigitsInputData> >())
                {
                    subCommand.OnInputRequested += DigitInputOnOnInputRequested;
                }
            }
        }
コード例 #3
0
        static TclCompletionManager()
        {
            try
            {
                Logger.Info("Initializing completion data...");

                _tclEvents = new HashSet <ICompletionResult>();
                foreach (var tclEvent in CiscoTclEvents.All)
                {
                    _tclEvents.Add(new CompletionResult(tclEvent, 3));
                }

                _tclKeywords = new HashSet <ICompletionResult>();
                foreach (var keyword in TclKeywords.All)
                {
                    _tclKeywords.Add(new CompletionResult(keyword, 1));
                }

                _customTclCommands = new HashSet <ICompletionResult>();
                foreach (var command in TclCommandProvider.GetCustomCommands())
                {
                    _customTclCommands.Add(new CompletionResult(command.Name, 1));
                }

                _allCompletions = new HashSet <ICompletionResult>();
                _allCompletions.UnionWith(_tclKeywords);
                _allCompletions.UnionWith(_tclEvents);
                _allCompletions.UnionWith(_customTclCommands);

                Logger.Info("Completion data were successfully initialized.");
            }
            catch (Exception e)
            {
                Logger.Error(e, "Error while intializing completion data.");
                throw;
            }
        }