Edge.js = Node.js + .NET
c# 은 광대하며 다양한 어플리케이션에서 개발하는데 사용될 수 있는 static type 프로그래밍 언어 중에 가장 파워풀하다고 말씀드리고 싶다. node.js 는 javascript 플렛폼을 server side 단에서 실행하는 것을 의미하며, V8 자바스크립트 엔진 상에서 고성능 확장 가능한 어플리케이션을 구현하는데 사용될 수 있다.
.NET 은 NuGet 에서 11,000 packages 보다 더 많이 제공하고 있으며, node.js 는 npm 에서 30,000 modules 보다 더 많이 제공합니다. 이는 우리가 한 공간에서 . NET과 Node.js 플랫폼 모두를 사용할 수 있다면 이는 매우 좋을 겁니다. edge.js 가 .net 환경에서 실행할 개발자분들에게 Node.js npm module 을 구현 가능하게끔 해줍니다. 이는 하나의 프로세스에서 node.js 를 실행하며, node.js 와 .net 간의 기능을 호출 가능합니다.
edge.js 는 node.js 에서 C# 비동기 림다를 호출 할 수도 있습니다. .net 와 node.js 는 다른 스레드 모델을 사용합니다. 그러나 edge 는 하나의 스레드 v8, 그리고 멀티 스레드 CLR 을 핸들링 합니다. 현재 Edge.js 는 C#, F#, Python, PowerShell 을 가지고 자바스크립트를 사용하도록 제공해 줍니다. edge.js 는 Tomasz Janczuk 에 의해 개발되었습니다. Edge.js 프레임워크는 https://github.com/tjanczuk/edge 에 있는 Github 에서 호스팅 해줍니다.
Edge.js 프레임워크을 운영하는데 있어서 아래의 환경이 요구됩니다.
- Windows
- Node.js 0.6.x or later
- .NET 4.5
- Edge NPM Module
Working with Edge.js
command prompt 에서 npm install edge 를 실행합니다.
Calling C# class from Node.js
아래 코드는 하나의 이미지 포멧에서 다른 이미지 포멧으로 이미지를 convert 하기 위해 c# 코드를 사용하여 간단한 node.js 프로그램을 구현 하였습니다.
1: var edge = require('edge');
2: var convertImage = edge.func(function() {/*
3: #r "System.Drawing.dll"
4:
5: using System;
6: using System.Threading.Tasks;
7: using System.Collections.Generic;
8: using System.Drawing;
9: using System.Drawing.Imaging;
10:
11: class Startup
12: {
13: static IDictionary<string, ImageFormat> formats
14: = new Dictionary<string, ImageFormat>
15: {
16: { "jpg", ImageFormat.Jpeg },
17: { "bmp", ImageFormat.Bmp },
18: { "gif", ImageFormat.Gif },
19: { "tiff", ImageFormat.Tiff },
20: { "png", ImageFormat.Png }
21: };
22:
23: public async Task<object> Invoke(
24: IDictionary<string,object> input)
25: {
26: await Task.Run(async () => {
27: using (Image image = Image.FromFile(
28: (string)input["source"]))
29: {
30: image.Save((string)input["destination"],
31: formats[(string)input["toType"]]);
32: }
33: });
34:
35: return null;
36: }
37: }
38: */});
39:
40: var params = {
41: source: '.\\shiju.png',
42: destination: '.\\shiju.jpg',
43: toType: 'jpg'
44: };
45:
46: convertImage(params, function (error) {
47: if (error) throw error;
48: console.log('The image shiju.png has been asynchronously converted to shiju.jpg');
49: });