Skip to content

Commit a1b3341

Browse files
Adds support for custom plugin and query folder removes logging from the extension in favour of adding errors to the activity log adds to the raven wrapper error logging (in case of absence of connection)
1 parent 6cadad3 commit a1b3341

File tree

11 files changed

+102
-85
lines changed

11 files changed

+102
-85
lines changed

Src/BridgeVs.Build/BridgeVs.Build.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
<PlatformTarget>AnyCPU</PlatformTarget>
3232
<Optimize>true</Optimize>
3333
</PropertyGroup>
34-
<PropertyGroup>
35-
<SignAssembly>false</SignAssembly>
36-
</PropertyGroup>
37-
<PropertyGroup>
38-
<AssemblyOriginatorKeyFile>..\LinqBridgeVsExtension\Key.snk</AssemblyOriginatorKeyFile>
39-
</PropertyGroup>
4034
<ItemGroup>
4135
<Compile Include="Dependency\Crawler.cs" />
4236
<Compile Include="Dependency\ProjectDependency.cs" />

Src/BridgeVs.DynamicVisualizers/BridgeVs.DynamicVisualizers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Reference Include="Microsoft.VisualStudio.DebuggerVisualizers, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
4646
<SpecificVersion>False</SpecificVersion>
4747
<HintPath>..\..\Lib\VS2017\Microsoft.VisualStudio.DebuggerVisualizers.dll</HintPath>
48+
<Private>True</Private>
4849
</Reference>
4950
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5051
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>

