Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
per lib/project query folder created
Option window validates the folder to linqpad
removes linqpad version from the registry
  • Loading branch information
codingadventures committed Apr 23, 2018
1 parent a59a49c commit 546d1de
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 88 deletions.
34 changes: 6 additions & 28 deletions Src/BridgeVs.Locations/CommonRegistryConfigurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,18 @@ public class CommonRegistryConfigurations
private const string LINQPadVersionPathRegistryValue = "LINQPadVersion";

// ReSharper disable once InconsistentNaming
public static string LINQPadInstallationPath
public static string GetLINQPadInstallationPath(string vsVersion)
{
get
using (RegistryKey key = Registry.CurrentUser.OpenSubKey($@"Software\LINQBridgeVs\{vsVersion}"))
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
{
return key?.GetValue(LINQPadInstallationPathRegistryValue) as string;
}
}
set
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
{
key?.SetValue(LINQPadInstallationPathRegistryValue, value);
}
return key?.GetValue(LINQPadInstallationPathRegistryValue) as string;
}
}

// ReSharper disable once InconsistentNaming
public static string LINQPadVersion
public static void SetLINQPadInstallationPath(string vsVersion, string installationPath)
{
get
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
{
return key?.GetValue(LINQPadVersionPathRegistryValue) as string;
}
}
set
using (RegistryKey key = Registry.CurrentUser.CreateSubKey($@"Software\LINQBridgeVs\{vsVersion}"))
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
{
key?.SetValue(LINQPadVersionPathRegistryValue, value);
}
key?.SetValue(LINQPadInstallationPathRegistryValue, installationPath);
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions Src/Build/Tasks/MapperBuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,6 @@ private void MergeVisualizerWithDependencies(string visualizerInstallationPath,
{
throw new ArgumentException("Installation Path and temporary path cannot be the same", nameof(temporaryVisualizerFilePath));
}

// ILMerge merge = new ILMerge()
// {
// OutputFile = customVisualizerTargetInstallationPath,
//#if DEPLOY
// DebugInfo = false,
//#endif
// TargetKind = ILMerge.Kind.SameAsPrimaryAssembly,
// Closed = false
// };

//the order of input assemblies does matter. the first assembly is used as a template (for assembly attributes also)
//for merging all the rest into it
//merge.SetInputAssemblies(new[] {
// temporaryVisualizerFilePath,
// typeof(DynamicCore.DynamicDebuggerVisualizer).Assembly.Location,
// typeof(Newtonsoft.Json.DateFormatHandling).Assembly.Location,
// typeof(Grapple.Truck).Assembly.Location,
// typeof(Locations.CommonFolderPaths).Assembly.Location,
// typeof(Log).Assembly.Location,
// typeof(System.IO.Abstractions.DirectoryBase).Assembly.Location
// });

//string searchDirectory = VisualStudioOptions.GetCommonReferenceAssembliesPath(VisualStudioVer).FirstOrDefault(Directory.Exists);

//merge.SetSearchDirectories(new[] { Path.GetDirectoryName(GetType().Assembly.Location), searchDirectory });

//merge.Merge();
}
/// <summary>
/// Maps the dot net framework types. If the file already exists for a given vs version it won't be
Expand Down
21 changes: 13 additions & 8 deletions Src/DynamicCore/DynamicDebuggerVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ internal void DeployLinqScript(Message message)
string dstScriptPath = CommonFolderPaths.LinqPadQueryFolder;

Log.Write("dstScriptPath: {0}", dstScriptPath);
string targetFolder = Path.Combine(dstScriptPath, message.AssemblyName);

string dst = Path.Combine(dstScriptPath, string.Format(message.FileName, message.TypeFullName));
Log.Write("dst: {0}", dst);
if (!Directory.Exists(targetFolder))
Directory.CreateDirectory(targetFolder);

string linqPadScriptPath = Path.Combine(targetFolder, message.FileName);
Log.Write("linqPadScriptPath: {0}", linqPadScriptPath);

List<string> refAssemblies = new List<string>();
refAssemblies.AddRange(message.ReferencedAssemblies);
Expand All @@ -106,15 +110,14 @@ internal void DeployLinqScript(Message message)

Log.Write("LinqQuery file Transformed");

