コード例 #1
0
        public void ValidateAndThrow()
        {
            var errors = new List <string>();

            if (Port <= 0 || Port > 65535)
            {
                errors.Add($"Port out of range({Port}).");
            }

            if (BufferSize <= 0)
            {
                errors.Add($"Buffer size is <= 0({BufferSize}).");
            }

            if (Analyzers == null || Analyzers.Count() == 0)
            {
                errors.Add("No analyzers are set. Add paths to some external analyzers.");
            }
            else
            {
                foreach (var path in Analyzers)
                {
                    if (!File.Exists(path))
                    {
                        errors.Add($"File not found \"{path}\"");
                    }
                }
            }

            if (errors.Count != 0)
            {
                var n = Environment.NewLine;
                throw new Exception($"Invalid command line options:{n}{string.Join(n, errors)}");
            }
        }
コード例 #2
0
 /// <summary>
 /// Stops the engine safely. Letting all current operations complete but will not allow the engine to start any now tasks.
 /// </summary>
 public void StopEngine()
 {
     Task.Run(() =>
     {
         AddMessage("Initiating engine shutdown.");
         ChangeState(State.ShuttingDown);
         AddMessage("Waiting for all analyzers to finish.");
         var timer = new Stopwatch();
         timer.Start();
         while (Analyzers.Any(a => a.Value.State != State.Stopped) && timer.ElapsedMilliseconds < 30000)
         {
             AddMessage($"{Analyzers.Count(a => a.Value.State != State.Stopped)} analyzers not stopped. Waited {timer.ElapsedMilliseconds} ms.");
             Task.Delay(1000).Wait();
         }
         AddMessage("Shutdown complete.");
         ChangeState(State.Stopped);
     });
 }