Src/BridgeVs.DynamicVisualizers/DynamicDebuggerVisualizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ internal void DeployLinqScript(Message message)
9191
{
9292
Log.Write("Entered in DeployLinqScript");
9393

94-
string dstScriptPath = CommonFolderPaths.LinqPadQueryFolder;
94+
string dstScriptPath = CommonFolderPaths.DefaultLinqPadQueryFolder;
9595

9696
Log.Write("dstScriptPath: {0}", dstScriptPath);
9797
string targetFolder = Path.Combine(dstScriptPath, message.AssemblyName);
@@ -159,7 +159,7 @@ public Form ShowLINQPad(Stream inData, string vsVersion)
159159
DeployLinqScript(message);
160160
Log.Write("LinqQuery Successfully deployed");
161161

162-
string linqQueryfileName = Path.Combine(CommonFolderPaths.LinqPadQueryFolder, message.AssemblyName, message.FileName);
162+
string linqQueryfileName = Path.Combine(CommonFolderPaths.DefaultLinqPadQueryFolder, message.AssemblyName, message.FileName);
163163
string linqPadInstallationPath = CommonRegistryConfigurations.GetLINQPadInstallationPath(vsVersion);
164164
ProcessStartInfo startInfo = new ProcessStartInfo
165165
{

Src/BridgeVs.Locations/CommonFolderPaths.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System;
2727
using System.IO;
2828
using System.Reflection;
29+
using System.Linq;
2930

3031
namespace BridgeVs.Locations
3132
{
@@ -50,17 +51,18 @@ public static class CommonFolderPaths
5051
public static readonly string VisualStudio2013Path = Path.Combine(ProgramFilesFolderPath, @"Microsoft Visual Studio 12.0");
5152
public static readonly string VisualStudio2012Path = Path.Combine(ProgramFilesFolderPath, @"Microsoft Visual Studio 11.0");
5253

54+
public static readonly string ApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
55+
5356
public static readonly string GrappleFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Grapple");
5457

5558
public static string InstallFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
5659

5760
public static readonly string Documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
5861

59-
public static readonly string LinqPadQueryFolder = Path.Combine(Documents, "LINQPad Queries", "BridgeVs");
60-
public static readonly string LinqPadPluginFolder = Path.Combine(Documents, "LINQPad Plugins");
61-
6262
public static readonly string LinqPad4DestinationFolder = Path.Combine(ProgramFilesFolderPath, "LINQPad4");
6363
public static readonly string LinqPad5DestinationFolder = Path.Combine(ProgramFilesFolderPath, "LINQPad5");
64+
public static readonly string LinqPadCustomQueryFolderConfigurationFile = Path.Combine(ApplicationData, "LINQPad", "QueryLocations.txt");
65+
public static readonly string LinqPadCustomPluginFolderConfigurationFile = Path.Combine(ApplicationData, "LINQPad", "PluginLocations.txt");
6466

6567
public static readonly string CustomAfterTargetFileNamePath = Path.Combine(InstallFolder, CustomAfterTargets);
6668
public static readonly string CustomAfterTargetFileName = Path.GetFileName(CustomAfterTargets);
@@ -91,6 +93,37 @@ public static class CommonFolderPaths
9193
public static readonly string Vs2015DebuggerVisualizerDestinationFolder = Documents + @"\Visual Studio 2015\Visualizers\";
9294
public static readonly string Vs2017DebuggerVisualizerDestinationFolder = Documents + @"\Visual Studio 2017\Visualizers\";
9395

96+
public static string DefaultLinqPadQueryFolder
97+
{
98+
get
99+
{
100+
//I could cache the file here
101+
if (File.Exists(LinqPadCustomQueryFolderConfigurationFile))
102+
{
103+
string customQueryFolderPath = File.ReadLines(LinqPadCustomQueryFolderConfigurationFile).FirstOrDefault();
104+
if (!string.IsNullOrEmpty(customQueryFolderPath))
105+
return Path.Combine(customQueryFolderPath, "BridgeVs");
106+
}
107+
//
108+
return Path.Combine(Documents, "LINQPad Queries", "BridgeVs");
109+
}
110+
}
111+
112+
public static string DefaultLinqPadPluginFolder
113+
{
114+
get
115+
{
116+
if (File.Exists(LinqPadCustomPluginFolderConfigurationFile))
117+
{
118+
string customPluginFolderPath = File.ReadLines(LinqPadCustomPluginFolderConfigurationFile).FirstOrDefault();
119+
if (!string.IsNullOrEmpty(customPluginFolderPath))
120+
return customPluginFolderPath;
121+
}
122+
123+
return Path.Combine(Documents, "LINQPad Plugins");
124+
}
125+
}
126+
94127
static CommonFolderPaths()
95128
{
96129

Src/BridgeVs.Logging/Bridgevs.Logging.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<TargetFrameworkProfile />
1515
</PropertyGroup>
1616
<PropertyGroup>
17-
<SignAssembly>true</SignAssembly>
17+
<SignAssembly>false</SignAssembly>
1818
</PropertyGroup>
1919
<PropertyGroup>
2020
<AssemblyOriginatorKeyFile>Logging.snk</AssemblyOriginatorKeyFile>

Src/BridgeVs.Logging/RavenWrapper.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,22 @@ public sealed class RavenWrapper
4646
private RavenWrapper()
4747
{
4848
#if DEPLOY
49-
Func<Requester, Requester> removeUserId = new Func<Requester, Requester>(req => {
49+
Func<Requester, Requester> removeUserId = new Func<Requester, Requester>(req =>
50+
{
5051
//GDPR compliant, no server name or username stored
5152
req.Packet.ServerName = string.Empty;
5253
req.Packet.User.Username = string.Empty;
5354
return req;
5455
});
56+
57+
Action<Exception> onSendError = new Action<Exception>(ex =>
58+
{
59+
Log.Configure("entry", "AllProjects");
60+
Log.Write(ex, "Error sending the exception to Sentry.");
61+
});
5562
_ravenClient = new RavenClient(RavenClientId);
5663
_ravenClient.BeforeSend = removeUserId;
64+
_ravenClient.ErrorOnCapture = onSendError;
5765
#endif
5866
}
5967

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.VisualStudio.Shell.Interop;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace BridgeVs.VsPackage.Helper
10+
{
11+
public static class ActivityLogger
12+
{
13+
public static void VsLog(this IVsActivityLog log, string message)
14+
{
15+
if (log == null) return;
16+
17+
int hr = log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, message, "Error in LINQBridgeVs");
18+
}
19+
}
20+
}

Src/BridgeVs.VsPackage.Helper/BridgeVs.VsPackage.Helper.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
<Reference Include="WindowsBase" />
214214
</ItemGroup>
215215
<ItemGroup>
216+
<Compile Include="ActivityLogger.cs" />
216217
<Compile Include="BridgeCommand.cs" />
217218
<Compile Include="BridgeCommand.ExecuteParams.cs" />
218219
<Compile Include="Configuration\MsBuildVersionHelper.cs" />
@@ -269,10 +270,6 @@
269270
<Project>{bc10f93a-5da2-44f8-ae5e-5603cb46b548}</Project>
270271
<Name>BridgeVs.Locations</Name>
271272
</ProjectReference>
272-
<ProjectReference Include="..\BridgeVs.Logging\BridgeVs.Logging.csproj">
273-
<Project>{0b546762-c8c0-45c6-bc42-c5d91d510351}</Project>
274-
<Name>BridgeVs.Logging</Name>
275-
</ProjectReference>
276273
</ItemGroup>
277274
<ItemGroup>
278275
<Page Include="Installer\Welcome.xaml">

Src/BridgeVs.VsPackage.Helper/Configuration/PackageConfigurator.cs

Lines changed: 28 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
using System.Security.Principal;
3333
using System.Windows.Forms;
3434
using BridgeVs.Locations;
35-
using BridgeVs.Logging;
3635
using Microsoft.Win32;
3736
using OpenFileDialog = System.Windows.Forms.OpenFileDialog;
3837

@@ -131,12 +130,8 @@ private static void SetEnvironment(string vsVersion, string vsEdition)
131130
string msBuildDir = CreateMsBuildTargetDirectory(vsVersion, vsEdition);
132131
//Copy the CustomAfter and CustomBefore to the default MSbuild v4.0 location
133132
File.Copy(CommonFolderPaths.CustomAfterTargetFileNamePath, Path.Combine(msBuildDir, CommonFolderPaths.CustomAfterTargetFileName), true);
134-
Log.Write("CustomAfterTargetFileName Targets copied to {0} ", Path.Combine(msBuildDir, CommonFolderPaths.CustomAfterTargetFileName));
135133

136134
File.Copy(CommonFolderPaths.CustomBeforeTargetFileNamePath, Path.Combine(msBuildDir, CommonFolderPaths.CustomBeforeTargetFileName), true);
137-
Log.Write("CustomBeforeTargetFileName Targets copied to {0} ", Path.Combine(msBuildDir, CommonFolderPaths.CustomBeforeTargetFileName));
138-
139-
Log.Write("Setting IsEnvironmentConfigured to True");
140135
}
141136

142137
private static void SetInstallationFolder(string vsVersion)
@@ -147,8 +142,10 @@ private static void SetInstallationFolder(string vsVersion)
147142
if (key == null) return;
148143

149144
object value = key.GetValue(InstallFolderPathRegistryValue);
150-
if (value != null && value.Equals(CommonFolderPaths.InstallFolder)) return;
151-
Log.Write("Setting InstallFolderPath to {0}", CommonFolderPaths.InstallFolder);
145+
146+
if (value != null && value.Equals(CommonFolderPaths.InstallFolder))
147+
return;
148+
152149
key.SetValue(InstallFolderPathRegistryValue, CommonFolderPaths.InstallFolder);
153150
}
154151
}
@@ -176,7 +173,6 @@ private static string CreateMsBuildTargetDirectory(string vsVersion, string vsEd
176173
? string.Format(CommonFolderPaths.MsBuildPath2017, vsEdition)
177174
: CommonFolderPaths.MsBuildPath, msBuildVersion);
178175

179-
Log.Write("MsBuild Directory being created {0}", directoryToCreate);
180176
if (!Directory.Exists(directoryToCreate))
181177
{
182178
try
@@ -191,21 +187,13 @@ private static string CreateMsBuildTargetDirectory(string vsVersion, string vsEd
191187
Directory.CreateDirectory(directoryToCreate, sec);
192188
return directoryToCreate;
193189
}
194-
catch (UnauthorizedAccessException uae)
190+
catch (UnauthorizedAccessException)
195191
{
196-
Log.Write(uae);
197192
MessageBox.Show(
198193
"It wasn't possible to complete the configuration of BridgeVs. Please restart Visual Studio as Administrator");
199194
throw;
200195
}
201-
catch (Exception exception)
202-
{
203-
Log.Write(exception);
204-
Log.Write("Error creating MSBuild Path folder in {0}", CommonFolderPaths.MsBuildPath);
205-
throw;
206-
}
207196
}
208-
Log.Write("MSBuild Path {0} already exists", directoryToCreate);
209197
return directoryToCreate;
210198
}
211199

@@ -217,8 +205,6 @@ public static bool IsBridgeVsConfigured(string visualStudioVersion)
217205
{
218206
if (InstalledExtensionVersion(visualStudioVersion) != CurrentAssemblyVersion)
219207
{
220-
Log.Write("New LINQBridgeVs Extensions. Previous Version {0}. Current Version {1}",
221-
InstalledExtensionVersion(visualStudioVersion), CurrentAssemblyVersion);
222208
return false;
223209
}
224210

@@ -235,48 +221,35 @@ private static void SetBridgeVsAssemblyVersion(string vsVersion)
235221
}
236222
public static bool Install(string vsVersion, string vsEdition)
237223
{
238-
Log.Write("Configuring LINQBridgeVs Extension");
239-
240-
try
224+
if (!IsLINQPadInstalled(vsVersion)) //ask the user to insert a custom location
241225
{
242-
if (!IsLINQPadInstalled(vsVersion)) //ask the user to insert a custom location
243-
{
244-
return false;
245-
}
246-
247-
ObsoleteXmlConfiguration.RemoveOldTargets();
248-
249-
SetBridgeVsAssemblyVersion(vsVersion);
226+
return false;
227+
}
250228

251-
CreateLinqPadQueryFolder();
229+
ObsoleteXmlConfiguration.RemoveOldTargets();
252230

253-
CreateLinqPadPluginFolder();
231+
SetBridgeVsAssemblyVersion(vsVersion);
232+
233+
CreateLinqPadQueryFolder();
254234

255-
CreateVisualizerFolder(vsVersion);
235+
CreateLinqPadPluginFolder();
256236

257-
CreateGrappleFolder();
237+
CreateVisualizerFolder(vsVersion);
258238

259-
//Always check if installation folder has changed
260-
SetInstallationFolder(vsVersion);
239+
CreateGrappleFolder();
261240

262-
Log.Write("Setting the Environment");
241+
//Always check if installation folder has changed
242+
SetInstallationFolder(vsVersion);
263243

264-
SetEnvironment(vsVersion, vsEdition);
244+
SetEnvironment(vsVersion, vsEdition);
265245

266-
DeleteExistingVisualizers(vsVersion);
246+
DeleteExistingVisualizers(vsVersion);
267247

268-
DeployDependencies(vsVersion);
248+
DeployDependencies(vsVersion);
269249

270-
CommonRegistryConfigurations.SetErrorTracking(vsVersion, true);
250+
CommonRegistryConfigurations.SetErrorTracking(vsVersion, true);
271251

272-
return true;
273-
}
274-
catch (Exception e)
275-
{
276-
const string context = "Error Configuring LINQBridgeVs";
277-
Log.Write(e, context);
278-
return false;
279-
}
252+
return true;
280253
}
281254