using (Stream memoryStream = FileSystem.File.Open(dst, FileMode.Create))
using (Stream memoryStream = FileSystem.File.Open(linqPadScriptPath, FileMode.Create))
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
{
streamWriter.Write(linqQueryText);
streamWriter.Flush();
memoryStream.Flush();
}
Log.Write("LinqQuery file Generated");

}
catch (Exception e)
{
Expand Down Expand Up @@ -152,13 +155,13 @@ public Form ShowLINQPad(Stream inData, string vsVersion)
DeployLinqScript(message);
Log.Write("LinqQuery Successfully deployed");

string linqQueryfileName = Path.Combine(CommonFolderPaths.LinqPadQueryFolder, message.FileName);

string linqQueryfileName = Path.Combine(CommonFolderPaths.LinqPadQueryFolder, message.AssemblyName, message.FileName);
string linqPadInstallationPath = CommonRegistryConfigurations.GetLINQPadInstallationPath(vsVersion);
ProcessStartInfo startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Normal,
FileName = Resources.LINQPadExe,
WorkingDirectory = CommonRegistryConfigurations.LINQPadInstallationPath,
WorkingDirectory = linqPadInstallationPath,
Arguments = linqQueryfileName + " " + Resources.LINQPadCommands
};

Expand All @@ -170,8 +173,10 @@ public Form ShowLINQPad(Stream inData, string vsVersion)
process.WaitForInputIdle(-1);
process.Dispose();
}
string linqPadExePath = Path.Combine(linqPadInstallationPath, Resources.LINQPadExe);
string linqPadVersion = FileVersionInfo.GetVersionInfo(linqPadExePath).FileDescription;

Process foundProcess = Process.GetProcessesByName("LINQPad").FirstOrDefault(p => CommonRegistryConfigurations.LINQPadVersion.Equals(p.MainWindowTitle));
Process foundProcess = Process.GetProcessesByName("LINQPad").FirstOrDefault(p => linqPadVersion.Equals(p.MainWindowTitle));

SendInputToProcess(foundProcess ?? process);

Expand Down
5 changes: 3 additions & 2 deletions Src/DynamicCore/DynamicObjectSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void BroadCastData(object target, Stream outgoingData)
Type targetType = GetInterfaceTypeIfIsIterator(target);
string targetTypeFullName = TypeNameHelper.GetDisplayName(targetType, true);
string targetTypeName = TypeNameHelper.GetDisplayName(targetType, false);
//I'm lazy I know it...
//I'm lazy I know...
Regex pattern1 = new Regex("[<]");
Regex pattern2 = new Regex("[>]");
Regex pattern3 = new Regex("[,]");
Expand All @@ -72,7 +72,8 @@ public static void BroadCastData(object target, Stream outgoingData)
TypeName = typeName.Trim(),
TypeFullName = targetTypeFullName,
TypeNamespace = targetType.Namespace,
AssemblyQualifiedName = targetType.AssemblyQualifiedName
AssemblyQualifiedName = targetType.AssemblyQualifiedName,
AssemblyName = targetType.Assembly.GetName().Name
};

BinaryFormatter binaryFormatter = new BinaryFormatter();
Expand Down
15 changes: 8 additions & 7 deletions Src/DynamicCore/Template/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ internal class Message

public string TypeNamespace;
public string AssemblyQualifiedName;
public string AssemblyName;

public readonly List<string> ReferencedAssemblies;

public Message()
Expand All @@ -46,14 +48,13 @@ public Message()

public override string ToString()
{
return "FileName: " + FileName
+ Environment.NewLine
+ "TypeFullName: " + TypeFullName
+ Environment.NewLine
+ "TypeName: " + TypeName
return "FileName: " + FileName
+ Environment.NewLine
+ "TypeFullName: " + TypeFullName
+ Environment.NewLine
+ "TypeName: " + TypeName
+ Environment.NewLine
+ "TypeNamespace: " + TypeNamespace
+ Environment.NewLine;
+ "TypeNamespace: " + TypeNamespace;
}
}
}
28 changes: 15 additions & 13 deletions Src/VsExtension.Helper/Configuration/PackageConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,23 @@ private static string InstalledExtensionVersion(string vsVersion)
}

