public Handle ( bool error, string m ) : void | ||
error | bool | |
m | string | |
return | void |
private void startService() { _service = new Process(); try { var responseDispatcher = new ResponseDispatcher( _keyPath, _dispatchErrors, "rscript-" + Name + " ", _outputDispatcher, internalDispatch, (response) => _service.Write(response) ); _service.SetLogger((logMsg) => Logger.Write(logMsg)); _service.Query( _file, "{global-profile} {local-profile}", false, _keyPath, (error, m) => { if (m == null) return; Logger.Write("request doing " + m); if (error) { Logger.Write("rscript-" + Name + " produced an error:"); Logger.Write("rscript-" + Name + "-" + m); } responseDispatcher.Handle(error, m); }, new[] { new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""), new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"") }); Logger.Write("Exiting service script"); } catch (Exception ex) { internalDispatch("rscript-" + Name + " " + ex.ToString()); Logger.Write(ex.ToString()); } }
public static CommandEndpoint GetEndpoint(string path, string[] enabledLanguages) { _path = path; var reader = new ConfigReader(_path); _interpreters = new Interpreters(_path); ProcessExtensions.GetInterpreter = (file) => { var interpreters = _interpreters .GetInterpreterFor(Path.GetExtension(file)); return interpreters; }; _cache = new TypeCache(); _outputEndpoint = new OutputEndpoint(_path); Logger.Write("Event endpoint serving on port: {0}", _outputEndpoint.Port); var responseDispatcher = new ResponseDispatcher( _path, false, "language-output ", (p, m) => _outputEndpoint.Send(p, m), (m) => _endpoint.Handle(m), (m) => {} ); responseDispatcher.OnlyCommands(); _pluginLocator = new PluginLocator( enabledLanguages, new ProfileLocator(_path), (msg) => { responseDispatcher.Handle(false, msg); } ); initPlugins(_pluginLocator); _eventEndpoint = new EventEndpoint(_path, _pluginLocator, _outputEndpoint); _eventEndpoint.Start(); Logger.Write("Event endpoint listening on port: {0}", _eventEndpoint.Port); Logger.Write("Creating plugin file tracker"); _tracker = new PluginFileTracker(); Logger.Write("Starting plugin file tracker"); var ignoreDirSetting = reader.Get("oi.ignore.directories"); var ignoreDirectories = new string[] {}; if (ignoreDirSetting != null) { ignoreDirectories = ignoreDirSetting .Split(new[] {','}) .Select(x => { if (Path.IsPathRooted(x)) { return x; } return Path.Combine(_path, x); }) .ToArray(); } _tracker.Start( _path, _cache, _cache, _pluginLocator, _eventEndpoint, ignoreDirectories); Logger.Write("Plugin file tracker started"); _endpoint = new CommandEndpoint(_path, _cache, _eventEndpoint); _endpoint.AddHandler(messageHandler); _handlers.AddRange(new IHandler[] { new GetProjectsHandler(_endpoint, _cache), new GetFilesHandler(_endpoint, _cache), new GetCodeRefsHandler(_endpoint, _cache), new GetSignatureRefsHandler(_endpoint, _cache), new GoToDefinitionHandler(_endpoint, _cache, _pluginLocator), new FindTypeHandler(_endpoint, _cache), new SnippetEditHandler(_endpoint, _cache, _path), new SnippetDeleteHandler(_cache, _path), new GetRScriptStateHandler(_endpoint, _eventEndpoint), new CompleteSnippetHandler(_cache, _path, _endpoint), new WriteOutputHandler(_eventEndpoint), new GetTokenPathHandler(_endpoint), // Make sure this handler is the last one since the command can be file extension or language name new LanguageCommandHandler(_endpoint, _cache, _pluginLocator) }); Logger.Write("Command endpoint started"); return _endpoint; }
private void runScript(string message) { if (_isFaulted) return; var originalMessage = message; message = "{event} {global-profile} {local-profile}"; Logger.Write("Running: " + _file + " " + message); ThreadPool.QueueUserWorkItem((task) => { try { var process = new Process(); var responseDispatcher = new ResponseDispatcher( _keyPath, _dispatchErrors, "rscript-" + Name + " ", _outputDispatcher, internalDispatch, (response) => process.Write(response) ); process.SetLogger((logMsg) => Logger.Write(logMsg)); var msg = task.ToString(); process.Query( _file, msg, false, _keyPath, (error, m) => { if (m == null) return; Logger.Write("request doing " + m); if (error) { Logger.Write("rscript-" + Name + " produced an error:"); Logger.Write("rscript-" + Name + "-" + m); } responseDispatcher.Handle(error, m); }, new[] { new KeyValuePair<string,string>("{event}", "\"" + originalMessage + "\""), new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""), new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"") }); Logger.Write("RScript completed"); } catch (Exception ex) { internalDispatch("rscript-" + Name + " " + ex.ToString()); Logger.Write(ex.ToString()); } }, message); }