Exemplo n.º 1
0
        public HelloModule()
        {
            Get["/"] = o => View["index"];

            Get["/flow"] = o =>
            {
                dynamic viewBag = new DynamicDictionary();
                viewBag.PersistencePort = Program.PersistencePort;

                return(View["flow", viewBag]);
            };

            Post["/validate"] = o =>
            {
                var json = Context.Request.Body.AsString();
                GetNodes(json);

                return(HttpStatusCode.OK);
            };

            Get["/scripts"] = o =>
            {
                dynamic viewBag = new DynamicDictionary();
                viewBag.PersistencePort = Program.PersistencePort;
                viewBag.Table           = "scripts";

                return(View["scripts", viewBag]);
            };

            Get["/questionAnswer"] = o =>
            {
                var    question = HttpUtility.UrlDecode(Request.Query["q"]);
                var    guid     = Guid.NewGuid();
                string answer   = MethodHandler.GetValue <string>(guid, () => HelloHub.Question(guid.ToString(), question));
                return(answer);
            };

            Get["/test"] = o =>
            {
                HelloHub.ReturnResults(null, "[\"test\"]", "info_outline");
                return(HttpStatusCode.OK);
            };
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Title = "Frontend";
            Console.WriteLine("Waiting for RabbitMQ...");

            MapPorts();

            PreparePaths();
            AddChromePortable();
            AddRabbit();
            AddPersistence();

            Bus = RabbitHutch.CreateBus(GetBusConfiguration(RabbitIP, "guest", "guest", 50));

            Logger = new LoggerConfiguration()
                     .WriteTo.ColoredConsole()
                     .CreateLogger();

            var resultSubscription = Bus.SubscribeAsync <Result>("subscriptionId", x =>
            {
                var data = JsonConvert.SerializeObject(x.Node.Results);
                HelloHub.ReturnResults(x.Node.Data.Guid, data, "done");
                Logger.Information(data);
                return(Task.FromResult(true));
            });

            var errorSubscription = Bus.SubscribeAsync <ErrorResult>("subscriptionId", x =>
            {
                HelloHub.ReturnResults(x.Node.Data.Guid, x.Node.Error, "error");
                Logger.Error("{@Node}", x.Node);
                return(Task.FromResult(true));
            });

            Console.Clear();
            Console.WriteLine($"Local - http://{IP}:{Port}");

            if (ExternalIP != null)
            {
                Console.WriteLine($"Public - http://{ExternalIP}:{ExternalPort}");
            }

            Console.WriteLine();
            Console.WriteLine("o - offscreen, f - winforms, w - wpf, s - selenium, r - remote debugging, p - publish, 1 - flow, 2 - flow, esc - exit");

            var workers = new List <Process>();

            var url = $"http://+:{Port}";


            using (WebApp.Start <Startup>(url))
            {
                while (true)
                {
                    ConsoleKey key = Console.ReadKey().Key;

                    switch (key)
                    {
                    case ConsoleKey.O:
                        workers.Add(StartWorker("CefSharp.OffScreen"));
                        break;

                    case ConsoleKey.F:
                        workers.Add(StartWorker("CefSharp.WinForms"));
                        break;

                    case ConsoleKey.W:
                        workers.Add(StartWorker("CefSharp.WPF"));
                        break;

                    case ConsoleKey.S:
                        workers.Add(StartWorker("Selenium"));
                        break;

                    case ConsoleKey.R:
                        workers.Add(StartWorker("RemoteDebugging"));
                        break;

                    case ConsoleKey.P:
                        Publish();
                        break;

                    case ConsoleKey.D1:
                        Flow1();
                        break;

                    case ConsoleKey.D2:
                        Flow2();
                        break;

                    case ConsoleKey.Escape:

                        resultSubscription.Dispose();
                        errorSubscription.Dispose();

                        workers.ForEach(p =>
                        {
                            IgnoreExceptions(() => p.Kill());
                        });
                        //erl.ToList().ForEach(e => e.Kill());
                        Environment.Exit(0);
                        break;
                    }

                    Console.WriteLine();
                }
            }
        }