// ReSharper disable once InconsistentNaming
private static bool IsLINQPadInstalled()
private static bool IsLINQPadInstalled(string vsVersion)
{
var currentInstalledVersionPath = CommonRegistryConfigurations.GetLINQPadInstallationPath(vsVersion);
var alreadyInstalled = !string.IsNullOrEmpty(currentInstalledVersionPath);

if (alreadyInstalled && Directory.Exists(currentInstalledVersionPath))
return true;

//otherwise set it up manually
if (Directory.Exists(CommonFolderPaths.LinqPad5DestinationFolder))
{
CommonRegistryConfigurations.LINQPadInstallationPath = CommonFolderPaths.LinqPad5DestinationFolder;
CommonRegistryConfigurations.LINQPadVersion = LinqPad5;
CommonRegistryConfigurations.SetLINQPadInstallationPath(vsVersion, CommonFolderPaths.LinqPad5DestinationFolder);
return true;
}
if (Directory.Exists(CommonFolderPaths.LinqPad4DestinationFolder))
{
CommonRegistryConfigurations.LINQPadInstallationPath = CommonFolderPaths.LinqPad4DestinationFolder;
CommonRegistryConfigurations.LINQPadVersion = LinqPad4;
CommonRegistryConfigurations.SetLINQPadInstallationPath(vsVersion, CommonFolderPaths.LinqPad4DestinationFolder);
return true;
}

Expand All @@ -112,9 +117,8 @@ private static bool IsLINQPadInstalled()
if (string.IsNullOrEmpty(linqPadDirectoryName))
throw new Exception("LINQPad file name not correct");

CommonRegistryConfigurations.LINQPadInstallationPath = linqPadDirectoryName;
CommonRegistryConfigurations.LINQPadVersion = linqPadDirectoryName.Contains("LINQPad 5") ? LinqPad5 : LinqPad4;

CommonRegistryConfigurations.SetLINQPadInstallationPath(vsVersion, linqPadDirectoryName);

return true;
}
openWebSite:
Expand Down Expand Up @@ -222,7 +226,6 @@ public static bool IsBridgeVsConfigured(string visualStudioVersion)

return !string.IsNullOrEmpty(installationFolder) && installationFolder == CommonFolderPaths.InstallFolder;
}

private static void SetBridgeVsAssemblyVersion(string vsVersion)
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(GetRegistryKey(Resources.ProductVersion, vsVersion)))
Expand All @@ -236,7 +239,7 @@ public static bool Install(string vsVersion, string vsEdition)

try
{
if (!IsLINQPadInstalled()) //ask the user to insert a custom location
if (!IsLINQPadInstalled(vsVersion)) //ask the user to insert a custom location
{
return false;
}
Expand Down Expand Up @@ -374,7 +377,7 @@ private static void CreateVisualizerFolder(string vsVersion)
Log.Write($"Directory Created: {debuggerVisualizerTargetFolder}");

}

private static void CreateGrappleFolder()
{
Log.Write("Creating folder for Delivery {0}", Path.GetFullPath(CommonFolderPaths.GrappleFolder));
Expand All @@ -386,7 +389,6 @@ private static void CreateGrappleFolder()

Log.Write("Folder Successfully Created");
}

#endregion
}
}
}
41 changes: 39 additions & 2 deletions Src/VsExtension.Helper/Settings/PackageSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using BridgeVs.Locations;
using EnvDTE;
using Microsoft.VisualStudio.Shell.Interop;
using System.Windows.Forms;
using System.IO;
using System.Linq;

namespace BridgeVs.Helper.Settings
{
Expand All @@ -16,8 +21,40 @@ public sealed class PackageSettings : DialogPage
[Description("Sets the path to the LINQPad exe")]
public string LINQPadInstallationPath
{
get => CommonRegistryConfigurations.LINQPadInstallationPath;
set => CommonRegistryConfigurations.LINQPadInstallationPath = value;
get
{
var dte = (DTE)GetService(typeof(SDTE));
if (dte != null)
return CommonRegistryConfigurations.GetLINQPadInstallationPath(dte.Version);

return string.Empty;
}
set
{
var dte = (DTE)GetService(typeof(SDTE));
if (dte != null)
{
if (string.IsNullOrEmpty(value))
{
MessageBox.Show("Please insert a valid path to LINQPad");
return;
}
bool possiblePath = value.IndexOfAny(Path.GetInvalidPathChars()) == -1;

if (!possiblePath)
{
MessageBox.Show("Please insert a valid path to LINQPad");
return;
}

if (!Directory.GetFiles(value, "*.exe", SearchOption.TopDirectoryOnly).Any( p=> p.Contains("LINQPad.exe")))
{
MessageBox.Show("Please insert a valid path to LINQPad");
return;
}
CommonRegistryConfigurations.SetLINQPadInstallationPath(dte.Version, value);
}
}
}

//[Category("Feedback")]
Expand Down

0 comments on commit 546d1de

Please sign in to comment.