Example #1
0
 public void When_calculating_cpu_usage()
 {
     using (var cpu = new CpuMeter())
     {
         var logger = new Mock <ILogger>();
         cpu.Calculate(logger.Object);
         logger.Verify(x => x.Log(It.Is(
                                      (string log) => float.Parse(log.Split("CPU Usage Total: %".ToCharArray()).Last()) <= 100
                                      )));
     }
 }
        /// <summary>
        /// Initialize form controls.
        /// </summary>
        void MainForm_Load(object sender, EventArgs e)
        {
            bool ok = true;

            txtView.Font      = _settings.EditorFont;
            txtView.BackColor = _settings.BackColor;

            btnClear.Click += (object _, EventArgs __) => { txtView.Clear(); };
            btnWrap.Click  += (object _, EventArgs __) => { txtView.WordWrap = btnWrap.Checked; };

            InitLogging();

            ///// Init UI //////
            Location    = new Point(_settings.MainFormInfo.X, _settings.MainFormInfo.Y);
            Size        = new Size(_settings.MainFormInfo.Width, _settings.MainFormInfo.Height);
            WindowState = FormWindowState.Normal;

            _surface.Visible  = true;
            _surface.Location = new Point(Right, Top);
            _surface.TopMost  = _settings.LockUi;

            ///// CPU meter /////
            CpuMeter cpuMeter = new CpuMeter()
            {
                Width        = 50,
                Height       = toolStrip1.Height,
                ControlColor = Color.Red
            };

            // This took way too long to find out:
            //https://stackoverflow.com/questions/12823400/statusstrip-hosting-a-usercontrol-fails-to-call-usercontrols-onpaint-event
            cpuMeter.MinimumSize = cpuMeter.Size;
            toolStrip1.Items.Add(new ToolStripControlHost(cpuMeter));

            ok = InitMidi();

            PopulateRecentMenu();

            KeyPreview = true; // for routing kbd strokes properly

            _watcher.FileChangeEvent += Watcher_Changed;

            Text = $"NProcessing {MiscUtils.GetVersionString()} - No file loaded";

            // Catches runtime errors during drawing.
            _surface.RuntimeErrorEvent += (object esender, Surface.RuntimeErrorEventArgs eargs) => { ScriptRuntimeError(eargs); };

            // Fast timer.
            _mmtimer.TimerElapsedEvent += TimerElapsedEvent;
            SetUiTimerPeriod();
            _mmtimer.Start();

            // Slow timer.
            timer1.Interval = 500;
            timer1.Start();

            // Look for filename passed in.
            string[] args = Environment.GetCommandLineArgs();
            if (ok && args.Count() > 1)
            {
                OpenFile(args[1]);
            }
        }