public BurstOptions(IStoplight stoplight)
 {
     _stoplight = stoplight;
     var segment = new BurstSegment { Send = 1 };
     _burstSegments = new[] { segment };
     BurstPattern = segment.ToString();
 }
Exemple #2
0
        public BurstOptions(IStoplight stoplight)
        {
            _stoplight = stoplight;
            var segment = new BurstSegment {
                Send = 1
            };

            _burstSegments = new[] { segment };
            BurstPattern   = segment.ToString();
        }
        /// <summary>
        /// Watch for stop and pause requests
        /// </summary>
        public static void Watch(IStoplight stoplight, bool canBeStopped, bool canBePaused, Action onStop, Action onPause, Action onResume, int checkEveryNMilliSeconds = 100)
        {
            //all this because Ctrl+C is broken in .net 4.0

            if (!Environment.UserInteractive)
            {
                throw new InvalidOperationException("expected UserInteractive mode");
            }

            ShowConsoleOptions(canBeStopped, canBePaused);
            bool isPaused = false;

            while (stoplight.IsGreen)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (isPaused)
                    {
                        if (key.Key == ConsoleKey.S)
                        {
                            onStop();
                        }
                        else if (key.Key == ConsoleKey.R)
                        {
                            onResume();
                            isPaused = false;
                            ShowConsoleOptions(canBeStopped, canBePaused);
                        }
                    }
                    else
                    {
                        if (key.Key == ConsoleKey.S)
                        {
                            onStop();
                        }
                        else if (key.Key == ConsoleKey.P)
                        {
                            isPaused = true;
                            onPause();
                            ShowConsoleOptions(canBeStopped, canBePaused, isPaused: true);
                        }
                    }
                }
                else
                {
                    Thread.Sleep(checkEveryNMilliSeconds);
                }
            }
        }
        /// <summary>
        /// Watch for stop and pause requests
        /// </summary>
        public static void Watch(IStoplight stoplight, bool canBeStopped, bool canBePaused, Action onStop, Action onPause, Action onResume, int checkEveryNMilliSeconds = 100)
        {
            //all this because Ctrl+C is broken in .net 4.0

            if (!Environment.UserInteractive)
            {
                throw new InvalidOperationException("expected UserInteractive mode");
            }

            ShowConsoleOptions(canBeStopped, canBePaused);
            bool isPaused = false;

            while (stoplight.IsGreen)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (isPaused)
                    {
                        if (key.Key == ConsoleKey.S)
                        {
                            onStop();
                        }
                        else if (key.Key == ConsoleKey.R)
                        {
                            onResume();
                            isPaused = false;
                            ShowConsoleOptions(canBeStopped, canBePaused);
                        }
                    }
                    else
                    {
                        if (key.Key == ConsoleKey.S)
                        {
                            onStop();
                        }
                        else if (key.Key == ConsoleKey.P)
                        {
                            isPaused = true;
                            onPause();
                            ShowConsoleOptions(canBeStopped, canBePaused, isPaused: true);
                        }
                    }
                }
                else
                {
                    Thread.Sleep(checkEveryNMilliSeconds);
                }
            }
        }