简体   繁体   English

使用Monaco Editor运行功能

[英]Run functionality with Monaco Editor

I wanted to use the Monaco Editor for my project and I want to run the server side languages like C# or node in my Monaco editor( https://github.com/Microsoft/monaco-editor/ ) which is a open source editor from Microsoft. 我想为项目使用Monaco编辑器,我想在Monaco编辑器( https://github.com/Microsoft/monaco-editor/ )中运行服务器端语言,例如C#或node,这是来自微软。

Here are few examples for that. 这里有一些例子。

https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-rendering-glyphs-in-the-margin https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-rendering-glyphs-in-the-margin

https://dotnet.microsoft.com/languages https://dotnet.microsoft.com/languages

If you see the the above examples you can see they are running c# with run button I wanted to implement same functionality. 如果您看到以上示例,则可以看到它们正在使用要实现相同功能的运行按钮运行c#。

I know that I need to install run time for particular language like C# and I have that in my local machine but still I am not able to run it. 我知道我需要为特定的语言(如C#)安装运行时,并且在本地计算机中已经安装了该运行时,但是仍然无法运行它。

Any help will be highly appreciated. 任何帮助将不胜感激。

What you see there is not a Monaco feature and is up to you to implement. 您看到的内容没有Monaco功能,您可以自行实现。 How you do that, will depend largely on the language you're trying to run. 如何执行,将在很大程度上取决于您尝试运行的语言。

The first example (and jsFiddle and CodePen and many others) simply displays an iframe to show the result. 第一个示例(以及jsFiddle和CodePen等)仅显示一个iframe来显示结果。 That iframe loads a file with a unique name that contains the HTML, CSS and JavaScript code entered in the editor. iframe会加载一个具有唯一名称的文件,其中包含在编辑器中输入的HTML,CSS和JavaScript代码。 You can confirm that this is what they're doing, using Chrome Dev Tools. 您可以使用Chrome开发工具来确认他们正在做什么。

If you're going to run a language like C#, know that you will need full control of your web server. 如果要运行C#之类的语言,请知道您将需要完全控制Web服务器。 The flow will be something like this: 流将是这样的:

  1. The user presses the Run button. 用户按下运行按钮。
  2. You call a web service (that you must develop), passing it the C# code and anything else needed to build a working project (like dependencies). 您调用一个Web服务(必须开发),将C#代码以及构建正常项目所需的其他任何东西(如依赖项)传递给它。
  3. The web service creates the project from those inputs, invokes the C# compiler, runs the resulting executable, and finally captures the output (both stdout and stderr ) into string variables. Web服务根据这些输入创建项目,调用C#编译器,运行生成的可执行文件,最后将输出( stdoutstderr )捕获到字符串变量中。 Those strings are returned by the web service. 这些字符串由Web服务返回。
  4. Back in the browser, you display the output from the web service. 返回浏览器,显示Web服务的输出。

This is very doable, but getting it to perform well when your volumes pick up will be a special problem. 这是非常可行的,但是当您的音量增加时使其性能良好将是一个特殊的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM