예제 #1
0
파일: Script.cs 프로젝트: yonglehou/OpenIDE
        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);
        }
예제 #2
0
        public void Handle(bool error, string m)
        {
            if (m == null)
            {
                return;
            }

            var cmdText   = "command|";
            var eventText = "event|";

            if (error)
            {
                if (_dispatchErrors)
                {
                    _outputDispatcher(_eventPrefix, "error|" + m);
                }
            }
            else
            {
                if (m.StartsWith(cmdText))
                {
                    Logger.Write("Handling command " + m);
                    var toDispatch = m.Substring(cmdText.Length, m.Length - cmdText.Length);
                    var args       = toDispatch.Split(new[]   {
                        " "
                    }, StringSplitOptions.RemoveEmptyEntries);
                    if (args.Length > 1 && args[0] == "editor")
                    {
                        var _editor = _editorFactory();
                        if (_editor == null)
                        {
                            return;
                        }
                        _editor.Send(toDispatch.Substring(6, toDispatch.Length - 6).Trim());
                    }
                    else
                    {
                        _dispatcher(toDispatch);
                    }
                }
                else if (m.StartsWith(eventText))
                {
                    if (_onlyCommands)
                    {
                        return;
                    }
                    _dispatcher(m.Substring(eventText.Length, m.Length - eventText.Length));
                }
                else if (_requestRunner.IsRequest(m))
                {
                    if (_onlyCommands)
                    {
                        return;
                    }
                    var response = _requestRunner.Request(m);
                    foreach (var content in response)
                    {
                        _dispatchResponse(content);
                    }
                }
                else
                {
                    if (_onlyCommands)
                    {
                        return;
                    }
                    _outputDispatcher(_eventPrefix, m);
                }
            }
        }