zoukankan      html  css  js  c++  java
  • 示例

    要想在NodeJS中调用SS生成的DLL, 需要借助EdgeJS. 

    EdgeJS: http://tjanczuk.github.io/edge/

    如果你还不知道如何在SS中生成DLL, 请查看: Spider Studio 新版本 (x-mas) - 可以引入第三方程序集, 可以将脚本生成为DLL

    下面以曾经写过的XML/JSON互转的脚本为例 (C#中另辟蹊径解决JSON / XML互转的问题) 说明如何在NodeJS中应用SS DLL:

    1. 安装edgejs

    npm install edge

    2. 为www.utilities_online.info.XmlJsonConverter.dll编写一个javascript的代理脚本

    一共两个方法, Xml2Json & Json2Xml:

    var edge = require('edge');
    
    exports.xml2json = edge.func({
        source: function() {/*
    
            using System.Threading;
            using System.Threading.Tasks;
            using www.utilities_online.info;
    
            public class Startup
            {
                public async Task<object> Invoke(object input)
                {
                    object result = null;
                    Thread t = new Thread(new ParameterizedThreadStart((p) => { 
                        using(var proxy = new XmlJsonConverter())
                        {
                            proxy.Init();
                            result = proxy.Xml2Json(p.ToString());
                        }
                    } ));
                    t.SetApartmentState(ApartmentState.STA);
                    t.IsBackground = true;
                    t.Start(input);
                    while (t.ThreadState != ThreadState.Stopped)
                    {
                        Thread.Sleep(100);
                    }
                    return result;
                }
            }
        */},
        references: [ __dirname + '\www.utilities_online.info.XmlJsonConverter.dll' ]
    });
    
    exports.json2xml = edge.func({
        source: function() {/*
    
            using System.Threading;
            using System.Threading.Tasks;
            using www.utilities_online.info;
    
            public class Startup
            {
                public async Task<object> Invoke(object input)
                {
                    object result = null;
                    Thread t = new Thread(new ParameterizedThreadStart((p) => { 
                        using(var proxy = new XmlJsonConverter())
                        {
                            proxy.Init();
                            result = proxy.Json2Xml(p.ToString());
                        }
                    } ));
                    t.SetApartmentState(ApartmentState.STA);
                    t.IsBackground = true;
                    t.Start(input);
                    while (t.ThreadState != ThreadState.Stopped)
                    {
                        Thread.Sleep(100);
                    }
                    return result;
                }
            }
        */},
        references: [ __dirname + '\www.utilities_online.info.XmlJsonConverter.dll' ]
    });

    3. 编写服务脚本 www.utilities_online.info.XmlJsonConverter.js

    var http = require('http');
    var xmlJson = require('./www.utilities_online.info.XmlJsonConverter.proxy.js');
    
    var person = { person:{ name:'Mike', age:30 }};
    
    var proxy = http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'application/xml'});
      var xml = xmlJson.json2xml(JSON.stringify(person), true);
      console.log(xml);
      res.end(xml);
    }).listen(1338);

    4. 运行, 查看效果:

  • 相关阅读:
    使用火炬之光资源(转)
    (转)Visual Leak Detector (VLD)使用
    (转)ofusion 导出注意事项
    OgreMax 导出(转)
    (转)C++ 内存池 C++ Memory Pool 翻译版
    Maven教程初级篇01: 简介
    浅谈JSON 数据源格式
    面向连接的Socket Server的简单实现
    oracle杀死死锁进程
    重构——让程序员快乐的工作
  • 原文地址:https://www.cnblogs.com/iamzyf/p/3515928.html
Copyright © 2011-2022 走看看