Skip to content

Commit

Permalink
Move to DTE2
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Ejlskov Jensen committed Jul 12, 2021
1 parent fe066b0 commit 997b464
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 41 deletions.
21 changes: 11 additions & 10 deletions src/GUI/SqlCe35Toolbox/Commands/DatabaseMenuCommandsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Input;
using EnvDTE;
using EnvDTE;
using EnvDTE80;
using ErikEJ.SqlCeScripting;
using ErikEJ.SqlCeToolbox.Dialogs;
using ErikEJ.SqlCeToolbox.Helpers;
using ErikEJ.SqlCeToolbox.ToolWindows;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;

namespace ErikEJ.SqlCeToolbox.Commands
{
Expand Down Expand Up @@ -519,7 +520,7 @@ public void GenerateCeDgmlFiles(object sender, ExecutedRoutedEventArgs e)
if (databaseInfo == null) return;

if (package == null) return;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;

var fd = new SaveFileDialog
{
Expand Down Expand Up @@ -613,7 +614,7 @@ public void GenerateModelCodeInProject(object sender, ExecutedRoutedEventArgs e)
if (databaseInfo == null) return;

if (package == null) return;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;

var dteH = new EnvDteHelper();

Expand Down
17 changes: 9 additions & 8 deletions src/GUI/SqlCe35Toolbox/Commands/DatabasesMenuCommandsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System;
using System.IO;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Input;
using EnvDTE;
using EnvDTE;
using EnvDTE80;
using ErikEJ.SqlCeScripting;
using ErikEJ.SqlCeToolbox.Dialogs;
using ErikEJ.SqlCeToolbox.Helpers;
using ErikEJ.SqlCeToolbox.ToolWindows;
using Microsoft.VisualStudio.Data.Services;
using Microsoft.Win32;
using System;
using System.IO;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Input;

namespace ErikEJ.SqlCeToolbox.Commands
{
Expand Down Expand Up @@ -174,7 +175,7 @@ public void AddCe40Database(object sender, ExecutedRoutedEventArgs e)

private bool TryGetInitialPath(SqlCeToolboxPackage package, out string path)
{
var dte = package.GetServiceHelper(typeof(DTE)) as DTE;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;
var dteHelper = new EnvDteHelper();
try
{
Expand Down Expand Up @@ -252,7 +253,7 @@ public void SyncFxGenerateLocalDatabaseCacheCode(object sender, ExecutedRoutedEv
// http://www.mztools.com/articles/2007/MZ2007011.aspx
var menuItem = sender as MenuItem;
if (menuItem == null) return;
var dte = _package.GetServiceHelper(typeof(DTE)) as DTE;
var dte = _package.GetServiceHelper(typeof(DTE)) as DTE2;
var dteH = new EnvDteHelper();
var project = dteH.GetProject(dte);
if (project == null)
Expand Down
21 changes: 11 additions & 10 deletions src/GUI/SqlCe35Toolbox/Commands/SqlCeDatabaseMenuCommandsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using EnvDTE;
using EnvDTE80;
using ErikEJ.SqlCeScripting;
using ErikEJ.SqlCeToolbox.Dialogs;
using ErikEJ.SqlCeToolbox.Helpers;
using ErikEJ.SqlCeToolbox.ToolWindows;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using EnvDTE;
using ErikEJ.SqlCeScripting;
using ErikEJ.SqlCeToolbox.Dialogs;
using ErikEJ.SqlCeToolbox.Helpers;
using ErikEJ.SqlCeToolbox.ToolWindows;
using Microsoft.Win32;
using Microsoft.VisualStudio.Shell.Interop;

namespace ErikEJ.SqlCeToolbox.Commands
{
Expand Down Expand Up @@ -235,7 +236,7 @@ public void GenerateDataContextInProject(object sender, ExecutedRoutedEventArgs
var isDesktop = (bool)((MenuItem)sender).Tag;

if (package == null) return;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;
if (dte == null) return;
if (dte.Mode == vsIDEMode.vsIDEModeDebug)
{
Expand Down Expand Up @@ -741,7 +742,7 @@ public void SyncFxGenerateSyncCodeInProject(object sender, ExecutedRoutedEventAr
if (databaseInfo == null) return;

if (package == null) return;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;

var dteH = new EnvDteHelper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void GenerateServerDgmlFiles(object sender, ExecutedRoutedEventArgs e)
if (databaseInfo == null) return;

var originalValue = Properties.Settings.Default.KeepSchemaNames;
var dte = _package.GetServiceHelper(typeof(DTE)) as DTE;
var dte = _package.GetServiceHelper(typeof(DTE)) as DTE2;
try
{
var connectionString = databaseInfo.DatabaseInfo != null
Expand Down
4 changes: 3 additions & 1 deletion src/GUI/SqlCe35Toolbox/Helpers/DataConnectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System.Data.SQLite;
using Microsoft.VisualStudio.Shell;
using System.Linq;
using EnvDTE80;
using EnvDTE;

namespace ErikEJ.SqlCeToolbox.Helpers
{
Expand Down Expand Up @@ -342,7 +344,7 @@ internal void ValidateConnections(SqlCeToolboxPackage package)

internal void ScanConnections(SqlCeToolboxPackage package)
{
var dte = package.GetServiceHelper(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;
var helper = RepositoryHelper.CreateEngineHelper(DatabaseType.SQLCE40);
EnvDteHelper dteHelper = new EnvDteHelper();
var list = dteHelper.GetSqlCeFilesInActiveSolution(dte);
Expand Down
9 changes: 5 additions & 4 deletions src/GUI/SqlCe35Toolbox/Helpers/EnvDTEHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Windows.Forms;
using EnvDTE;
using EnvDTE80;
using ErikEJ.SqlCeToolbox.Properties;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
Expand All @@ -15,7 +16,7 @@ namespace ErikEJ.SqlCeToolbox.Helpers
{
internal class EnvDteHelper
{
public Project GetProject(DTE dte)
public Project GetProject(DTE2 dte)
{
foreach (SelectedItem item in dte.SelectedItems)
{
Expand Down Expand Up @@ -117,7 +118,7 @@ public bool ContainsEfSqlCeReference(Project project)
return false;
}

public HashSet<string> GetSqlCeFilesInActiveSolution(DTE dte)
public HashSet<string> GetSqlCeFilesInActiveSolution(DTE2 dte)
{
var list = new HashSet<string>();

Expand All @@ -132,7 +133,7 @@ public HashSet<string> GetSqlCeFilesInActiveSolution(DTE dte)
return list;
}

public string GetInitialFolder(DTE dte)
public string GetInitialFolder(DTE2 dte)
{
if (!dte.Solution.IsOpen)
return null;
Expand Down Expand Up @@ -227,7 +228,7 @@ public List<Guid> AllowedWpProjectKinds

public static void LaunchUrl(string url)
{
var dte = Package.GetGlobalService(typeof(DTE)) as DTE;
var dte = Package.GetGlobalService(typeof(DTE)) as DTE2;
if (dte != null)
{
dte.ItemOperations.Navigate(url);
Expand Down
7 changes: 4 additions & 3 deletions src/GUI/SqlCe35Toolbox/Helpers/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ErikEJ.SqlCeToolbox.Helpers
public static class Telemetry
{
private static TelemetryClient _telemetry;
private static DTEEvents _events;
//private static DTEEvents _events;

/// <summary>
/// Initializes the telemetry client.
Expand All @@ -30,8 +30,8 @@ public static void Initialize(DTE2 dte, string version, string vsVersion, string
_telemetry.InstrumentationKey = telemetryKey;
_telemetry.Context.Component.Version = version;

_events = dte.Events.DTEEvents;
_events.OnBeginShutdown += delegate { _telemetry.Flush(); };
//_events = dte.Events.DTEEvents;
//_events.OnBeginShutdown += delegate { _telemetry.Flush(); };

Enabled = true;
}
Expand Down Expand Up @@ -68,6 +68,7 @@ public static void TrackException(Exception ex)
var telex = new Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry(ex);
telex.HandledAt = Microsoft.ApplicationInsights.DataContracts.ExceptionHandledAt.UserCode;
_telemetry.TrackException(telex);
_telemetry.Flush();
}
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion src/GUI/SqlCe35Toolbox/SqlCeToolboxPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.Runtime.InteropServices;
using EnvDTE;
using EnvDTE80;
using ErikEJ.SqlCeToolbox.Helpers;
using ErikEJ.SqlCeToolbox.ToolWindows;
using Microsoft.VisualStudio;
Expand Down Expand Up @@ -180,7 +181,7 @@ public static Version VisualStudioVersion
{
get
{
var dte = GetGlobalService(typeof(DTE)) as DTE;
var dte = GetGlobalService(typeof(DTE)) as DTE2;
return dte != null
? new Version(int.Parse(dte.Version.Split('.')[0], CultureInfo.InvariantCulture), 0)
: new Version(0,0,0,0);
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/SqlCe35Toolbox/ToolWindows/ExplorerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void BuildDatabaseTree(bool fromUiThread)
databaseList.Add(info.Key, info.Value);
}
//Boot Telemetry
var dte = (DTE2)package.GetServiceHelper(typeof(DTE));
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;
Telemetry.Enabled = Properties.Settings.Default.ParticipateInTelemetry;
if (Telemetry.Enabled)
{
Expand Down
3 changes: 2 additions & 1 deletion src/GUI/SqlCe35Toolbox/ToolWindows/SqlEditorControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Input;
using System.Xml;
using EnvDTE;
using EnvDTE80;
using ErikEJ.SqlCeToolbox.Helpers;
using ExecutionPlanVisualizer;
using ICSharpCode.AvalonEdit.Highlighting;
Expand Down Expand Up @@ -141,7 +142,7 @@ private void SetEditorFont()
try
{
var package = _parentWindow.Package as SqlCeToolboxPackage;
var dte = package?.GetServiceHelper(typeof(DTE)) as DTE;
var dte = package?.GetServiceHelper(typeof(DTE)) as DTE2;
if (dte == null) return;
var properties = dte.Properties["FontsAndColors", "TextEditor"];
_fontFamiliy = GetFontFamily(properties, _fontSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Windows;
using ErikEJ.SqlCeScripting;
using System;
using EnvDTE80;
using EnvDTE;

namespace ErikEJ.SqlCeToolbox.ToolWindows
{
Expand Down Expand Up @@ -89,7 +91,7 @@ private void btnSample_Click(object sender, RoutedEventArgs e)
txtStatus.Text = string.Empty;
var package = _parentWindow.Package as SqlCeToolboxPackage;
if (package == null) return;
var dte = package.GetServiceHelper(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
var dte = package.GetServiceHelper(typeof(DTE)) as DTE2;

var fileName = System.IO.Path.GetTempFileName();
fileName = fileName + ".cs";
Expand Down

0 comments on commit 997b464

Please sign in to comment.