Example #1
0
        public static void Start(ManosApp application)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            app = application;

            app.StartInternal();

            started = true;

            foreach (var ep in listenEndPoints)
            {
                var server = new HttpServer(HandleTransaction, IOLoop.CreateSocketStream());
                server.Listen(ep.Address.ToString(), ep.Port);

                servers.Add(server);
            }
            foreach (var ep in secureListenEndPoints.Keys)
            {
                var keypair = secureListenEndPoints [ep];
                var socket  = IOLoop.CreateSecureSocket(keypair.Item1, keypair.Item2);
                var server  = new HttpServer(HandleTransaction, socket);
                server.Listen(ep.Address.ToString(), ep.Port);

                servers.Add(server);
            }

            ioloop.Start();
        }
Example #2
0
        public static void Start(ManosApp application)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            app = application;

            app.StartInternal();

            started = true;

            foreach (var ep in listenEndPoints)
            {
                var server = new HttpServer(HandleTransaction, ioloop);
                server.Listen(ep.Address.ToString(), ep.Port);

                servers.Add(server);
            }

            syncBlockWatcher = new AsyncWatcher(IOLoop.EventLoop, HandleSynchronizationEvent);
            syncBlockWatcher.Start();

            ioloop.Start();
        }
Example #3
0
        public static void Start(ManosApp application)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            app = application;

            started = true;
            server  = new HttpServer(HandleTransaction, ioloop);

            server.Listen(IPAddress.ToString(), port);

            ioloop.Start();
        }
Example #4
0
        public static void Start(ManosApp application)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            app = application;

            app.StartInternal();

            started = true;
            server  = new HttpServer(HandleTransaction, ioloop);

            server.Listen(IPAddress.ToString(), port);

            syncBlockWatcher = new AsyncWatcher(IOLoop.EventLoop, HandleSynchronizationEvent);
            syncBlockWatcher.Start();

            ioloop.Start();
        }
Example #5
0
        public int Run(string app, IList <string> args)
        {
            IManosRun mr = Loader.LoadLibrary <IManosRun> (app, new List <string> ());

            IOLoop loop = IOLoop.Instance;

            string [] strargs = new string [args.Count];
            for (int i = 0; i < strargs.Length; i++)
            {
                strargs [i] = args [i];
            }

            if (mr == null)
            {
                Console.WriteLine("Binary {0} has no suitable entry point", app);
                return(-1);
            }

            int ret = mr.Main(strargs);

            loop.Start();

            return(ret);
        }
Example #6
0
        public static int Main(string[] args)
        {
            GlobalErrorHandler.Instance.SetGlobalErrorHandler((o, e) =>
            {
                Console.WriteLine(e.ExceptionObject);
                IOLoop.Instance.Stop();
                Environment.Exit(-1);
            });

            if (args.Length == 0)
            {
                Console.Error.WriteLine("node yourdll.dll [args[]]");
                return(-1);
            }

            string dll = args[0];

            if (!dll.EndsWith(".dll"))
            {
                dll += ".dll";
            }

            if (!File.Exists(dll))
            {
                Console.Error.WriteLine("dll '{0}' not found", dll);
                return(-1);
            }

            Assembly asy;

            try
            {
                asy = Assembly.LoadFile(args[0]);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("failed to load dll '{0}'. Exception was {1}", dll, ex.Message);
                return(-1);
            }

            Type[] types = asy.GetTypes();

            INodeProgram program = null;

            foreach (var type in types)
            {
                if (typeof(INodeProgram).IsAssignableFrom(type))
                {
                    try
                    {
                        program = (INodeProgram)asy.CreateInstance(type.FullName);

                        break;
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine("failed to type '{0}'. Exception was {1}", type.FullName, ex.Message);
                        return(-1);
                    }
                }
            }

            if (program == null)
            {
                Console.Error.WriteLine("Assembly '{0}' doesn't appear to have a INodeProgram type", asy.FullName);
                return(-1);
            }

            string[] progArgs = new string[args.Length - 1];

            for (int i = 1; i < args.Length; i++)
            {
                progArgs[i] = args[i];
            }

            IOLoop loop = IOLoop.Instance;

            int retCode = 0;

            Manos.Timeout t = new Manos.Timeout(TimeSpan.FromSeconds(1), RepeatBehavior.Single, null,
                                                (a, o) =>
            {
                Console.WriteLine("Starting program");

                try
                {
                    retCode = program.Main(progArgs);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("NodeProgram failed on startup {0}", ex);

                    loop.Stop();
                    retCode = -1;
                }

                if (retCode != 0)
                {
                    loop.Stop();
                }
            });

            loop.AddTimeout(t);

            loop.Start();

            return(retCode);
        }