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

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

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

            DialogResult result = MessageBox.Show("Please Install LINQPad and then Restart Visual Studio or provide a folder", "LINQPad Not Found", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                OpenFileDialog dialog = new OpenFileDialog()
                {
                    Multiselect      = false,
                    Filter           = "LINQPad 4, 5|*.exe",
                    InitialDirectory = CommonFolderPaths.ProgramFilesFolderPath
                };
                DialogResult dialogResult   = dialog.ShowDialog();
                bool         isLinqPadFound = dialogResult == DialogResult.OK && dialog.FileName.Contains("LINQPad.exe");
                if (!isLinqPadFound)
                {
                    //how much do I love prohibitive things...
                    goto openWebSite;
                }

                string linqPadDirectoryName = Path.GetDirectoryName(dialog.FileName);
                if (string.IsNullOrEmpty(linqPadDirectoryName))
                {
                    throw new Exception("LINQPad file name not correct");
                }

                CommonRegistryConfigurations.SetLINQPadInstallationPath(vsVersion, linqPadDirectoryName);

                return(true);
            }
openWebSite:
            System.Diagnostics.Process.Start("http://www.linqpad.net");
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VisualizerAttributeInjector"/> class.
        /// </summary>
        /// <param name="targetVisualizerAssemblyPath">The assembly debugger visualizer location.</param>
        /// <param name="targetVsVersion">The targeted Visual Studio version</param>
        /// <exception cref="System.IO.FileNotFoundException"></exception>
        public VisualizerAttributeInjector(string targetVisualizerAssemblyPath, string targetVsVersion)
        {
            if (!FS.FileSystem.File.Exists(targetVisualizerAssemblyPath))
            {
                throw new FileNotFoundException(
                          $"Assembly doesn't exist at location {targetVisualizerAssemblyPath}");
            }


            //usually vsVersion has this format 15.0 so I'm only interested in the first part
            string versionNumber = targetVsVersion.Split('.').FirstOrDefault();

            int.TryParse(versionNumber, out int vsVersion);

            if (vsVersion == 0)
            {
                throw new ArgumentException($"Visual Studio version is incorrect {_targetVsVersion}");
            }

            _targetVsVersion = vsVersion;

            //create pdb info if logging or error tracking is enabled
            bool createPdbInfo = CommonRegistryConfigurations.IsLoggingEnabled(targetVsVersion);

            createPdbInfo |= CommonRegistryConfigurations.IsErrorTrackingEnabled(targetVsVersion);

            _writerParameters = new WriterParameters
            {
                WriteSymbols         = createPdbInfo,
                SymbolWriterProvider = createPdbInfo ? new PdbWriterProvider() : null
            };

            ReaderParameters readerParameters = new ReaderParameters
            {
                AssemblyResolver             = GetAssemblyResolver(targetVisualizerAssemblyPath),
                ReadingMode                  = ReadingMode.Immediate,
                SymbolReaderProvider         = createPdbInfo ? new PdbReaderProvider() : null,
                InMemory                     = true,
                ReadSymbols                  = createPdbInfo,
                ThrowIfSymbolsAreNotMatching = false,
            };

            //using a stream is better for testing
            _assemblyStream = FS.FileSystem.File.OpenRead(targetVisualizerAssemblyPath);

            _debuggerVisualizerAssembly = AssemblyDefinition.ReadAssembly(_assemblyStream, readerParameters);

            InitializeDebuggerAssembly();
            RemapAssembly();
        }
        private void Create3RdPartyVisualizers()
        {
            try
            {
                if (!CommonRegistryConfigurations.Map3RdPartyAssembly(SolutionName, VisualStudioVer))
                {
                    return;
                }

                IEnumerable <string> assemblies = Crawler.FindDependencies(ProjectPath);

                foreach (string assemblyPath in assemblies)
                {
                    string assemblyName;

                    try
                    {
                        assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
                    }
                    catch
                    {
                        continue; //in case it is not a well formed path
                    }
                    //visualizer target name based on visual studio version
                    string targetAssemblyName = VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(VisualStudioVer, assemblyName);

                    string targetInstallationFilePath = Path.Combine(VisualizerDestinationFolder, targetAssemblyName);

                    //no need to recreate the 3rd party assembly all the time
                    if (FS.FileSystem.File.Exists(targetInstallationFilePath))
                    {
                        continue;
                    }
                    VisualizerAttributeInjector attributeInjector = new VisualizerAttributeInjector(_dynamicVisualizerDllAssemblyPath, VisualStudioVer);

                    attributeInjector.MapTypesFromAssembly(assemblyPath);

                    attributeInjector.SaveDebuggerVisualizer(targetInstallationFilePath);
                }
            }
            catch (Exception e)
            {
                const string errorMessage = "Error Mapping 3rd Party Assemblies";
                Log.Write(e, errorMessage);
                BuildWarningEventArgs errorEvent = new BuildWarningEventArgs("Debugger Visualizer Creator", "", "MapperBuildTask", 0, 0, 0, 0, $"There was an error creating custom debugger visualizers for 3rd Party Assemblies. Disable it in Tools->Options->BridgeVs->Map3RdPartyAssembly", "", "LINQBridgeVs");
                BuildEngine.LogWarningEvent(errorEvent);
                e.Capture(VisualStudioVer, message: errorMessage);
            }
        }
        public void Capture(Exception exception, ErrorLevel errorLevel = ErrorLevel.Error, string message = "")
        {
            if (!CommonRegistryConfigurations.IsErrorTrackingEnabled(VisualStudioVersion))
            {
                return;
            }

            var sentryEvent = new SentryEvent(exception)
            {
                Message = message,
                Level   = errorLevel
            };

            sentryEvent.Tags.Add("Visual Studio Version", VisualStudioVersion);

            _ravenClient.Capture(sentryEvent);
        }
        public static void ActivateBridgeVsOnSolution(CommandAction action, List <Project> projects, string solutionName,
                                                      string vsVersion,
                                                      string vsEdition)
        {
            List <BridgeProjectInfo> executeParams = new List <BridgeProjectInfo>();

            //enable each individual project by mapping the assembly name and location to a registry entry
            foreach (Project project in projects)
            {
                string path       = project.Properties.Item("FullPath").Value.ToString();
                string outputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value
                                    .ToString();
                string fileName          = project.Properties.Item("OutputFileName").Value.ToString();
                string projectOutputPath = Path.Combine(path, outputPath, fileName);

                string assemblyName             = project.Properties.Item("AssemblyName").Value.ToString();
                IEnumerable <string> references = Enumerable.Empty <string>();

                if (project.Object is VSProject vsProject && vsProject.References != null)
                {
                    references = from Reference reference in vsProject.References
                                 where reference.SourceProject == null                                                    //it means it's an assembly reference
                                 where !reference.Path.Contains(".NETFramework") && !reference.Path.Contains("Microsoft") //no .net framework assembly
                                 select reference.Path;
                }

                executeParams.Add(new BridgeProjectInfo(project.FullName, solutionName, assemblyName,
                                                        projectOutputPath, vsVersion, vsEdition, references.ToList()));
            }
            switch (action)
            {
            case CommandAction.Enable:
                CommonRegistryConfigurations.BridgeSolution(solutionName, vsVersion, executeParams);
                break;

            case CommandAction.Disable:
                CommonRegistryConfigurations.UnBridgeSolution(solutionName, vsVersion);
                break;
            }

            string result     = action == CommandAction.Enable ? "Bridged" : "Un-Bridged";
            string userAction = action == CommandAction.Enable ? "Please rebuild your solution." : string.Empty;
            string message    = $@"Solution {solutionName} has been {result}. {userAction}";

            MessageBox.Show(message);
        }
        private static string InstalledExtensionVersion(string vsVersion)
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(CommonRegistryConfigurations.GetRegistryKey(Resources.ProductVersion, vsVersion)))
            {
                if (key == null)
                {
                    return(string.Empty);
                }

                object value = key.GetValue(VersionRegistryValue);

                if (value != null)
                {
                    return(value.ToString());
                }
            }
            return(string.Empty);
        }
