public ResponseDispatcher(string token, bool dispatchErrors, string eventPrefix, Action<string,string> outputDispatcher, Action<string> dispatcher, Action<string> dispatchResponse)
 {
     _token = token;
     _outputDispatcher = outputDispatcher;
     _dispatchErrors = dispatchErrors;
     _eventPrefix = eventPrefix;
     _dispatcher = dispatcher;
     _dispatchResponse = dispatchResponse;
     _requestRunner = new RequestRunner(_token);
     _editorFactory = () => {
         if (_editor == null) {
             var locator = new OpenIDE.Core.EditorEngineIntegration.EngineLocator(new OpenIDE.Core.FileSystem.FS());
             _editor = locator.GetInstance(_token);
         }
         return _editor;
     };
 }
Esempio n. 2
0
        public void Run(string arguments, Action<string> onLine)
        {
            var process = new Process();
            _isRunning = true;
            var stdinForwarder = new Thread(() => {
                try {
                    while (_isRunning) {
                        var line = Console.ReadLine();
                        process.Write(line);
                    }
                } catch {
                }
            });
            stdinForwarder.Start();

            Logger.Write("Running script {0} with {1}", _file, arguments);
            arguments = "{global-profile} {local-profile} " + arguments;
            run(
                arguments,
                (m) => {
                    var requestRunner = new RequestRunner(_token);
                    if (requestRunner.IsRequest(m)) {
                        ThreadPool.QueueUserWorkItem((msg) => {
                            var response = requestRunner.Request(msg.ToString());
                            foreach (var content in response)
                                process.Write(content);
                        },
                        m);
                    } else {
                        onLine(m);
                    }
                },
                new[] {
                        new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
                        new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
                },
                process);
            _isRunning = false;
            stdinForwarder.Abort();
            Logger.Write("Running script completed {0}", _file);
        }