src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs
/// <summary>
/// Start the preview on the Control.
/// </summary>
/// <param name="dataSource">Stream reference to access source file.</param>
Start the preview on the Control.
Start the preview on the Control .
public override void DoPreview<T>(T dataSource)
        {
            this.InvokeOnControlThread(() =>
            {
                try
                {
                    this.infoBarAdded = false;
                    string svgData = null;
                    using (var stream = new StreamWrapper(dataSource as IStream))
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            svgData = reader.ReadToEnd();
                        }
                    }
                    if (SvgPreviewHandlerHelper.CheckBlockedElements(svgData))
                    {
                        this.infoBarAdded = true;
                        this.AddTextBoxControl(Resource.BlockedElementInfoText);
                    }
                    this.AddBrowserControl(svgData);
                    this.Resize += this.FormResized;
                    base.DoPreview(dataSource);
                    PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewed());
                }
                catch (Exception ex)
                {
                    PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = ex.Message });
                    this.Controls.Clear();
                    this.infoBarAdded = true;
                    this.AddTextBoxControl(Resource.SvgNotPreviewedError);
                    base.DoPreview(dataSource);
                }
            });
        }
public override void DoPreview < T > ( T dataSource ) { this . InvokeOnControlThread ( ( ) => { try { this . infoBarAdded = false ; string svgData = null ; using ( var stream = new StreamWrapper ( dataSource as IStream ) ) { using ( var reader = new StreamReader ( stream ) ) { svgData = reader . ReadToEnd ( ) ; } } if ( SvgPreviewHandlerHelper . CheckBlockedElements ( svgData ) ) { this . infoBarAdded = true ; this . AddTextBoxControl ( Resource . BlockedElementInfoText ) ; } this . AddBrowserControl ( svgData ) ; this . Resize += this . FormResized ; base . DoPreview ( dataSource ) ; PowerToysTelemetry . Log . WriteEvent ( new SvgFilePreviewed ( ) ) ; } catch ( Exception ex ) { PowerToysTelemetry . Log . WriteEvent ( new SvgFilePreviewError { Message = ex . Message } ) ; this . Controls . Clear ( ) ; this . infoBarAdded = true ; this . AddTextBoxControl ( Resource . SvgNotPreviewedError ) ; base . DoPreview ( dataSource ) ; } } ) ; }
Start the preview on the Control.
Start the preview on the Control .
// Add a info bar on top of the Preview if any blocked element is present.
dataSource
T
Stream reference to access source file.
Stream reference to access source file .