Exemple #7
0
        private CommandStates GetStatus(CommandAction action)
        {
            CommandStates result = CommandStates.Visible;

            bool isBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_application.Version);

            if (!isBridgeVsConfigured)
            {
                return(result); //just show it as visible
            }
            bool isSolutionEnabled = CommonRegistryConfigurations.IsSolutionEnabled(SolutionName, _application.Version);

            if (isSolutionEnabled && action == CommandAction.Disable || !isSolutionEnabled && action == CommandAction.Enable)
            {
                result |= CommandStates.Enabled;
            }

            return(result);
        }
        private static void SetInstallationFolder(string vsVersion)
        {
            //Set in the registry the installer location if it is has changed
            using (RegistryKey key = Registry.CurrentUser.CreateSubKey(CommonRegistryConfigurations.GetRegistryKey(Resources.ProductRegistryKey, vsVersion)))
            {
                if (key == null)
                {
                    return;
                }

                object value = key.GetValue(InstallFolderPathRegistryValue);

                if (value != null && value.Equals(CommonFolderPaths.InstallFolder))
                {
                    return;
                }

                key.SetValue(InstallFolderPathRegistryValue, CommonFolderPaths.InstallFolder);
            }
        }
        public void Init()
        {
            Isolate.WhenCalled(() => FS.FileSystem).WillReturn(MockFileSystem);

            object[] args =
            {
                AssemblyToInjectLocation, FileMode.Open, FileAccess.ReadWrite,
                FileShare.Read
            };
            Stream access = FS.FileSystem.File.Open(AssemblyToInjectLocation, FileMode.Open, FileAccess.Read,
                                                    FileShare.ReadWrite);

            Isolate.NonPublic.WhenCalled(typeof(ModuleDefinition), "GetFileStream")
            .WithExactArguments(args)
            .WillReturn(access);

            Isolate.WhenCalled(() => CommonRegistryConfigurations.Map3RdPartyAssembly("", "")).WillReturn(false);
            Isolate.WhenCalled(() => CommonRegistryConfigurations.IsErrorTrackingEnabled("")).WillReturn(false);
            Isolate.WhenCalled(() => CommonRegistryConfigurations.IsLoggingEnabled("")).WillReturn(false);
        }
