/// <summary> /// Fires the <see cref="Graphic.Drawing"/> event. Should be called by an <see cref="IRenderer"/> /// for each object just before it is drawn/rendered, hence the reason it is public. /// </summary> /// <remarks> /// When this graphic is drawn, the <see cref="PresentationState"/> is deserialized. Any exceptions are caught /// and drawn to an exception text graphic placed at the <see cref="IApplicationGraphicsProvider">application-level</see>, /// if available. If no such in-grahic exception reporting mechanism is available, then the exception is thrown and /// the renderer will handle it according to its specific implementation. /// </remarks> public override void OnDrawing() { if (!_applied && base.ParentPresentationImage != null) { // set flag up here, in case deserializing the presentation state causes another draw _applied = true; if (_presentationState != null) { Exception exception = null; try { _presentationState.Deserialize(base.ParentPresentationImage); } catch (Exception ex) { Platform.Log(LogLevel.Warn, ex, "An error has occurred while deserializing the image presentation state."); exception = ex; } if (base.ParentPresentationImage is IApplicationGraphicsProvider) { ExceptionGraphic exGraphic = (ExceptionGraphic)((IApplicationGraphicsProvider)base.ParentPresentationImage).ApplicationGraphics.FirstOrDefault(IsType <ExceptionGraphic>); if (exGraphic == null) { ((IApplicationGraphicsProvider)base.ParentPresentationImage).ApplicationGraphics.Add(exGraphic = new ExceptionGraphic()); } exGraphic.Set(exception); } else if (exception != null) { // fallback mechanism when no other exception reporting mechanism is available throw exception; } } } base.OnDrawing(); }
/// <summary> /// Cloning constructor. /// </summary> private ExceptionGraphic(ExceptionGraphic source, ICloningContext context) : base() { context.CloneFields(source, this); }