Edge for C#

Edge for C#
refer: https://github.com/tjanczuk/edge/tree/master#scripting-nodejs-from-clr

Note: After building NodeJs code by VS no need deploy the js code, because the js code alreay building in dll.

Windows

Node.js 0.8.x or later (developed and tested with v0.8.22, and v0.10.0, both x32 and x64 architectures)
.NET 4.5
to use Python, you also need IronPython 2.7.3 or later
to use F#, read Dave Thomas blog post

How to: use external Node.js modules

You can use external Node.js modules, for example modules installed from NPM.
Note: Most Node.js modules are written in JavaScript and will execute in Edge as-is. However, some Node.js external modules are native binary modules, rebuilt by NPM on module installation to suit your local execution environment. Native binary modules will not run in Edge unless they are rebuilt to link against the NodeJS dll that Edge uses.
To install modules from NPM, you must first install Node.js on your machine and use the npm package manager that comes with the Node.js installation. NPM modules must be installed in the directory where your build system places the Edge.js NuGet package (most likely the same location as the rest of your application binaries), or any ancestor directory. Alternatively, you can install NPM modules globally on the machine using npm install -g:

coding: (NodeJs code should under building fold /node_modules )
       public ActionResult Index()
        {
            Task.Run((Action)test).Wait();
            return View();
           
        }
        public async void test()
        {
            var func = Edge.Func(@"                                return function(path){//                  var Fontmin = require('fontmin');//                 var fontmin = new Fontmin().src(path).dest('d:\\')//                    .use(Fontmin.ttf2woff({//                        clone: true,//                        deflate: true //                    }));//                    fontmin.run(function (err, files) {//                        if (err) {//                            throw err;//                        }////                        console.log(files[0]);//    //                    });                    var Woffmin = require('woffmin'); //                  Woffmin.aa(path);                    Woffmin.towoff(path);                };            ");
            try
            {
                await func("d:\\ariblk.ttf");
            }
            catch(Exception e){
                string aa = e.Message;
            }


var woffmin = require('./woffmin/woffmin');
var font = require('fontmin');
           
exports.towoff = function (path) {
    woffmin.towoff(path);
};

---------------------------------------------------------------------------------------------------------------------
var Fontmin = require('fontmin');

exports.towoff = function (path) {
    var fontmin = new Fontmin().src(path).dest('d:\\')
.use(Fontmin.ttf2woff({
clone: true,
deflate: true
}));
fontmin.run(function (err, files) {
  if (err) {
   throw err;
  }
});              
};

猜你喜欢

转载自owenxu.iteye.com/blog/2221591