Exemple #10
0
        public static void Write(string msg, params object[] args)
        {
            if (string.IsNullOrEmpty(VisualStudioVersion))
            {
                return;
            }

            if (!CommonRegistryConfigurations.IsLoggingEnabled(VisualStudioVersion))
            {
                return;
            }

            try
            {
                InternalWrite(msg, args);
            }
            catch
            {
                // ignored
            }
        }
Exemple #11
0
        public static void Capture(this Exception exception, string vsVersion, ErrorLevel errorLevel = ErrorLevel.Error, string message = "")
        {
            if (string.IsNullOrEmpty(vsVersion))
            {
                return;
            }

            if (!CommonRegistryConfigurations.IsErrorTrackingEnabled(vsVersion))
            {
                return;
            }

            Func <Requester, Requester> removeUserId = new Func <Requester, Requester>(request =>
            {
                //GDPR compliant, no personal data sent: no server name, no username stored, no ip address
                request.Packet.ServerName           = LinqBridgeVs;
                request.Packet.Contexts.Device.Name = LinqBridgeVs;
                request.Packet.User.Username        = CommonRegistryConfigurations.GetUniqueGuid(vsVersion);
                request.Packet.Release        = Assembly.GetExecutingAssembly().VersionNumber();
                request.Packet.User.IpAddress = "0.0.0.0";
                return(request);
            });

            SentryEvent sentryEvent = new SentryEvent(exception)
            {
                Message = message,
                Level   = errorLevel
            };

            sentryEvent.Tags.Add("Visual Studio Version", vsVersion);

            RavenClient ravenClient = new RavenClient(RavenClientId)
            {
                BeforeSend     = removeUserId,
                ErrorOnCapture = OnSendError,
                Timeout        = TimeSpan.FromMilliseconds(Timeout) //should fail early if it can't send a message
            };

            ravenClient.Capture(sentryEvent);
        }
        public bool Execute()
        {
            Log.VisualStudioVersion = VisualStudioVer;

            if (!CommonRegistryConfigurations.IsSolutionEnabled(SolutionName, VisualStudioVer))
            {
                return(true);
            }

            try
            {
                string visualizerAssemblyName = VisualizerAssemblyNameFormat.GetTargetVisualizerAssemblyName(VisualStudioVer, Assembly);
                string targetInstallationPath = VisualStudioOption.GetVisualizerDestinationFolder(VisualStudioVer);

                string visualizerFullPath = Path.Combine(targetInstallationPath, visualizerAssemblyName);

                if (FS.FileSystem.File.Exists(visualizerFullPath))
                {
                    FS.FileSystem.File.Delete(visualizerFullPath);
                }

                //check if pdb also exists and delete it
                string visualizerPdbFullPath = Path.ChangeExtension(visualizerFullPath, "pdb");

                if (FS.FileSystem.File.Exists(visualizerPdbFullPath))
                {
                    FS.FileSystem.File.Delete(visualizerPdbFullPath);
                }
            }
            catch (System.Exception exception)
            {
                Log.Write(exception, "Error During cleanup");
                BuildWarningEventArgs errorEvent = new BuildWarningEventArgs("Debugger Visualizer Cleanup", "", "CleanBuildTask", 0, 0, 0, 0, $"There was an error cleaning custom debugger visualizers", "", "LINQBridgeVs");
                BuildEngine.LogWarningEvent(errorEvent);
                exception.Capture(VisualStudioVer, message: "Error during project cleaning");
            }

            return(true);
        }
