From 043cdc474a91e69286c85fefc13bc3f28cc0cea9 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Fri, 17 Jan 2020 18:10:32 -0800 Subject: [PATCH 01/12] Added a new project for Svg preview handler --- PowerToys.sln | 7 +++ .../Properties/AssemblyInfo.cs | 36 +++++++++++++ .../SvgPreviewHandler/SvgPreviewHandler.cs | 13 +++++ .../SvgPreviewHandler.csproj | 54 +++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs create mode 100644 src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs create mode 100644 src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj diff --git a/PowerToys.sln b/PowerToys.sln index 3fc62ac04940..1d8239722f2e 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -90,6 +90,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "previewpane", "previewpane" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "src\modules\previewpane\common\Common.csproj", "{AF2349B8-E5B6-4004-9502-687C1C7730B1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgPreviewHandler", "src\modules\previewpane\SvgPreviewHandler\SvgPreviewHandler.csproj", "{DA425894-6E13-404F-8DCB-78584EC0557A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -168,6 +170,10 @@ Global {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Debug|x64.Build.0 = Debug|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|x64.ActiveCfg = Release|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|x64.Build.0 = Release|x64 + {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.ActiveCfg = Debug|Any CPU + {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.Build.0 = Debug|Any CPU + {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.ActiveCfg = Release|Any CPU + {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -193,6 +199,7 @@ Global {0485F45C-EA7A-4BB5-804B-3E8D14699387} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3} {2F305555-C296-497E-AC20-5FA1B237996A} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {AF2349B8-E5B6-4004-9502-687C1C7730B1} = {2F305555-C296-497E-AC20-5FA1B237996A} + {DA425894-6E13-404F-8DCB-78584EC0557A} = {2F305555-C296-497E-AC20-5FA1B237996A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs b/src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..56e3142b7a3f --- /dev/null +++ b/src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SvgPreviewHandler")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SvgPreviewHandler")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("da425894-6e13-404f-8dcb-78584ec0557a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs new file mode 100644 index 000000000000..d0e1b40a61a6 --- /dev/null +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SvgPreviewHandler +{ + public class SvgPreviewHandler + { + + } +} diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj new file mode 100644 index 000000000000..cd5771548b6e --- /dev/null +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {DA425894-6E13-404F-8DCB-78584EC0557A} + Library + Properties + SvgPreviewHandler + SvgPreviewHandler + v4.8 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + {af2349b8-e5b6-4004-9502-687c1c7730b1} + Common + + + + \ No newline at end of file From 74e36c611d6659db66964dd24df8e8e3ae86a830 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Fri, 17 Jan 2020 20:12:36 -0800 Subject: [PATCH 02/12] Added initial implementation of Svg Preview Handler --- PowerToys.sln | 8 +-- .../Properties/AssemblyInfo.cs | 6 ++- .../SvgPreviewHandler/SvgPreviewControl.cs | 34 ++++++++++++ .../SvgPreviewHandler/SvgPreviewHandler.cs | 35 ++++++++++--- .../SvgPreviewHandler.csproj | 49 ++++++++++++++---- .../SvgPreviewHandler/SvgPreviewHandler.snk | Bin 0 -> 596 bytes .../SvgPreviewHandler/packages.config | 4 ++ .../examplehandler/TestCustomHandler.cs | 4 +- 8 files changed, 117 insertions(+), 23 deletions(-) create mode 100644 src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs create mode 100644 src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.snk create mode 100644 src/modules/previewpane/SvgPreviewHandler/packages.config diff --git a/PowerToys.sln b/PowerToys.sln index 1d8239722f2e..7323d8c4d2b2 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -170,10 +170,10 @@ Global {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Debug|x64.Build.0 = Debug|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|x64.ActiveCfg = Release|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|x64.Build.0 = Release|x64 - {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.ActiveCfg = Debug|Any CPU - {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.Build.0 = Debug|Any CPU - {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.ActiveCfg = Release|Any CPU - {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.Build.0 = Release|Any CPU + {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.ActiveCfg = Debug|x64 + {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.Build.0 = Debug|x64 + {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.ActiveCfg = Release|x64 + {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs b/src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs index 56e3142b7a3f..0bc87e35c8eb 100644 --- a/src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs +++ b/src/modules/previewpane/SvgPreviewHandler/Properties/AssemblyInfo.cs @@ -1,4 +1,8 @@ -using System.Reflection; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs new file mode 100644 index 000000000000..77db65d1afc5 --- /dev/null +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows.Forms; +using Common; + +namespace SvgPreviewHandler +{ + /// + /// Implementation of Control for Svg Preview Handler. + /// + public class SvgPreviewControl : FormHandlerControl + { + /// + /// Start the preview on the Control. + /// + /// Path to the file. + public override void DoPreview(T dataSource) + { + this.InvokeOnControlThread(() => + { + this.Enabled = false; + var filePath = dataSource as string; + WebBrowser browser = new WebBrowser(); + browser.Navigate(filePath); + browser.Dock = DockStyle.Fill; + browser.IsWebBrowserContextMenuEnabled = false; + this.Controls.Add(browser); + base.DoPreview(dataSource); + }); + } + } +} diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs index d0e1b40a61a6..5c0b5b58238c 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs @@ -1,13 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using Common; namespace SvgPreviewHandler { - public class SvgPreviewHandler + /// + /// Extends for Svg Preview Handler. + /// + [PreviewHandler("SvgPreviewHandler", ".svg", "{88235ab2-bfce-4be8-9ed0-0408cd8da792}")] + [ProgId("SvgPreviewHandler")] + [Guid("22a1a8e8-e929-4732-90ce-91eaff38b614")] + [ClassInterface(ClassInterfaceType.None)] + [ComVisible(true)] + public class SvgPreviewHandler : FileBasedPreviewHandler { + private SvgPreviewControl svgPreviewControl; + + /// + public override void DoPreview() + { + this.svgPreviewControl.DoPreview(this.FilePath); + } + /// + protected override IPreviewHandlerControl CreatePreviewHandlerControl() + { + this.svgPreviewControl = new SvgPreviewControl(); + return this.svgPreviewControl; + } } } diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj index cd5771548b6e..d306e4a09ecd 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj @@ -13,26 +13,41 @@ 512 true - + + true + + + SvgPreviewHandler.snk + + true - full - false - bin\Debug\ + bin\x64\Debug\ DEBUG;TRACE + bin\Debug\SvgPreviewHandler.xml + 2 + true + full + x64 + 7.3 prompt - 4 + MinimumRecommendedRules.ruleset - - pdbonly - true - bin\Release\ + + bin\x64\Release\ TRACE + bin\Release\SvgPreviewHandler.xml + true + true + pdbonly + x64 + 7.3 prompt - 4 + MinimumRecommendedRules.ruleset + @@ -41,6 +56,9 @@ + + Form + @@ -50,5 +68,16 @@ Common + + + StyleCop.json + + + + + + + + \ No newline at end of file diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.snk b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.snk new file mode 100644 index 0000000000000000000000000000000000000000..3375897afa1bf7275e1305344e104c29839d1a18 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50096Ay18EQ#E7hr6A49{)c7sb#Wc%soHgfg zLl?)ROEo}E*gqsDw3>`o6XUv6bKvqtPSL?8K0$N!WTZ4Q4^Mj`pIn8 zszE{v&ggSHEBv7I(A1)&q{HnT#o(BO7|M;3h`@e)EQBtsRgNB=_{(er|8ytqLeQTNv9S(AV| + + + \ No newline at end of file diff --git a/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs b/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs index daf06cde9e79..ae9461f056da 100644 --- a/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs +++ b/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs @@ -9,11 +9,11 @@ namespace Common /// /// This is a example custom handler to show how to extend the library. /// - [PreviewHandler("SvgPreviewHandler", ".svg", "{88235ab2-bfce-4be8-9ed0-0408cd8da792}")] + /*[PreviewHandler("SvgPreviewHandler", ".svg", "{88235ab2-bfce-4be8-9ed0-0408cd8da792}")] [ProgId("SvgPreviewHandler")] [Guid("22a1a8e8-e929-4732-90ce-91eaff38b614")] [ClassInterface(ClassInterfaceType.None)] - [ComVisible(true)] + [ComVisible(true)]*/ public class TestCustomHandler : FileBasedPreviewHandler { private CustomControlTest previewHandlerControl; From 2fbaf7ff99b91f0cdfb5bb0ab03ae2bdfe957751 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Sun, 19 Jan 2020 16:15:21 -0800 Subject: [PATCH 03/12] Fixed output path --- .../previewpane/SvgPreviewHandler/SvgPreviewControl.cs | 3 ++- .../previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj | 4 ++-- src/modules/previewpane/common/controls/FormHandlerControl.cs | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs index 77db65d1afc5..b1b487900f48 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -20,9 +20,10 @@ public override void DoPreview(T dataSource) { this.InvokeOnControlThread(() => { - this.Enabled = false; var filePath = dataSource as string; WebBrowser browser = new WebBrowser(); + + // browser.DocumentText = "Test"; browser.Navigate(filePath); browser.Dock = DockStyle.Fill; browser.IsWebBrowserContextMenuEnabled = false; diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj index d306e4a09ecd..1978d7069dae 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj @@ -21,7 +21,7 @@ true - bin\x64\Debug\ + bin\Debug\ DEBUG;TRACE bin\Debug\SvgPreviewHandler.xml 2 @@ -33,7 +33,7 @@ MinimumRecommendedRules.ruleset - bin\x64\Release\ + bin\Release\ TRACE bin\Release\SvgPreviewHandler.xml true diff --git a/src/modules/previewpane/common/controls/FormHandlerControl.cs b/src/modules/previewpane/common/controls/FormHandlerControl.cs index 642bc094fe8d..664d75fd317a 100644 --- a/src/modules/previewpane/common/controls/FormHandlerControl.cs +++ b/src/modules/previewpane/common/controls/FormHandlerControl.cs @@ -110,6 +110,7 @@ public virtual void Unload() } this.Controls.Clear(); + GC.Collect(); }); } From bb270091e9cc6ddf20119b7ccf129dfd6fdac19c Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Mon, 20 Jan 2020 15:14:25 -0800 Subject: [PATCH 04/12] Added Unit Test Project --- .../UnitTests/NuGetUpgradeLog.html | 163 ++++++++++++++++++ .../previewpane/UnitTests/UnitTests.csproj | 68 ++++++++ .../previewpane/UnitTests/packages.config | 5 + .../SvgPreviewHandler/NuGetUpgradeLog.html | 162 +++++++++++++++++ .../SvgPreviewHandler.csproj | 83 +++++++++ .../SvgPreviewHandler/packages.config | 0 PowerToys.sln | 7 + .../SvgPreviewHandler/SvgPreviewControl.cs | 2 - .../SvgPreviewHandler.csproj | 8 +- .../UnitTests/Properties/AssemblyInfo.cs | 20 +++ .../previewpane/UnitTests/UnitTest1.cs | 28 +++ .../previewpane/UnitTests/UnitTests.csproj | 72 ++++++++ .../common/controls/FormHandlerControl.cs | 1 - 13 files changed, 613 insertions(+), 6 deletions(-) create mode 100644 MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html create mode 100644 MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj create mode 100644 MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config create mode 100644 MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html create mode 100644 MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj rename {src => MigrationBackup/81db75f1}/modules/previewpane/SvgPreviewHandler/packages.config (100%) create mode 100644 src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs create mode 100644 src/modules/previewpane/UnitTests/UnitTest1.cs create mode 100644 src/modules/previewpane/UnitTests/UnitTests.csproj diff --git a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html new file mode 100644 index 000000000000..67eba3745614 --- /dev/null +++ b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html @@ -0,0 +1,163 @@ + + + + + NuGetMigrationLog +

+ NuGet Migration Report - modules\previewpane\UnitTests

Overview

Migration to PackageReference was completed successfully. Please build and run your solution to verify that all packages are available.
+ If you run into any problems, have feedback, questions, or concerns, please + file an issue on the NuGet GitHub repository.

Packages processed

Top-level dependencies:

Package IdVersion
MSTest.TestAdapter + v1.3.2
MSTest.TestFramework + v1.3.2

Transitive dependencies:

Package IdVersion
+ No transitive dependencies found. +

Package compatibility issues

Description
+ No issues were found. +
\ No newline at end of file diff --git a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj new file mode 100644 index 000000000000..865c8b8d4905 --- /dev/null +++ b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj @@ -0,0 +1,68 @@ + + + + + + Debug + AnyCPU + {179872C7-C59B-4AF0-9B64-A0434205CC5E} + Library + Properties + UnitTests + UnitTests + v4.8 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\..\..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config new file mode 100644 index 000000000000..ccebefbaa972 --- /dev/null +++ b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html new file mode 100644 index 000000000000..329faf96af5b --- /dev/null +++ b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html @@ -0,0 +1,162 @@ + + + + + NuGetMigrationLog +

+ NuGet Migration Report - modules\previewpane\SvgPreviewHandler

Overview

Migration to PackageReference was completed successfully. Please build and run your solution to verify that all packages are available.
+ If you run into any problems, have feedback, questions, or concerns, please + file an issue on the NuGet GitHub repository.

Packages processed

Top-level dependencies:

Package IdVersion
StyleCop.Analyzers + v1.1.118

Transitive dependencies:

Package IdVersion
+ No transitive dependencies found. +

Package compatibility issues

Description
+ No issues were found. +
\ No newline at end of file diff --git a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj new file mode 100644 index 000000000000..1978d7069dae --- /dev/null +++ b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {DA425894-6E13-404F-8DCB-78584EC0557A} + Library + Properties + SvgPreviewHandler + SvgPreviewHandler + v4.8 + 512 + true + + + true + + + SvgPreviewHandler.snk + + + true + bin\Debug\ + DEBUG;TRACE + bin\Debug\SvgPreviewHandler.xml + 2 + true + full + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + bin\Release\ + TRACE + bin\Release\SvgPreviewHandler.xml + true + true + pdbonly + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + + + Form + + + + + + + {af2349b8-e5b6-4004-9502-687c1c7730b1} + Common + + + + + StyleCop.json + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/previewpane/SvgPreviewHandler/packages.config b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/packages.config similarity index 100% rename from src/modules/previewpane/SvgPreviewHandler/packages.config rename to MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/packages.config diff --git a/PowerToys.sln b/PowerToys.sln index 7323d8c4d2b2..eb08c4b23d1b 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -92,6 +92,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "src\modules\previ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgPreviewHandler", "src\modules\previewpane\SvgPreviewHandler\SvgPreviewHandler.csproj", "{DA425894-6E13-404F-8DCB-78584EC0557A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\modules\previewpane\UnitTests\UnitTests.csproj", "{179872C7-C59B-4AF0-9B64-A0434205CC5E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -174,6 +176,10 @@ Global {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.Build.0 = Debug|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.ActiveCfg = Release|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.Build.0 = Release|x64 + {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Debug|x64.ActiveCfg = Debug|x64 + {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Debug|x64.Build.0 = Debug|x64 + {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Release|x64.ActiveCfg = Release|x64 + {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -200,6 +206,7 @@ Global {2F305555-C296-497E-AC20-5FA1B237996A} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {AF2349B8-E5B6-4004-9502-687C1C7730B1} = {2F305555-C296-497E-AC20-5FA1B237996A} {DA425894-6E13-404F-8DCB-78584EC0557A} = {2F305555-C296-497E-AC20-5FA1B237996A} + {179872C7-C59B-4AF0-9B64-A0434205CC5E} = {2F305555-C296-497E-AC20-5FA1B237996A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs index b1b487900f48..d264a72f1c68 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -22,8 +22,6 @@ public override void DoPreview(T dataSource) { var filePath = dataSource as string; WebBrowser browser = new WebBrowser(); - - // browser.DocumentText = "Test"; browser.Navigate(filePath); browser.Dock = DockStyle.Fill; browser.IsWebBrowserContextMenuEnabled = false; diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj index 1978d7069dae..6963dcf10029 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj @@ -72,12 +72,14 @@ StyleCop.json - - - + + 1.1.118 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + \ No newline at end of file diff --git a/src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs b/src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..2ba6a5d4ed12 --- /dev/null +++ b/src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnitTests")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("179872c7-c59b-4af0-9b64-a0434205cc5e")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/modules/previewpane/UnitTests/UnitTest1.cs b/src/modules/previewpane/UnitTests/UnitTest1.cs new file mode 100644 index 000000000000..5ac78f7ca583 --- /dev/null +++ b/src/modules/previewpane/UnitTests/UnitTest1.cs @@ -0,0 +1,28 @@ +using System; +using Common; +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace UnitTests +{ + [TestClass] + public class FormHandlerUnitTest + { + private class TestFormHandler : FormHandlerControl + { + } + + [TestMethod] + public void GetHandle_ShouldReturnFormHandle() + { + using (var testFormHandler = new TestFormHandler()) + { + // Act + var actualHandle = testFormHandler.GetHandle(); + + // Assert + actualHandle.Should().BeEq + } + } + } +} diff --git a/src/modules/previewpane/UnitTests/UnitTests.csproj b/src/modules/previewpane/UnitTests/UnitTests.csproj new file mode 100644 index 000000000000..6c6cf87eef06 --- /dev/null +++ b/src/modules/previewpane/UnitTests/UnitTests.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {179872C7-C59B-4AF0-9B64-A0434205CC5E} + Library + Properties + UnitTests + UnitTests + v4.8 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + bin\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + bin\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + 1.3.2 + + + 1.3.2 + + + + + {af2349b8-e5b6-4004-9502-687c1c7730b1} + Common + + + {da425894-6e13-404f-8dcb-78584ec0557a} + SvgPreviewHandler + + + + + \ No newline at end of file diff --git a/src/modules/previewpane/common/controls/FormHandlerControl.cs b/src/modules/previewpane/common/controls/FormHandlerControl.cs index 664d75fd317a..642bc094fe8d 100644 --- a/src/modules/previewpane/common/controls/FormHandlerControl.cs +++ b/src/modules/previewpane/common/controls/FormHandlerControl.cs @@ -110,7 +110,6 @@ public virtual void Unload() } this.Controls.Clear(); - GC.Collect(); }); } From f317266ce11d56dcfa4a3614895fb4c5704512ce Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Mon, 20 Jan 2020 19:57:04 -0800 Subject: [PATCH 05/12] Added StreamWrapper and Update Svg Control --- PowerToys.sln | 7 - .../SvgPreviewHandler/SvgPreviewControl.cs | 16 +- .../SvgPreviewHandler/SvgPreviewHandler.cs | 6 +- .../SvgPreviewHandler.csproj | 3 + .../UnitTests/Properties/AssemblyInfo.cs | 20 -- .../previewpane/UnitTests/UnitTest1.cs | 28 --- .../previewpane/UnitTests/UnitTests.csproj | 72 ------- .../common/Utilities/StreamWrapper.cs | 196 ++++++++++++++++++ src/modules/previewpane/common/common.csproj | 3 +- .../examplehandler/TestCustomHandler.cs | 4 +- ...andler.cs => StreamBasedPreviewHandler.cs} | 2 +- 11 files changed, 220 insertions(+), 137 deletions(-) delete mode 100644 src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs delete mode 100644 src/modules/previewpane/UnitTests/UnitTest1.cs delete mode 100644 src/modules/previewpane/UnitTests/UnitTests.csproj create mode 100644 src/modules/previewpane/common/Utilities/StreamWrapper.cs rename src/modules/previewpane/common/handlers/{SteamBasedPreviewHandler.cs => StreamBasedPreviewHandler.cs} (86%) diff --git a/PowerToys.sln b/PowerToys.sln index eb08c4b23d1b..7323d8c4d2b2 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -92,8 +92,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "src\modules\previ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgPreviewHandler", "src\modules\previewpane\SvgPreviewHandler\SvgPreviewHandler.csproj", "{DA425894-6E13-404F-8DCB-78584EC0557A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\modules\previewpane\UnitTests\UnitTests.csproj", "{179872C7-C59B-4AF0-9B64-A0434205CC5E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -176,10 +174,6 @@ Global {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.Build.0 = Debug|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.ActiveCfg = Release|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.Build.0 = Release|x64 - {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Debug|x64.ActiveCfg = Debug|x64 - {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Debug|x64.Build.0 = Debug|x64 - {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Release|x64.ActiveCfg = Release|x64 - {179872C7-C59B-4AF0-9B64-A0434205CC5E}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -206,7 +200,6 @@ Global {2F305555-C296-497E-AC20-5FA1B237996A} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {AF2349B8-E5B6-4004-9502-687C1C7730B1} = {2F305555-C296-497E-AC20-5FA1B237996A} {DA425894-6E13-404F-8DCB-78584EC0557A} = {2F305555-C296-497E-AC20-5FA1B237996A} - {179872C7-C59B-4AF0-9B64-A0434205CC5E} = {2F305555-C296-497E-AC20-5FA1B237996A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs index d264a72f1c68..2ebba73b35f8 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -2,8 +2,11 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.IO; +using System.Runtime.InteropServices.ComTypes; using System.Windows.Forms; using Common; +using Common.Utilities; namespace SvgPreviewHandler { @@ -15,14 +18,21 @@ public class SvgPreviewControl : FormHandlerControl /// /// Start the preview on the Control. /// - /// Path to the file. + /// Stream reference to access source file. public override void DoPreview(T dataSource) { this.InvokeOnControlThread(() => { - var filePath = dataSource as string; WebBrowser browser = new WebBrowser(); - browser.Navigate(filePath); + var stream = dataSource as IStream; + using (var streamWrapper = new StreamWrapper(stream)) + { + using (var reader = new StreamReader(streamWrapper)) + { + browser.DocumentText = reader.ReadToEnd(); + } + } + browser.Dock = DockStyle.Fill; browser.IsWebBrowserContextMenuEnabled = false; this.Controls.Add(browser); diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs index 5c0b5b58238c..8dbaaf1b09a4 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs @@ -9,21 +9,21 @@ namespace SvgPreviewHandler { /// - /// Extends for Svg Preview Handler. + /// Extends for Svg Preview Handler. /// [PreviewHandler("SvgPreviewHandler", ".svg", "{88235ab2-bfce-4be8-9ed0-0408cd8da792}")] [ProgId("SvgPreviewHandler")] [Guid("22a1a8e8-e929-4732-90ce-91eaff38b614")] [ClassInterface(ClassInterfaceType.None)] [ComVisible(true)] - public class SvgPreviewHandler : FileBasedPreviewHandler + public class SvgPreviewHandler : StreamBasedPreviewHandler { private SvgPreviewControl svgPreviewControl; /// public override void DoPreview() { - this.svgPreviewControl.DoPreview(this.FilePath); + this.svgPreviewControl.DoPreview(this.Stream); } /// diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj index 6963dcf10029..6fe55664b8e1 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj @@ -75,6 +75,9 @@ + + 5.10.0 + 1.1.118 runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs b/src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 2ba6a5d4ed12..000000000000 --- a/src/modules/previewpane/UnitTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("UnitTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("UnitTests")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("179872c7-c59b-4af0-9b64-a0434205cc5e")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/modules/previewpane/UnitTests/UnitTest1.cs b/src/modules/previewpane/UnitTests/UnitTest1.cs deleted file mode 100644 index 5ac78f7ca583..000000000000 --- a/src/modules/previewpane/UnitTests/UnitTest1.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Common; -using FluentAssertions; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace UnitTests -{ - [TestClass] - public class FormHandlerUnitTest - { - private class TestFormHandler : FormHandlerControl - { - } - - [TestMethod] - public void GetHandle_ShouldReturnFormHandle() - { - using (var testFormHandler = new TestFormHandler()) - { - // Act - var actualHandle = testFormHandler.GetHandle(); - - // Assert - actualHandle.Should().BeEq - } - } - } -} diff --git a/src/modules/previewpane/UnitTests/UnitTests.csproj b/src/modules/previewpane/UnitTests/UnitTests.csproj deleted file mode 100644 index 6c6cf87eef06..000000000000 --- a/src/modules/previewpane/UnitTests/UnitTests.csproj +++ /dev/null @@ -1,72 +0,0 @@ - - - - - Debug - AnyCPU - {179872C7-C59B-4AF0-9B64-A0434205CC5E} - Library - Properties - UnitTests - UnitTests - v4.8 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - true - bin\Debug\ - DEBUG;TRACE - full - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - - - bin\Release\ - TRACE - true - pdbonly - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - 1.3.2 - - - 1.3.2 - - - - - {af2349b8-e5b6-4004-9502-687c1c7730b1} - Common - - - {da425894-6e13-404f-8dcb-78584ec0557a} - SvgPreviewHandler - - - - - \ No newline at end of file diff --git a/src/modules/previewpane/common/Utilities/StreamWrapper.cs b/src/modules/previewpane/common/Utilities/StreamWrapper.cs new file mode 100644 index 000000000000..e6539c189594 --- /dev/null +++ b/src/modules/previewpane/common/Utilities/StreamWrapper.cs @@ -0,0 +1,196 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.IO; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace Common.Utilities +{ + /// + /// Wraps interface into Class. + /// + /// + /// Implements only read from the stream functionality. + /// + public class StreamWrapper : Stream + { + private IStream stream; + + /// + /// Initializes a new instance of the class. + /// + /// A pointer to an interface that represents the stream source. + public StreamWrapper(IStream stream) + { + this.stream = stream ?? throw new ArgumentNullException(nameof(stream)); + } + + /// + public override bool CanRead + { + get + { + return true; + } + } + + /// + public override bool CanSeek + { + get + { + return true; + } + } + + /// + public override bool CanWrite + { + get + { + return false; + } + } + + /// + public override long Length + { + get + { + this.CheckDisposed(); + System.Runtime.InteropServices.ComTypes.STATSTG stat; + this.stream.Stat(out stat, 1); // STATFLAG_NONAME + + return stat.cbSize; + } + } + + /// + public override long Position + { + get + { + return this.Seek(0, SeekOrigin.Current); + } + + set + { + this.Seek(value, SeekOrigin.Begin); + } + } + + /// + public override int Read(byte[] buffer, int offset, int count) + { + this.CheckDisposed(); + + if (offset < 0 || count < 0 || offset + count > buffer.Length) + { + throw new ArgumentOutOfRangeException(); + } + + byte[] localBuffer = buffer; + + if (offset > 0) + { + localBuffer = new byte[count]; + } + + IntPtr bytesReadPtr = Marshal.AllocCoTaskMem(sizeof(int)); + + try + { + this.stream.Read(localBuffer, count, bytesReadPtr); + int bytesRead = Marshal.ReadInt32(bytesReadPtr); + + if (offset > 0) + { + Array.Copy(localBuffer, 0, buffer, offset, bytesRead); + } + + return bytesRead; + } + finally + { + Marshal.FreeCoTaskMem(bytesReadPtr); + } + } + + /// + public override long Seek(long offset, SeekOrigin origin) + { + this.CheckDisposed(); + + int dwOrigin; + + switch (origin) + { + case SeekOrigin.Begin: + dwOrigin = 0; // STREAM_SEEK_SET + break; + + case SeekOrigin.Current: + dwOrigin = 1; // STREAM_SEEK_CUR + break; + + case SeekOrigin.End: + dwOrigin = 2; // STREAM_SEEK_END + break; + + default: + throw new ArgumentOutOfRangeException(); + } + + IntPtr posPtr = Marshal.AllocCoTaskMem(sizeof(long)); + + try + { + this.stream.Seek(offset, dwOrigin, posPtr); + return Marshal.ReadInt64(posPtr); + } + finally + { + Marshal.FreeCoTaskMem(posPtr); + } + } + + /// + public override void Flush() + { + throw new NotImplementedException(); + } + + /// + public override void SetLength(long value) + { + throw new NotImplementedException(); + } + + /// + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotImplementedException(); + } + + /// + protected override void Dispose(bool disposing) + { + if (this.stream != null) + { + Marshal.ReleaseComObject(this.stream); + this.stream = null; + } + } + + private void CheckDisposed() + { + if (this.stream == null) + { + throw new ObjectDisposedException(nameof(StreamWrapper)); + } + } + } +} diff --git a/src/modules/previewpane/common/common.csproj b/src/modules/previewpane/common/common.csproj index ccba0d677e41..a20985f126e3 100644 --- a/src/modules/previewpane/common/common.csproj +++ b/src/modules/previewpane/common/common.csproj @@ -77,8 +77,9 @@ - + + diff --git a/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs b/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs index ae9461f056da..daf06cde9e79 100644 --- a/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs +++ b/src/modules/previewpane/common/examplehandler/TestCustomHandler.cs @@ -9,11 +9,11 @@ namespace Common /// /// This is a example custom handler to show how to extend the library. /// - /*[PreviewHandler("SvgPreviewHandler", ".svg", "{88235ab2-bfce-4be8-9ed0-0408cd8da792}")] + [PreviewHandler("SvgPreviewHandler", ".svg", "{88235ab2-bfce-4be8-9ed0-0408cd8da792}")] [ProgId("SvgPreviewHandler")] [Guid("22a1a8e8-e929-4732-90ce-91eaff38b614")] [ClassInterface(ClassInterfaceType.None)] - [ComVisible(true)]*/ + [ComVisible(true)] public class TestCustomHandler : FileBasedPreviewHandler { private CustomControlTest previewHandlerControl; diff --git a/src/modules/previewpane/common/handlers/SteamBasedPreviewHandler.cs b/src/modules/previewpane/common/handlers/StreamBasedPreviewHandler.cs similarity index 86% rename from src/modules/previewpane/common/handlers/SteamBasedPreviewHandler.cs rename to src/modules/previewpane/common/handlers/StreamBasedPreviewHandler.cs index d329a5fadc16..8412dd7b92a5 100644 --- a/src/modules/previewpane/common/handlers/SteamBasedPreviewHandler.cs +++ b/src/modules/previewpane/common/handlers/StreamBasedPreviewHandler.cs @@ -10,7 +10,7 @@ namespace Common /// /// Extends the by implementing IInitializeWithStream. /// - public abstract class SteamBasedPreviewHandler : PreviewHandlerBase, IInitializeWithStream + public abstract class StreamBasedPreviewHandler : PreviewHandlerBase, IInitializeWithStream { /// /// Gets the stream object to access file. From 1180134c1358b7ce816ef8ae44a484351a810d6e Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Mon, 20 Jan 2020 20:00:19 -0800 Subject: [PATCH 06/12] Updated Svg Handler Guid --- src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs index 8dbaaf1b09a4..642cd13e83f0 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.cs @@ -13,7 +13,7 @@ namespace SvgPreviewHandler /// [PreviewHandler("SvgPreviewHandler", ".svg", "{88235ab2-bfce-4be8-9ed0-0408cd8da792}")] [ProgId("SvgPreviewHandler")] - [Guid("22a1a8e8-e929-4732-90ce-91eaff38b614")] + [Guid("ddee2b8a-6807-48a6-bb20-2338174ff779")] [ClassInterface(ClassInterfaceType.None)] [ComVisible(true)] public class SvgPreviewHandler : StreamBasedPreviewHandler From 8c2eb2f308e028b52c8d9f4958ee09296c317734 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Mon, 20 Jan 2020 20:09:07 -0800 Subject: [PATCH 07/12] Removed migration backup folder --- .../UnitTests/NuGetUpgradeLog.html | 163 ------------------ .../previewpane/UnitTests/UnitTests.csproj | 68 -------- .../previewpane/UnitTests/packages.config | 5 - .../SvgPreviewHandler/NuGetUpgradeLog.html | 162 ----------------- .../SvgPreviewHandler.csproj | 83 --------- .../SvgPreviewHandler/packages.config | 4 - 6 files changed, 485 deletions(-) delete mode 100644 MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html delete mode 100644 MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj delete mode 100644 MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config delete mode 100644 MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html delete mode 100644 MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj delete mode 100644 MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/packages.config diff --git a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html deleted file mode 100644 index 67eba3745614..000000000000 --- a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/NuGetUpgradeLog.html +++ /dev/null @@ -1,163 +0,0 @@ - - - - - NuGetMigrationLog -

- NuGet Migration Report - modules\previewpane\UnitTests

Overview

Migration to PackageReference was completed successfully. Please build and run your solution to verify that all packages are available.
- If you run into any problems, have feedback, questions, or concerns, please - file an issue on the NuGet GitHub repository.

Packages processed

Top-level dependencies:

Package IdVersion
MSTest.TestAdapter - v1.3.2
MSTest.TestFramework - v1.3.2

Transitive dependencies:

Package IdVersion
- No transitive dependencies found. -

Package compatibility issues

Description
- No issues were found. -
\ No newline at end of file diff --git a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj deleted file mode 100644 index 865c8b8d4905..000000000000 --- a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/UnitTests.csproj +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - Debug - AnyCPU - {179872C7-C59B-4AF0-9B64-A0434205CC5E} - Library - Properties - UnitTests - UnitTests - v4.8 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - - - ..\..\..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file diff --git a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config b/MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config deleted file mode 100644 index ccebefbaa972..000000000000 --- a/MigrationBackup/7aa13917/modules/previewpane/UnitTests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html deleted file mode 100644 index 329faf96af5b..000000000000 --- a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/NuGetUpgradeLog.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - NuGetMigrationLog -

- NuGet Migration Report - modules\previewpane\SvgPreviewHandler

Overview

Migration to PackageReference was completed successfully. Please build and run your solution to verify that all packages are available.
- If you run into any problems, have feedback, questions, or concerns, please - file an issue on the NuGet GitHub repository.

Packages processed

Top-level dependencies:

Package IdVersion
StyleCop.Analyzers - v1.1.118

Transitive dependencies:

Package IdVersion
- No transitive dependencies found. -

Package compatibility issues

Description
- No issues were found. -
\ No newline at end of file diff --git a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj deleted file mode 100644 index 1978d7069dae..000000000000 --- a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Debug - AnyCPU - {DA425894-6E13-404F-8DCB-78584EC0557A} - Library - Properties - SvgPreviewHandler - SvgPreviewHandler - v4.8 - 512 - true - - - true - - - SvgPreviewHandler.snk - - - true - bin\Debug\ - DEBUG;TRACE - bin\Debug\SvgPreviewHandler.xml - 2 - true - full - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - - - bin\Release\ - TRACE - bin\Release\SvgPreviewHandler.xml - true - true - pdbonly - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - - - Form - - - - - - - {af2349b8-e5b6-4004-9502-687c1c7730b1} - Common - - - - - StyleCop.json - - - - - - - - - - \ No newline at end of file diff --git a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/packages.config b/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/packages.config deleted file mode 100644 index e18dca45cdaf..000000000000 --- a/MigrationBackup/81db75f1/modules/previewpane/SvgPreviewHandler/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 0a905f8ff29cfd0fab3621803c6576bc7e3e08d4 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Mon, 20 Jan 2020 20:10:45 -0800 Subject: [PATCH 08/12] Removed Fluent Assertions NuGet --- .../previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj index 6fe55664b8e1..6963dcf10029 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewHandler.csproj @@ -75,9 +75,6 @@
- - 5.10.0 - 1.1.118 runtime; build; native; contentfiles; analyzers; buildtransitive From 6387f38f5d663829534f0d6adc2a6188eb51e7e4 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Tue, 21 Jan 2020 09:30:14 -0800 Subject: [PATCH 09/12] Added Comments for StreamWrapper --- .../SvgPreviewHandler/SvgPreviewControl.cs | 12 ++++++++++++ .../previewpane/common/Utilities/StreamWrapper.cs | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs index 2ebba73b35f8..6f0222821f5f 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -2,6 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.IO; using System.Runtime.InteropServices.ComTypes; using System.Windows.Forms; @@ -39,5 +40,16 @@ public override void DoPreview(T dataSource) base.DoPreview(dataSource); }); } + + /// + /// Override the base Unload method to free resources. + /// + public override void Unload() + { + base.Unload(); + + // Call the GC after disposing controls. This is to fix the issue Prevhost Process is not exiting after closing the File Explorer. + GC.Collect(); + } } } diff --git a/src/modules/previewpane/common/Utilities/StreamWrapper.cs b/src/modules/previewpane/common/Utilities/StreamWrapper.cs index e6539c189594..7f05492a4e96 100644 --- a/src/modules/previewpane/common/Utilities/StreamWrapper.cs +++ b/src/modules/previewpane/common/Utilities/StreamWrapper.cs @@ -62,6 +62,8 @@ public override long Length { this.CheckDisposed(); System.Runtime.InteropServices.ComTypes.STATSTG stat; + + // Stat called with STATFLAG_NONAME. The pwcsName is not required more details https://docs.microsoft.com/en-us/windows/win32/api/wtypes/ne-wtypes-statflag this.stream.Stat(out stat, 1); // STATFLAG_NONAME return stat.cbSize; @@ -123,9 +125,9 @@ public override int Read(byte[] buffer, int offset, int count) public override long Seek(long offset, SeekOrigin origin) { this.CheckDisposed(); - int dwOrigin; + // Maps the SeekOrigin with dworigin more details: https://docs.microsoft.com/en-us/windows/win32/api/objidl/ne-objidl-stream_seek switch (origin) { case SeekOrigin.Begin: From 53ce72d1a35e0d568b1e554ea7b95caaa94c6ff7 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Tue, 21 Jan 2020 12:41:57 -0800 Subject: [PATCH 10/12] Removed the manual GC collect --- .../SvgPreviewHandler/SvgPreviewControl.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs index 6f0222821f5f..f3659db640da 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -40,16 +40,5 @@ public override void DoPreview(T dataSource) base.DoPreview(dataSource); }); } - - /// - /// Override the base Unload method to free resources. - /// - public override void Unload() - { - base.Unload(); - - // Call the GC after disposing controls. This is to fix the issue Prevhost Process is not exiting after closing the File Explorer. - GC.Collect(); - } } } From e45677e3461f698a113a37f17872e0829dff5fe0 Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Wed, 22 Jan 2020 13:39:03 -0800 Subject: [PATCH 11/12] Added unit tests for Svg preview Handler --- PowerToys.sln | 7 ++ .../Properties/AssemblyInfo.cs | 20 ++++ .../SvgPreviewControlTests.cs | 95 +++++++++++++++++++ .../UnitTests-SvgPreviewHandler.csproj | 75 +++++++++++++++ .../common/Utilities/StreamWrapper.cs | 6 +- src/modules/previewpane/common/common.csproj | 8 +- .../previewpane/common/packages.config | 4 - 7 files changed, 207 insertions(+), 8 deletions(-) create mode 100644 src/modules/previewpane/UnitTests-SvgPreviewHandler/Properties/AssemblyInfo.cs create mode 100644 src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs create mode 100644 src/modules/previewpane/UnitTests-SvgPreviewHandler/UnitTests-SvgPreviewHandler.csproj delete mode 100644 src/modules/previewpane/common/packages.config diff --git a/PowerToys.sln b/PowerToys.sln index 7323d8c4d2b2..fcd1cd5abf97 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -92,6 +92,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "src\modules\previ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgPreviewHandler", "src\modules\previewpane\SvgPreviewHandler\SvgPreviewHandler.csproj", "{DA425894-6E13-404F-8DCB-78584EC0557A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests-SvgPreviewHandler", "src\modules\previewpane\UnitTests-SvgPreviewHandler\UnitTests-SvgPreviewHandler.csproj", "{060D75DA-2D1C-48E6-A4A1-6F0718B64661}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -174,6 +176,10 @@ Global {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.Build.0 = Debug|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.ActiveCfg = Release|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.Build.0 = Release|x64 + {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Debug|x64.ActiveCfg = Debug|x64 + {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Debug|x64.Build.0 = Debug|x64 + {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Release|x64.ActiveCfg = Release|x64 + {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -200,6 +206,7 @@ Global {2F305555-C296-497E-AC20-5FA1B237996A} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {AF2349B8-E5B6-4004-9502-687C1C7730B1} = {2F305555-C296-497E-AC20-5FA1B237996A} {DA425894-6E13-404F-8DCB-78584EC0557A} = {2F305555-C296-497E-AC20-5FA1B237996A} + {060D75DA-2D1C-48E6-A4A1-6F0718B64661} = {2F305555-C296-497E-AC20-5FA1B237996A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/previewpane/UnitTests-SvgPreviewHandler/Properties/AssemblyInfo.cs b/src/modules/previewpane/UnitTests-SvgPreviewHandler/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..48cfa2bbd020 --- /dev/null +++ b/src/modules/previewpane/UnitTests-SvgPreviewHandler/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("UnitTests-SvgPreviewHandler")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnitTests-SvgPreviewHandler")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("060d75da-2d1c-48e6-a4a1-6f0718b64661")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs b/src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs new file mode 100644 index 000000000000..b2b3935f0e1b --- /dev/null +++ b/src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs @@ -0,0 +1,95 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using System.Text; +using System.Windows.Forms; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SvgPreviewHandler; + +namespace UnitTests_SvgPreviewHandler +{ + [TestClass] + public class SvgPreviewControlTests + { + [TestMethod] + public void SvgPreviewControl_ShouldAddBrowserControl_WhenDoPreviewCalled() + { + // Arrange + var svgPreviewControl = new SvgPreviewControl(); + var mockStreamObject = GetMockStream(string.Empty); + + // Act + svgPreviewControl.DoPreview(mockStreamObject); + + // Assert + Assert.AreEqual(svgPreviewControl.Controls.Count, 1); + Assert.IsInstanceOfType(svgPreviewControl.Controls[0], typeof(WebBrowser)); + } + + [TestMethod] + public void SvgPreviewControl_ShouldSetDocumentText_WhenDoPreviewCalled() + { + // Arrange + var svgPreviewControl = new SvgPreviewControl(); + var mockStreamObject = GetMockStream(string.Empty); + + // Act + svgPreviewControl.DoPreview(mockStreamObject); + + // Assert + Assert.IsNotNull(((WebBrowser)svgPreviewControl.Controls[0]).DocumentText); + } + + [TestMethod] + public void SvgPreviewControl_ShouldDisableWebBrowserContextMenu_WhenDoPreviewCalled() + { + // Arrange + var svgPreviewControl = new SvgPreviewControl(); + var mockStreamObject = GetMockStream(string.Empty); + + // Act + svgPreviewControl.DoPreview(mockStreamObject); + + // Assert + Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).IsWebBrowserContextMenuEnabled, false); + } + + [TestMethod] + public void SvgPreviewControl_ShouldFillDockForWebBrowser_WhenDoPreviewCalled() + { + // Arrange + var svgPreviewControl = new SvgPreviewControl(); + var mockStreamObject = GetMockStream(string.Empty); + + // Act + svgPreviewControl.DoPreview(mockStreamObject); + + // Assert + Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).Dock, DockStyle.Fill); + } + + private IStream GetMockStream(string streamData) + { + var byteStreamData = Encoding.Unicode.GetBytes(streamData); + var mockStream = new Mock(); + bool doesRead = false; + mockStream.Setup(x => x.Read(It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((pv, cb, pcbRead) => + { + if (!doesRead) + { + Array.Copy(byteStreamData, 0, pv, 0, byteStreamData.Length); + Marshal.WriteInt32(pcbRead, byteStreamData.Length); + doesRead = true; + } + else + { + Marshal.WriteInt32(pcbRead, 0); + } + }); + + return mockStream.Object; + } + } +} diff --git a/src/modules/previewpane/UnitTests-SvgPreviewHandler/UnitTests-SvgPreviewHandler.csproj b/src/modules/previewpane/UnitTests-SvgPreviewHandler/UnitTests-SvgPreviewHandler.csproj new file mode 100644 index 000000000000..5c99aca7f709 --- /dev/null +++ b/src/modules/previewpane/UnitTests-SvgPreviewHandler/UnitTests-SvgPreviewHandler.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {060D75DA-2D1C-48E6-A4A1-6F0718B64661} + Library + Properties + UnitTests_SvgPreviewHandler + UnitTests-SvgPreviewHandler + v4.8 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x64 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + x64 + + + + + + + + + + + + + 4.13.1 + + + 1.3.2 + + + 1.3.2 + + + + + {AF2349B8-E5B6-4004-9502-687C1C7730B1} + Common + + + {DA425894-6E13-404F-8DCB-78584EC0557A} + SvgPreviewHandler + False + + + + + \ No newline at end of file diff --git a/src/modules/previewpane/common/Utilities/StreamWrapper.cs b/src/modules/previewpane/common/Utilities/StreamWrapper.cs index 7f05492a4e96..fdb0ebd416f5 100644 --- a/src/modules/previewpane/common/Utilities/StreamWrapper.cs +++ b/src/modules/previewpane/common/Utilities/StreamWrapper.cs @@ -182,7 +182,11 @@ protected override void Dispose(bool disposing) { if (this.stream != null) { - Marshal.ReleaseComObject(this.stream); + if (Marshal.IsComObject(this.stream)) + { + Marshal.ReleaseComObject(this.stream); + } + this.stream = null; } } diff --git a/src/modules/previewpane/common/common.csproj b/src/modules/previewpane/common/common.csproj index a20985f126e3..db5df2a52f64 100644 --- a/src/modules/previewpane/common/common.csproj +++ b/src/modules/previewpane/common/common.csproj @@ -85,12 +85,14 @@ StyleCop.json - - - + + 1.1.118 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + \ No newline at end of file diff --git a/src/modules/previewpane/common/packages.config b/src/modules/previewpane/common/packages.config deleted file mode 100644 index e18dca45cdaf..000000000000 --- a/src/modules/previewpane/common/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From 4bfa47ccb1d3b600565446db8c3edb58bc7a400c Mon Sep 17 00:00:00 2001 From: Udit Singh Date: Wed, 22 Jan 2020 15:06:50 -0800 Subject: [PATCH 12/12] Updated the xml doc for stream wrapper --- .../SvgPreviewHandler/SvgPreviewControl.cs | 27 +++++--- .../SvgPreviewControlTests.cs | 66 ++++++++++--------- .../common/Utilities/StreamWrapper.cs | 60 ++++++++++++++--- 3 files changed, 105 insertions(+), 48 deletions(-) diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs index f3659db640da..c41c48e7fcce 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -16,6 +16,8 @@ namespace SvgPreviewHandler /// public class SvgPreviewControl : FormHandlerControl { + private Stream dataSourceStream; + /// /// Start the preview on the Control. /// @@ -25,20 +27,29 @@ public override void DoPreview(T dataSource) this.InvokeOnControlThread(() => { WebBrowser browser = new WebBrowser(); - var stream = dataSource as IStream; - using (var streamWrapper = new StreamWrapper(stream)) - { - using (var reader = new StreamReader(streamWrapper)) - { - browser.DocumentText = reader.ReadToEnd(); - } - } + this.dataSourceStream = new StreamWrapper(dataSource as IStream); + browser.DocumentStream = this.dataSourceStream; browser.Dock = DockStyle.Fill; browser.IsWebBrowserContextMenuEnabled = false; + browser.ScriptErrorsSuppressed = true; + browser.ScrollBarsEnabled = true; this.Controls.Add(browser); base.DoPreview(dataSource); }); } + + /// + /// Free resources on the unload of Preview. + /// + public override void Unload() + { + base.Unload(); + if (this.dataSourceStream != null) + { + this.dataSourceStream.Dispose(); + this.dataSourceStream = null; + } + } } } diff --git a/src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs b/src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs index b2b3935f0e1b..c78e338fc070 100644 --- a/src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs +++ b/src/modules/previewpane/UnitTests-SvgPreviewHandler/SvgPreviewControlTests.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; @@ -17,10 +18,10 @@ public void SvgPreviewControl_ShouldAddBrowserControl_WhenDoPreviewCalled() { // Arrange var svgPreviewControl = new SvgPreviewControl(); - var mockStreamObject = GetMockStream(string.Empty); + var mockStream = new Mock(); // Act - svgPreviewControl.DoPreview(mockStreamObject); + svgPreviewControl.DoPreview(mockStream.Object); // Assert Assert.AreEqual(svgPreviewControl.Controls.Count, 1); @@ -28,17 +29,17 @@ public void SvgPreviewControl_ShouldAddBrowserControl_WhenDoPreviewCalled() } [TestMethod] - public void SvgPreviewControl_ShouldSetDocumentText_WhenDoPreviewCalled() + public void SvgPreviewControl_ShouldSetDocumentStream_WhenDoPreviewCalled() { // Arrange var svgPreviewControl = new SvgPreviewControl(); - var mockStreamObject = GetMockStream(string.Empty); + var mockStream = new Mock(); // Act - svgPreviewControl.DoPreview(mockStreamObject); - + svgPreviewControl.DoPreview(mockStream.Object); + // Assert - Assert.IsNotNull(((WebBrowser)svgPreviewControl.Controls[0]).DocumentText); + Assert.IsNotNull(((WebBrowser)svgPreviewControl.Controls[0]).DocumentStream); } [TestMethod] @@ -46,10 +47,10 @@ public void SvgPreviewControl_ShouldDisableWebBrowserContextMenu_WhenDoPreviewCa { // Arrange var svgPreviewControl = new SvgPreviewControl(); - var mockStreamObject = GetMockStream(string.Empty); + var mockStream = new Mock(); // Act - svgPreviewControl.DoPreview(mockStreamObject); + svgPreviewControl.DoPreview(mockStream.Object); // Assert Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).IsWebBrowserContextMenuEnabled, false); @@ -60,36 +61,41 @@ public void SvgPreviewControl_ShouldFillDockForWebBrowser_WhenDoPreviewCalled() { // Arrange var svgPreviewControl = new SvgPreviewControl(); - var mockStreamObject = GetMockStream(string.Empty); + var mockStream = new Mock(); // Act - svgPreviewControl.DoPreview(mockStreamObject); + svgPreviewControl.DoPreview(mockStream.Object); // Assert Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).Dock, DockStyle.Fill); } - private IStream GetMockStream(string streamData) + [TestMethod] + public void SvgPreviewControl_ShouldSetScriptErrorsSuppressedProperty_WhenDoPreviewCalled() { - var byteStreamData = Encoding.Unicode.GetBytes(streamData); + // Arrange + var svgPreviewControl = new SvgPreviewControl(); var mockStream = new Mock(); - bool doesRead = false; - mockStream.Setup(x => x.Read(It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((pv, cb, pcbRead) => - { - if (!doesRead) - { - Array.Copy(byteStreamData, 0, pv, 0, byteStreamData.Length); - Marshal.WriteInt32(pcbRead, byteStreamData.Length); - doesRead = true; - } - else - { - Marshal.WriteInt32(pcbRead, 0); - } - }); - - return mockStream.Object; + + // Act + svgPreviewControl.DoPreview(mockStream.Object); + + // Assert + Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).ScriptErrorsSuppressed, true); + } + + [TestMethod] + public void SvgPreviewControl_ShouldSetScrollBarsEnabledProperty_WhenDoPreviewCalled() + { + // Arrange + var svgPreviewControl = new SvgPreviewControl(); + var mockStream = new Mock(); + + // Act + svgPreviewControl.DoPreview(mockStream.Object); + + // Assert + Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).ScrollBarsEnabled, true); } } } diff --git a/src/modules/previewpane/common/Utilities/StreamWrapper.cs b/src/modules/previewpane/common/Utilities/StreamWrapper.cs index fdb0ebd416f5..8d31b9eff7d4 100644 --- a/src/modules/previewpane/common/Utilities/StreamWrapper.cs +++ b/src/modules/previewpane/common/Utilities/StreamWrapper.cs @@ -28,7 +28,9 @@ public StreamWrapper(IStream stream) this.stream = stream ?? throw new ArgumentNullException(nameof(stream)); } - /// + /// + /// Gets a value indicating whether the current stream supports reading. + /// public override bool CanRead { get @@ -37,7 +39,9 @@ public override bool CanRead } } - /// + /// + /// Gets a value indicating whether the current stream supports seeking. + /// public override bool CanSeek { get @@ -46,7 +50,9 @@ public override bool CanSeek } } - /// + /// + /// Gets a value indicating whether the current stream supports writing. + /// public override bool CanWrite { get @@ -55,7 +61,9 @@ public override bool CanWrite } } - /// + /// + /// Gets the length in bytes of the stream. + /// public override long Length { get @@ -70,7 +78,9 @@ public override long Length } } - /// + /// + /// Gets or Sets the position within the current. + /// public override long Position { get @@ -84,7 +94,13 @@ public override long Position } } - /// + /// + /// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. + /// + /// An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source. + /// The zero-based byte offset in buffer at which to begin storing the data read from the current stream. + /// The maximum number of bytes to be read from the current stream. + /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero if the end of the stream has been reached. public override int Read(byte[] buffer, int offset, int count) { this.CheckDisposed(); @@ -121,7 +137,12 @@ public override int Read(byte[] buffer, int offset, int count) } } - /// + /// + /// Sets the position within the current stream. + /// + /// A byte offset relative to the origin parameter. + /// A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position. + /// The new position within the current stream. public override long Seek(long offset, SeekOrigin origin) { this.CheckDisposed(); @@ -159,19 +180,38 @@ public override long Seek(long offset, SeekOrigin origin) } } - /// + /// + /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device. + /// + /// + /// Not implemented current implementation supports only read. + /// public override void Flush() { throw new NotImplementedException(); } - /// + /// + /// Sets the length of the current stream. + /// + /// The desired length of the current stream in bytes. + /// /// + /// Not implemented current implementation supports only read. + /// public override void SetLength(long value) { throw new NotImplementedException(); } - /// + /// + /// Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. + /// + /// An array of bytes. This method copies count bytes from buffer to the current stream. + /// The zero-based byte offset in buffer at which to begin copying bytes to the current stream. + /// The number of bytes to be written to the current stream. + /// + /// Not implemented current implementation supports only read. + /// public override void Write(byte[] buffer, int offset, int count) { throw new NotImplementedException();