protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); commandLineArgs = new CommandLineArgs(e.Args); ViewManager.SetImplementation(new DefaultViewManager(t => kernel.Get(t))); Log.SetImplementation((DefaultLogger)LogManager.GetLogger("", typeof(DefaultLogger))); if (commandLineArgs.Contains("-debug", StringComparer.OrdinalIgnoreCase)) { Log.Level = "Debug"; } Log.Info($"Starting Astrarium {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion}"); var splashVM = new SplashScreenVM(); ViewManager.ShowWindow(splashVM); // in order to ensure the UI stays responsive, we need to // do the work on a different thread Task.Factory.StartNew(() => { ConfigureContainer(splashVM); Dispatcher.Invoke(() => { ViewManager.ShowWindow <MainVM>(); splashVM.Close(); }); }); Dispatcher.UnhandledException += (s, ea) => { string message = $"An unhandled exception occurred:\n\n{ea.Exception.Message}\nStack trace:\n\n{ea.Exception.StackTrace}"; Log.Error(message); ViewManager.ShowMessageBox("Error", message, MessageBoxButton.OK); ea.Handled = true; }; }
public void Render(Graphics g) { try { renderStopWatch.Restart(); mapContext.Graphics = g; g.Clear(mapContext.GetSkyColor()); g.PageUnit = GraphicsUnit.Display; g.SmoothingMode = Antialias ? SmoothingMode.HighQuality : SmoothingMode.HighSpeed; drawnObjects.Clear(); labels.Clear(); bool needDrawSelectedObject = true; if (LockedObject != null) { Center.Altitude = LockedObject.Horizontal.Altitude; Center.Azimuth = LockedObject.Horizontal.Azimuth; } for (int i = 0; i < renderers.Count(); i++) { try { renderers.ElementAt(i).Render(mapContext); } catch (Exception ex) { if (commandLineArgs.Contains("-debug", StringComparer.OrdinalIgnoreCase)) { g.DrawString($"Rendering error:\n{ex}", fontDiagnosticText, Brushes.Red, new RectangleF(10, 10, Width - 20, Height - 20)); } Log.Debug($"Rendering error: {ex}"); } if (needDrawSelectedObject) { needDrawSelectedObject = !DrawSelectedObject(g); } } // TODO: this should be refactored and moved to separate "Printing" plugin #if DEBUG // Map information if (mapContext.Schema == ColorSchema.White) { float headerHeight = (int)(mapContext.GetPointSize(0) + 35); float margin = 10; g.FillRectangle(Brushes.White, new RectangleF(0, 0, mapContext.Width, headerHeight)); g.DrawLine(Pens.Black, 0, headerHeight, mapContext.Width, headerHeight); var location = settings.Get <CrdsGeographical>("ObserverLocation"); var date = new Date(mapContext.JulianDay, location.UtcOffset); double offset = location.UtcOffset; string tz = offset != 0 ? $"UTC{(offset < 0 ? "-" : "+")}{TimeSpan.FromHours(offset):h\\:mm}" : "UTC"; string dateText = $"{Formatters.DateTime.Format(date)} {tz}"; var dateTextSize = g.MeasureString(dateText, fontMapInformationText); g.DrawString(dateText, fontMapInformationText, Brushes.Black, margin, (headerHeight - dateTextSize.Height) / 2); var mapTransformSb = new StringBuilder(); if (mapContext.IsInverted) { mapTransformSb.Append(" inverted"); } if (mapContext.IsMirrored) { mapTransformSb.Append(" mirrored"); } string mapTransformText = mapTransformSb.ToString().Trim(); if (string.IsNullOrEmpty(mapTransformText)) { mapTransformText = "Direct"; } var mapTransformTextSize = g.MeasureString(mapTransformText, fontMapInformationText); g.DrawString(mapTransformText, fontMapInformationText, Brushes.Black, mapContext.Width - margin - mapTransformTextSize.Width, (headerHeight - mapTransformTextSize.Height) / 2); g.DrawRectangle(Pens.Black, new Rectangle(0, 0, mapContext.Width, mapContext.Height)); var magLimit = mapContext.MagLimit; float r0 = mapContext.GetPointSize(0); float gap = r0 * 1.1f; float yLabel = headerHeight / 2 - r0 / 2 - fontMag.Height / 2 - 3; float scaleWidth = ((int)magLimit) * gap; int magStep = 1; if (magLimit >= 14) { magStep = 2; scaleWidth = scaleWidth / 2; } int c = 0; for (int m = 0; m <= magLimit + magStep; m += magStep) { float r = mapContext.GetPointSize(m); if ((int)r > 0) { string label = m.ToString(); float labelWidth = g.MeasureString(label, fontMag).Width; float xCircle = mapContext.Width / 2 - scaleWidth / 2 + c * gap - r / 2; float xLabel = mapContext.Width / 2 - scaleWidth / 2 + c * gap - labelWidth / 2; float yCircle = headerHeight / 2 - r / 2 + fontMag.Height / 2 + 3; g.DrawString(label, fontMag, Brushes.Black, xLabel, yLabel); g.FillEllipse(Brushes.Gray, xCircle, yCircle, r, r); } c++; } } #endif renderStopWatch.Stop(); rendersCount++; int fps = (int)(1000f / renderStopWatch.ElapsedMilliseconds); // Calculate mean time of rendering with Cumulative Moving Average formula meanRenderTime = (renderStopWatch.ElapsedMilliseconds + rendersCount * meanRenderTime) / (rendersCount + 1); // Diagnostic info if (commandLineArgs.Contains("-debug", StringComparer.OrdinalIgnoreCase)) { g.DrawString($"FOV: {Formatters.Angle.Format(ViewAngle)}\nMag limit: {Formatters.Magnitude.Format(MagLimit)}\nFPS: {fps}\nDaylight factor: {mapContext.DayLightFactor:F2}", fontDiagnosticText, Brushes.Red, new PointF(10, 10)); } } catch (Exception ex) { if (commandLineArgs.Contains("-debug", StringComparer.OrdinalIgnoreCase)) { g.DrawString($"Rendering error:\n{ex}", fontDiagnosticText, Brushes.Red, new RectangleF(10, 10, Width - 20, Height - 20)); } Log.Error($"Rendering error: {ex}"); } }