Exemple #13
0
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            string vsVersion = VisualStudioVersionHelper.FindCurrentVisualStudioVersion();

            Log.VisualStudioVersion = vsVersion;
            Exception exception = null;

            try
            {
                Message message = GetMessage(objectProvider);

                string linqQueryFileName = DeployLinqScript(message, vsVersion);

                string linqPadInstallationPath = CommonRegistryConfigurations.GetLINQPadInstallationPath(vsVersion);

                OpenLinqPad(linqQueryFileName, linqPadInstallationPath);

                string linqPadExePath = Path.Combine(linqPadInstallationPath, "LINQPad.exe");
                string linqPadVersion = FileVersionInfo.GetVersionInfo(linqPadExePath).FileDescription;

                SendInputToLinqPad(linqPadVersion);
            }
            catch (ThreadAbortException)
            {
                // Catch exception and do nothing
                Thread.ResetAbort();
            }
            catch (Exception ex)
            {
                const string context = "Error during LINQPad execution";
                Log.Write(ex, context);
                ex.Capture(vsVersion, message: context);
                exception = ex;
            }

            windowService.ShowDialog(new TemporaryForm(exception));
        }
Exemple #14
0
 private static void GenerateGuidForCurrentInstallation(string vsVersion)
 {
     CommonRegistryConfigurations.SetUniqueGuid(vsVersion, Guid.NewGuid().ToString());
 }
Exemple #15
0
 public void Init()
 {
     Isolate.WhenCalled(() => FS.FileSystem).WillReturn(new MockFileSystem());
     Isolate.WhenCalled(() => CommonRegistryConfigurations.IsErrorTrackingEnabled("")).WillReturn(false);
     Isolate.WhenCalled(() => CommonRegistryConfigurations.IsLoggingEnabled("")).WillReturn(false);
 }