282255
public static void DeployDependencies(string vsVersion)
@@ -286,7 +259,7 @@ public static void DeployDependencies(string vsVersion)
286259
throw new Exception("Dll location is null");
287260

288261
string debuggerVisualizerTargetFolder = DebuggerVisualizerTargetFolder(vsVersion);
289-
string linqPadPluginFolder = CommonFolderPaths.LinqPadPluginFolder;
262+
string linqPadPluginFolder = CommonFolderPaths.DefaultLinqPadPluginFolder;
290263
foreach (string dependency in Dependencies)
291264
{
292265
string sourceFile = Path.Combine(currentLocation, dependency);
@@ -338,22 +311,22 @@ private static string DebuggerVisualizerTargetFolder(string vsVersion)
338311

339312
private static void CreateLinqPadQueryFolder()
340313
{
341-
string dstScriptPath = CommonFolderPaths.LinqPadQueryFolder;
314+
//check first where LINQPad is installed
315+
string dstScriptPath = CommonFolderPaths.DefaultLinqPadQueryFolder;
342316

343-
if (Directory.Exists(dstScriptPath)) return;
317+
if (Directory.Exists(dstScriptPath))
318+
return;
344319

345320
DirectorySecurity sec = new DirectorySecurity();
346321
// Using this instead of the "Everyone" string means we work on non-English systems.
347322
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
348323
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
349324
Directory.CreateDirectory(dstScriptPath, sec);
350-
351-
Log.Write($"Directory Created: {dstScriptPath}");
352325
}
353326

354327
private static void CreateLinqPadPluginFolder()
355328
{
356-
string dstScriptPath = CommonFolderPaths.LinqPadPluginFolder;
329+
string dstScriptPath = CommonFolderPaths.DefaultLinqPadPluginFolder;
357330

358331
if (Directory.Exists(dstScriptPath)) return;
359332

@@ -362,8 +335,6 @@ private static void CreateLinqPadPluginFolder()
362335
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
363336
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
364337
Directory.CreateDirectory(dstScriptPath, sec);
365-
366-
Log.Write($"Directory Created: {dstScriptPath}");
367338
}
368339

369340
private static void CreateVisualizerFolder(string vsVersion)
@@ -376,21 +347,14 @@ private static void CreateVisualizerFolder(string vsVersion)
376347
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
377348
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
378349
Directory.CreateDirectory(debuggerVisualizerTargetFolder, sec);
379-
380-
Log.Write($"Directory Created: {debuggerVisualizerTargetFolder}");
381-
382350
}
383351

384352
private static void CreateGrappleFolder()
385353
{
386-
Log.Write("Creating folder for Delivery {0}", Path.GetFullPath(CommonFolderPaths.GrappleFolder));
387-
388354
if (Directory.Exists(CommonFolderPaths.GrappleFolder)) return;
389355

390356
//no need for security access
391357
Directory.CreateDirectory(CommonFolderPaths.GrappleFolder);
392-
393-
Log.Write("Folder Successfully Created");
394358
}
395359
#endregion
396360
}

0 commit comments

Comments
 (0)