Exemplo n.º 1
0
        public Handler BuildJavaScriptHandler <T>(HandlerInfo info)
        {
            var @namespace = info.Namespace ?? "module";
            var entrypoint = info.Entrypoint ?? "exports";
            var code       = info.Code ?? $"{@namespace}.{entrypoint} = {NoJavaScriptCodeHandler}";

            var md5        = MD5.Create();
            var inputBytes = Encoding.UTF8.GetBytes(code);
            var hash       = md5.ComputeHash(inputBytes);
            var sb         = new StringBuilder();

            foreach (var c in hash)
            {
                sb.Append(c.ToString("X2"));
            }
            var moduleName = $"{sb}.js";

            File.WriteAllText(moduleName, code);
            return((t, p) => _nodeServices.InvokeAsync <T>(moduleName, p).Result);
        }