Provides a mechanism for things to happen periodically within a ManosApp. Timeouts are gauranteed to happen at some moment on or after the TimeSpan specified has ellapsed. Timeouts will never run before the specified TimeSpan has elapsed. Use the method Manos.IO.IOLoop "AddTimeout" method to register each Timeout.
コード例 #1
0
ファイル: AppHost.cs プロジェクト: restrepo/manos
 public static void RunTimeout(Timeout t)
 {
     t.Run (app);
 }
コード例 #2
0
ファイル: AppHost.cs プロジェクト: restrepo/manos
        public static Timeout AddTimeout(TimeSpan begin, TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback)
        {
            Timeout t = new Timeout (begin, timespan, repeat, data, callback);

            ioloop.AddTimeout (t);

            return t;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: waqashaneef/Node.cs
        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);
        }
コード例 #4
0
ファイル: AppHost.cs プロジェクト: hlesesne/manos
        public static Timeout AddTimeout(TimeSpan begin, TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback)
        {
            Timeout t = new Timeout (begin, timespan, repeat, data, callback);

            ITimerWatcher timer = null;
            timer = context.CreateTimerWatcher (begin, timespan, delegate {
                t.Run (app);
                if (!t.ShouldContinueToRepeat ()) {
                    t.Stop ();
                    timer.Dispose ();
                }
            });

            timer.Start ();

            return t;
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: RobinGitHub/Node.cs
		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;
		}