Exemplo n.º 1
0
        private static async Task MainTask(string[] args)
        {
            Wax.WaxHub waxHub = new Wax.WaxHub();

            waxHub.SourceRoot         = SourceDirectoryFinder.CrayonSourceDirectory;
            waxHub.ErrorsAsExceptions = !IS_RELEASE;

            waxHub.RegisterService(new Router.RouterService());
            waxHub.RegisterService(new AssemblyResolver.AssemblyService());
            waxHub.RegisterService(new Runtime.RuntimeService());
            waxHub.RegisterService(new Builder.BuilderService());
            waxHub.RegisterService(new U3.U3Service());

            Wax.ToolchainCommand command = FlagParser.Parse(args);

            if (command.UseOutputPrefixes)
            {
                Wax.ConsoleWriter.EnablePrefixes();
            }

            foreach (string directory in GetExtensionDirectories())
            {
                waxHub.RegisterExtensionDirectory(directory);
            }

            waxHub.RegisterLibraryDirectory(GetLibraryDirectory());

            Dictionary <string, object> result = await waxHub.SendRequest("router", command);

            Wax.Error[] errors = Wax.Error.GetErrorsFromResult(result);

            if (command.UseJsonOutput)
            {
                string jsonErrors = "{\"errors\":[" +
                                    string.Join(',', errors.Select(err => err.ToJson())) +
                                    "]}";
                Wax.ConsoleWriter.Print(Wax.ConsoleMessageType.COMPILER_INFORMATION, jsonErrors);
            }
            else if (errors.Length > 0)
            {
                ErrorPrinter.ShowErrors(errors, waxHub.ErrorsAsExceptions);
            }
        }
Exemplo n.º 2
0
        public static void WaxSend(object eventLoopObj, object waxHubObj, bool isListener, string serviceId, string payloadJson, Value callback)
        {
            Wax.WaxHub waxHub    = (Wax.WaxHub)waxHubObj;
            EventLoop  eventLoop = (EventLoop)eventLoopObj;
            Dictionary <string, object> payload = new Dictionary <string, object>(new Wax.Util.JsonParser(payloadJson).ParseAsDictionary());

            if (waxHub.GetService(serviceId) == null)
            {
                eventLoop.ExecuteFunctionPointerNativeArgs(callback, new object[] { "The service '" + serviceId + "' does not exist.", null });
            }
            else if (isListener)
            {
                waxHub.RegisterListener(serviceId, payload, (data) =>
                {
                    object[] callbackArgs = new object[] { null, null };
                    callbackArgs[1]       = Wax.Util.JsonUtil.SerializeJson(data);
                    eventLoop.ExecuteFunctionPointerNativeArgs(callback, callbackArgs);
                    return(true);
                });
            }
            else
            {
                waxHub.SendRequest(serviceId, payload).ContinueWith(responseTask =>
                {
                    object[] callbackArgs = new object[] { null, null };
                    if (responseTask.IsFaulted)
                    {
                        callbackArgs[0] = responseTask.Exception.Message;
                    }
                    else
                    {
                        callbackArgs[1] = Wax.Util.JsonUtil.SerializeJson(responseTask.Result);
                    }
                    eventLoop.ExecuteFunctionPointerNativeArgs(callback, callbackArgs);
                });
            }
        }