1
- using Microsoft . VisualStudio . Shell ;
1
+ using BlazoryVS . Enums ;
2
+ using BlazoryVS . Services ;
3
+ using Microsoft . VisualStudio . Shell ;
4
+ using Microsoft . VisualStudio . Shell . Interop ;
5
+ using Microsoft . VisualStudio . Shell . Settings ;
2
6
using System ;
3
7
using System . Runtime . InteropServices ;
4
8
using System . Threading ;
7
11
namespace BlazoryVS
8
12
{
9
13
/// <summary>
10
- /// This is the class that implements the package exposed by this assembly .
14
+ /// Represents the entry extension class .
11
15
/// </summary>
12
- /// <remarks>
13
- /// <para>
14
- /// The minimum requirement for a class to be considered a valid package for Visual Studio
15
- /// is to implement the IVsPackage interface and register itself with the shell.
16
- /// This package uses the helper classes defined inside the Managed Package Framework (MPF)
17
- /// to do it: it derives from the Package class that provides the implementation of the
18
- /// IVsPackage interface and uses the registration attributes defined in the framework to
19
- /// register itself and its components with the shell. These attributes tell the pkgdef creation
20
- /// utility what data to put into .pkgdef file.
21
- /// </para>
22
- /// <para>
23
- /// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file.
24
- /// </para>
25
- /// </remarks>
26
16
[ PackageRegistration ( UseManagedResourcesOnly = true , AllowsBackgroundLoading = true ) ]
27
17
[ Guid ( BlazoryVSPackage . PackageGuidString ) ]
18
+ [ ProvideAutoLoad ( UIContextGuids . NoSolution , PackageAutoLoadFlags . BackgroundLoad ) ]
19
+ [ ProvideAutoLoad ( UIContextGuids . SolutionExists , PackageAutoLoadFlags . BackgroundLoad ) ]
28
20
public sealed class BlazoryVSPackage : AsyncPackage
29
21
{
30
22
/// <summary>
31
- /// BlazoryVSPackage GUID string.
23
+ /// Gets the BlazoryVSPackage GUID string.
32
24
/// </summary>
33
25
public const string PackageGuidString = "a0775924-0734-4872-b19d-3a1a56325a58" ;
34
26
@@ -43,9 +35,44 @@ public sealed class BlazoryVSPackage : AsyncPackage
43
35
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
44
36
protected override async Task InitializeAsync ( CancellationToken cancellationToken , IProgress < ServiceProgressData > progress )
45
37
{
46
- // When initialized asynchronously, the current thread may be a background thread at this point.
47
- // Do any initialization that requires the UI thread after switching to the UI thread.
48
- await this . JoinableTaskFactory . SwitchToMainThreadAsync ( cancellationToken ) ;
38
+ try
39
+ {
40
+ // Gets the snippets from the specified JSON url.
41
+ var csharpSnippets = await SnippetService . GetSnippetsAsync ( BlazoryVSDefaults . CSharpSnippetsJsonUrl , BlazoryVSDefaults . CSharpSnippetLanguage , BlazoryVSDefaults . SnippetAuthor ) ;
42
+ var razorSnippets = await SnippetService . GetSnippetsAsync ( BlazoryVSDefaults . RazorSnippetsJsonUrl , BlazoryVSDefaults . RazorSnippetLanguage , BlazoryVSDefaults . SnippetAuthor ) ;
43
+
44
+ // Switch to main thread.
45
+ await JoinableTaskFactory . SwitchToMainThreadAsync ( cancellationToken ) ;
46
+
47
+ // Initialize settings manager.
48
+ var settingsManager = new ShellSettingsManager ( ServiceProvider . GlobalProvider ) ;
49
+
50
+ // Removes the placeholder snippets.
51
+ SnippetService . RemovePlaceholderSnippets ( settingsManager ) ;
52
+
53
+ // Gets the old snippets from the settings.
54
+ var oldCsharpSnippets = SettingsService . GetLastSnippets ( settingsManager , SnippetType . CSharp ) ;
55
+ var oldRazorSnippets = SettingsService . GetLastSnippets ( settingsManager , SnippetType . Razor ) ;
56
+
57
+ // Generates the snippet comparison reports.
58
+ var csharpSnippetsComparison = SnippetService . GenerateSnippetComparisonReport ( csharpSnippets , oldCsharpSnippets ) ;
59
+ var razorSnippetsComparison = SnippetService . GenerateSnippetComparisonReport ( razorSnippets , oldRazorSnippets ) ;
60
+
61
+ // Removes the snippets that are not in the JSON.
62
+ SnippetService . RemoveSnippets ( settingsManager , SnippetType . CSharp , csharpSnippetsComparison . SnippetsToBeDeleted ) ;
63
+ SnippetService . RemoveSnippets ( settingsManager , SnippetType . Razor , razorSnippetsComparison . SnippetsToBeDeleted ) ;
64
+
65
+ // Adds the snippets that are different than in the JSON.
66
+ SnippetService . ApplySnippets ( settingsManager , SnippetType . CSharp , csharpSnippetsComparison . SnippetsToBeEdited ) ;
67
+ SnippetService . ApplySnippets ( settingsManager , SnippetType . Razor , razorSnippetsComparison . SnippetsToBeEdited ) ;
68
+
69
+ // Update old snippets to the new ones.
70
+ SettingsService . SaveToLastSnippets ( settingsManager , SnippetType . CSharp , csharpSnippets ) ;
71
+ SettingsService . SaveToLastSnippets ( settingsManager , SnippetType . Razor , razorSnippets ) ;
72
+ }
73
+ catch
74
+ {
75
+ }
49
76
}
50
77
51
78
#endregion
0 commit comments