
node.js edge

There was an engineer I used to work with who always said "That's just a software issue." No matter how complex the issue, no matter how daunting, they were confident it could be solved with software.
我曾经和一位工程师一起工作,他总是说“那只是软件问题”。 无论问题多么复杂,无论多么艰巨,他们都相信可以用软件解决。
.NET and C# and NuGet and the community have been making some amazing stuff in the last few years like ScriptCS, Chocolately, Boxstarter. Azure Websites now supports ASP.NET, sure, but also PHP, Python, Java (Tomcat or Jetty or your own container), and node.js. Getting these things to work together has been an interesting software issue. Apps can run side-by-side, but they can't really talk to each other in-process. (Mostly one just moves data between universes over JSON and HTTP when need-be.)
.NET和C#和的NuGet和社会各界一直在在过去的几年里像一些惊人的东西ScriptCS , Chocolately , Boxstarter 。 当然,Azure网站现在支持ASP.NET,还支持PHP,Python,Java(Tomcat或Jetty或您自己的容器)和node.js。 使这些东西协同工作一直是一个有趣的软件问题。 应用可以并排运行,但是它们实际上并不能在进程中相互通信。 (在需要时,大多数人只是通过JSON和HTTP在Universe之间移动数据。)
However, Tomasz Janczuk has been working on Edge.js (on Github) for a while now. I showed his work at jQuery Portland last year, but this week he's taking it to the next level. He is creating a wormhole between software universes.
但是, Tomasz Janczuk已经在Edge.js (在Github上)上工作了一段时间。 去年,我在jQuery Portland上展示了他的作品,但是本周他将作品提升到了一个新的水平。 他在软件世界之间制造了一个虫洞。
Edge.js现在允许您在Windows,Mac和Linux上在进程中运行node.js和.NET代码。 (Edge.js now lets you run node.js and .NET code in-process on Windows, Mac, and Linux.)
The name is great. An edge connects two nodes, and Edge.js is that edge.
这个名字很棒。 一条边连接两个节点,Edge.js是该边。

Here's a node app hello world node app calling .NET. Don't sweat that the .NET code is tunneled inside a comment, this is the Hello World proof of concept.
这是一个调用.NET的节点应用程序hello world节点应用程序。 不要为注释中的.NET代码带来麻烦,这就是Hello World概念的证明。
1 | var edge = require('edge');<br><br>var helloWorld = edge.func(function () {/*<br> async (input) => { <br> return ".NET Welcomes " + input.ToString(); <br> }<br>*/});<br><br>helloWorld('JavaScript', function (error, result) {<!-- --><br> if (error) throw error;<br> console.log(result);<br>}); |
Perhaps you have a bunch of CPU intensive work or algorithms in C#, but you've also got a node.js app that needs the result of that work. Edge can help with that.
也许您在C#中有大量CPU密集型工作或算法,但是您还具有需要该工作结果的node.js应用程序。 Edge可以帮上忙。
You can bring in a CS or CSX file into node like this:
您可以将CS或CSX文件导入节点,如下所示:
1 | var myCSharpCode = edge.func(require('path').join(__dirname, 'myCSharpCode.csx')); |
You can bring code from a .NET DLL into a node.js compiled as well.
您也可以将.NET DLL中的代码带入已编译的node.js中。
1 | var clrMethod = edge.func({<!-- --><br> assemblyFile: 'My.Edge.Samples.dll',<br> typeName: 'Samples.FooBar.MyType',<br> methodName: 'MyMethod'<br>}); |
It's not a hack, it's a clear way to marshal between CLR threads and the V8 (the node Javascript engine) thread. It's also interesting from a comp-sci perspective as the CLR can have many threads and V8 has the one.
这不是黑客,而是在CLR线程和V8(节点Javascript引擎)线程之间进行调度的一种清晰方法。 从comp-sci的角度来看,这也很有趣,因为CLR可以有很多线程,而V8则有一个。

Here's Tomasz's own words:
这是托马斯自己的话:
Edge.js provides an asynchronous, in-process mechanism for interoperability between Node.js and .NET.
Edge.js为Node.js和.NET之间的互操作性提供了一种异步的进程内机制。
You can use this mechanism to:
您可以使用此机制执行以下操作:
access MS SQL from Node.js using ADO.NET more...
使用ADO.NET从Node.js访问MS SQL更多...
use CLR multi-threading from Node.js for CPU intensive work more...
使用Node.js中的CLR多线程进行CPU密集型工作更多...
- write native extensions to Node.js in C# instead of C/C++ 用C#而不是C / C ++将原生扩展写入Node.js
- intergate existing .NET components into Node.js applications 将现有.NET组件与Node.js应用程序互连
Read more about the background and motivations of the project here.
在此处阅读有关该项目的背景和动机的更多信息。
Now, you might ask yourself, what problem does Edge.js solve? The answer is in the Edge.js FAQ.
现在,您可能会问自己,Edge.js解决了什么问题? 答案在Edge.js FAQ中。
Go explore what you can do. Edge goes much further than just C# and Node. It works on Windows, OSX, and Ubuntu but you should just "npm install edge" as there's a node package available.
去探索你能做什么。 Edge不仅限于C#和Node。 它可以在Windows , OSX和Ubuntu上运行,但是您应该“ npm install edge ”,因为有可用的节点包。
-
How to: integrate C# code into Node.js code
如何:将C#代码集成到Node.js代码中
-
How to: specify additional CLR assembly references in C# code
如何:在C#代码中指定其他CLR程序集引用
-
How to: marshal data between C# and Node.js
如何:在C#和Node.js之间封送数据
-
How to: call Node.js from C#
如何:从C#调用Node.js
-
How to: export C# function to Node.js
如何:将C#函数导出到Node.js
-
How to: script Python in a Node.js application
如何:在Node.js应用程序中编写Python脚本
-
How to: script PowerShell in a Node.js application
如何:在Node.js应用程序中编写PowerShell脚本
-
How to: script F# in a Node.js application
如何:在Node.js应用程序中编写F#脚本
-
How to: script T-SQL in a Node.js application
如何:在Node.js应用程序中编写T-SQL脚本
-
How to: support for other CLR languages
如何:支持其他CLR语言
-
How to leverage SQL Server with Node.js using Edge.js
如何使用Edge.js将SQL Server与Node.js结合使用
Have fun! You have a lot more power and flexibility than you think. It's just a software problem.
玩得开心! 您拥有的功能和灵活性比您想像的要强大得多。 这只是软件问题。
关于斯科特 (About Scott)
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
斯科特·汉塞尔曼(Scott Hanselman)是前教授,前金融首席架构师,现在是演讲者,顾问,父亲,糖尿病患者和Microsoft员工。 他是一位失败的单口相声漫画家,一个玉米种植者和一本书的作者。



About
关于
Newsletter
时事通讯
Hosting By
主持人

翻译自: https://www.hanselman.com/blog/its-just-a-software-issue-edgejs-brings-node-and-net-together-on-three-platforms
node.js edge