private string GetScriptPath(EnvironmentView view) { if (view == null) { return(null); } string path; lock (_cachedScriptPaths) { if (_cachedScriptPaths.TryGetValue(view, out path)) { return(path); } } try { path = _uiThread.Invoke(() => PythonInteractiveEvaluator.GetScriptsPath( _site, view.Description, view.Factory.Configuration, false )); } catch (Exception ex) when(!ex.IsCriticalException()) { view.Dispatcher.BeginInvoke((Action)(() => ex.ReportUnhandledException(_site, GetType())), DispatcherPriority.ApplicationIdle); path = null; } lock (_cachedScriptPaths) { _cachedScriptPaths[view] = path; } return(path); }
private string GetScriptPath(EnvironmentView view) { if (view == null) { return(null); } return(_uiThread.Invoke(() => PythonInteractiveEvaluator.GetScriptsPath( _site, view.Description, view.Factory.Configuration, false ))); }
private void GenerateFile(UIThreadBase uiThread, string filePath) { try { uiThread.Invoke(() => { using (var writer = new StreamWriter(filePath, false, Encoding.UTF8)) { try { _serviceProvider.GetPythonToolsService().GetDiagnosticsLog(writer, false); } catch (Exception ex) when(!ex.IsCriticalException()) { // Append the error to the log we're writing writer.WriteLine(ex.ToUnhandledExceptionMessage(GetType())); } } }); } catch (Exception ex) when(!ex.IsCriticalException()) { } }
private string GetData(UIThreadBase ui, bool skipAnalysisLog, CancellationToken cancel) { StringBuilder res = new StringBuilder(); if (PythonToolsPackage.IsIpyToolsInstalled()) { res.AppendLine("WARNING: IpyTools is installed on this machine. Having both IpyTools and Python Tools for Visual Studio installed will break Python editing."); } string pythonPathIsMasked = ""; EnvDTE.DTE dte = null; IPythonInterpreterFactoryProvider[] knownProviders = null; IPythonLauncherProvider[] launchProviders = null; InMemoryLogger inMemLogger = null; ui.Invoke((Action)(() => { pythonPathIsMasked = _serviceProvider.GetPythonToolsService().GeneralOptions.ClearGlobalPythonPath ? " (masked)" : ""; dte = (EnvDTE.DTE)_serviceProvider.GetService(typeof(EnvDTE.DTE)); var model = _serviceProvider.GetComponentModel(); knownProviders = model.GetExtensions<IPythonInterpreterFactoryProvider>().ToArray(); launchProviders = model.GetExtensions<IPythonLauncherProvider>().ToArray(); inMemLogger = model.GetService<InMemoryLogger>(); })); res.AppendLine("Projects: "); var projects = dte.Solution.Projects; foreach (EnvDTE.Project project in projects) { cancel.ThrowIfCancellationRequested(); string name; try { // Some projects will throw rather than give us a unique // name. They are not ours, so we will ignore them. name = project.UniqueName; } catch (Exception ex) when (!ex.IsCriticalException()) { bool isPythonProject = false; try { isPythonProject = Utilities.GuidEquals(PythonConstants.ProjectFactoryGuid, project.Kind); } catch (Exception ex2) when (!ex2.IsCriticalException()) { } if (isPythonProject) { // Actually, it was one of our projects, so we do care // about the exception. We'll add it to the output, // rather than crashing. res.AppendLine(" Project: " + ex.Message); res.AppendLine(" Kind: Python"); } continue; } res.AppendLine(" Project: " + name); if (Utilities.GuidEquals(PythonConstants.ProjectFactoryGuid, project.Kind)) { res.AppendLine(" Kind: Python"); foreach (var prop in InterestingDteProperties) { res.AppendLine(" " + prop + ": " + GetProjectProperty(project, prop)); } var pyProj = project.GetPythonProject(); if (pyProj != null) { ui.Invoke((Action)(() => { foreach (var prop in InterestingProjectProperties) { var propValue = pyProj.GetProjectProperty(prop); if (propValue != null) { res.AppendLine(" " + prop + ": " + propValue); } } })); foreach (var factory in pyProj.InterpreterFactories) { res.AppendLine(); res.AppendLine(" Interpreter: " + factory.Configuration.Description); res.AppendLine(" Id: " + factory.Configuration.Id); res.AppendLine(" Version: " + factory.Configuration.Version); res.AppendLine(" Arch: " + factory.Configuration.Architecture); res.AppendLine(" Prefix Path: " + factory.Configuration.PrefixPath ?? "(null)"); res.AppendLine(" Path: " + factory.Configuration.InterpreterPath ?? "(null)"); res.AppendLine(" Windows Path: " + factory.Configuration.WindowsInterpreterPath ?? "(null)"); res.AppendLine(string.Format(" Path Env: {0}={1}{2}", factory.Configuration.PathEnvironmentVariable ?? "(null)", Environment.GetEnvironmentVariable(factory.Configuration.PathEnvironmentVariable ?? ""), pythonPathIsMasked )); } } } else { res.AppendLine(" Kind: " + project.Kind); } res.AppendLine(); } res.AppendLine("Environments: "); foreach (var provider in knownProviders.MaybeEnumerate()) { cancel.ThrowIfCancellationRequested(); res.AppendLine(" " + provider.GetType().FullName); foreach (var config in provider.GetInterpreterConfigurations()) { res.AppendLine(" Id: " + config.Id); res.AppendLine(" Factory: " + config.Description); res.AppendLine(" Version: " + config.Version); res.AppendLine(" Arch: " + config.Architecture); res.AppendLine(" Prefix Path: " + config.PrefixPath ?? "(null)"); res.AppendLine(" Path: " + config.InterpreterPath ?? "(null)"); res.AppendLine(" Windows Path: " + config.WindowsInterpreterPath ?? "(null)"); res.AppendLine(" Path Env: " + config.PathEnvironmentVariable ?? "(null)"); res.AppendLine(); } } res.AppendLine("Launchers:"); foreach (var launcher in launchProviders.MaybeEnumerate()) { cancel.ThrowIfCancellationRequested(); res.AppendLine(" Launcher: " + launcher.GetType().FullName); res.AppendLine(" " + launcher.Description); res.AppendLine(" " + launcher.Name); res.AppendLine(); } try { res.AppendLine("Logged events/stats:"); res.AppendLine(inMemLogger.ToString()); res.AppendLine(); } catch (Exception ex) when (!ex.IsCriticalException()) { res.AppendLine(" Failed to access event log."); res.AppendLine(ex.ToString()); res.AppendLine(); } try { res.AppendLine("System events:"); var application = new EventLog("Application"); var lastWeek = DateTime.Now.Subtract(TimeSpan.FromDays(7)); foreach (var entry in application.Entries.Cast<EventLogEntry>() .Where(e => e.InstanceId == 1026L) // .NET Runtime .Where(e => e.TimeGenerated >= lastWeek) .Where(e => InterestingApplicationLogEntries.IsMatch(e.Message)) .OrderByDescending(e => e.TimeGenerated) ) { res.AppendLine(string.Format("Time: {0:s}", entry.TimeGenerated)); using (var reader = new StringReader(entry.Message.TrimEnd())) { for (var line = reader.ReadLine(); line != null; line = reader.ReadLine()) { res.AppendLine(line); } } res.AppendLine(); } } catch (Exception ex) when (!ex.IsCriticalException()) { res.AppendLine(" Failed to access event log."); res.AppendLine(ex.ToString()); res.AppendLine(); } res.AppendLine("Loaded assemblies:"); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(assem => assem.FullName)) { cancel.ThrowIfCancellationRequested(); AssemblyFileVersionAttribute assemFileVersion; var error = "(null)"; try { assemFileVersion = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false) .OfType<AssemblyFileVersionAttribute>() .FirstOrDefault(); } catch (Exception e) when (!e.IsCriticalException()) { assemFileVersion = null; error = string.Format("{0}: {1}", e.GetType().Name, e.Message); } res.AppendLine(string.Format(" {0}, FileVersion={1}", assembly.FullName, assemFileVersion?.Version ?? error )); } res.AppendLine(); string globalAnalysisLog = PythonTypeDatabase.GlobalLogFilename; if (File.Exists(globalAnalysisLog)) { res.AppendLine("Global Analysis:"); try { res.AppendLine(File.ReadAllText(globalAnalysisLog)); } catch (Exception ex) when (!ex.IsCriticalException()) { res.AppendLine("Error reading the global analysis log."); res.AppendLine("Please wait for analysis to complete and try again."); res.AppendLine(ex.ToString()); } } res.AppendLine(); if (!skipAnalysisLog) { res.AppendLine("Environment Analysis Logs: "); foreach (var provider in knownProviders) { foreach (var factory in provider.GetInterpreterFactories().OfType<IPythonInterpreterFactoryWithDatabase>()) { cancel.ThrowIfCancellationRequested(); res.AppendLine(factory.Configuration.Description); string analysisLog = factory.GetAnalysisLogContent(CultureInfo.InvariantCulture); if (!string.IsNullOrEmpty(analysisLog)) { res.AppendLine(analysisLog); } res.AppendLine(); } } } return res.ToString(); }
private string GetData(UIThreadBase ui, bool skipAnalysisLog, CancellationToken cancel) { StringBuilder res = new StringBuilder(); string pythonPathIsMasked = ""; EnvDTE.DTE dte = null; IPythonInterpreterFactoryProvider[] knownProviders = null; IPythonLauncherProvider[] launchProviders = null; InMemoryLogger inMemLogger = null; ui.Invoke((Action)(() => { pythonPathIsMasked = _serviceProvider.GetPythonToolsService().GeneralOptions.ClearGlobalPythonPath ? " (masked)" : ""; dte = (EnvDTE.DTE)_serviceProvider.GetService(typeof(EnvDTE.DTE)); var model = _serviceProvider.GetComponentModel(); knownProviders = model.GetExtensions <IPythonInterpreterFactoryProvider>().ToArray(); launchProviders = model.GetExtensions <IPythonLauncherProvider>().ToArray(); inMemLogger = model.GetService <InMemoryLogger>(); })); res.AppendLine("Projects: "); var projects = dte.Solution.Projects; foreach (EnvDTE.Project project in projects) { cancel.ThrowIfCancellationRequested(); string name; try { // Some projects will throw rather than give us a unique // name. They are not ours, so we will ignore them. name = project.UniqueName; } catch (Exception ex) when(!ex.IsCriticalException()) { bool isPythonProject = false; try { isPythonProject = Utilities.GuidEquals(PythonConstants.ProjectFactoryGuid, project.Kind); } catch (Exception ex2) when(!ex2.IsCriticalException()) { } if (isPythonProject) { // Actually, it was one of our projects, so we do care // about the exception. We'll add it to the output, // rather than crashing. res.AppendLine(" Project: " + ex.Message); res.AppendLine(" Kind: Python"); } continue; } res.AppendLine(" Project: " + name); if (Utilities.GuidEquals(PythonConstants.ProjectFactoryGuid, project.Kind)) { res.AppendLine(" Kind: Python"); foreach (var prop in InterestingDteProperties) { res.AppendLine(" " + prop + ": " + GetProjectProperty(project, prop)); } var pyProj = project.GetPythonProject(); if (pyProj != null) { ui.Invoke((Action)(() => { foreach (var prop in InterestingProjectProperties) { var propValue = pyProj.GetProjectProperty(prop); if (propValue != null) { res.AppendLine(" " + prop + ": " + propValue); } } })); foreach (var factory in pyProj.InterpreterFactories) { res.AppendLine(); res.AppendLine(" Interpreter: " + factory.Configuration.Description); res.AppendLine(" Id: " + factory.Configuration.Id); res.AppendLine(" Version: " + factory.Configuration.Version); res.AppendLine(" Arch: " + factory.Configuration.Architecture); res.AppendLine(" Prefix Path: " + factory.Configuration.PrefixPath ?? "(null)"); res.AppendLine(" Path: " + factory.Configuration.InterpreterPath ?? "(null)"); res.AppendLine(" Windows Path: " + factory.Configuration.WindowsInterpreterPath ?? "(null)"); res.AppendLine(string.Format(" Path Env: {0}={1}{2}", factory.Configuration.PathEnvironmentVariable ?? "(null)", Environment.GetEnvironmentVariable(factory.Configuration.PathEnvironmentVariable ?? ""), pythonPathIsMasked )); } } } else { res.AppendLine(" Kind: " + project.Kind); } res.AppendLine(); } res.AppendLine("Environments: "); foreach (var provider in knownProviders.MaybeEnumerate()) { cancel.ThrowIfCancellationRequested(); res.AppendLine(" " + provider.GetType().FullName); foreach (var config in provider.GetInterpreterConfigurations()) { res.AppendLine(" Id: " + config.Id); res.AppendLine(" Factory: " + config.Description); res.AppendLine(" Version: " + config.Version); res.AppendLine(" Arch: " + config.Architecture); res.AppendLine(" Prefix Path: " + config.PrefixPath ?? "(null)"); res.AppendLine(" Path: " + config.InterpreterPath ?? "(null)"); res.AppendLine(" Windows Path: " + config.WindowsInterpreterPath ?? "(null)"); res.AppendLine(" Path Env: " + config.PathEnvironmentVariable ?? "(null)"); res.AppendLine(); } } res.AppendLine("Launchers:"); foreach (var launcher in launchProviders.MaybeEnumerate()) { cancel.ThrowIfCancellationRequested(); res.AppendLine(" Launcher: " + launcher.GetType().FullName); res.AppendLine(" " + launcher.Description); res.AppendLine(" " + launcher.Name); res.AppendLine(); } try { res.AppendLine("Logged events/stats:"); res.AppendLine(inMemLogger.ToString()); res.AppendLine(); } catch (Exception ex) when(!ex.IsCriticalException()) { res.AppendLine(" Failed to access event log."); res.AppendLine(ex.ToString()); res.AppendLine(); } if (!skipAnalysisLog) { try { res.AppendLine("System events:"); var application = new EventLog("Application"); var lastWeek = DateTime.Now.Subtract(TimeSpan.FromDays(7)); foreach (var entry in application.Entries.Cast <EventLogEntry>() .Where(e => e.InstanceId == 1026L) // .NET Runtime .Where(e => e.TimeGenerated >= lastWeek) .Where(e => InterestingApplicationLogEntries.IsMatch(e.Message)) .OrderByDescending(e => e.TimeGenerated) ) { res.AppendLine(string.Format("Time: {0:s}", entry.TimeGenerated)); using (var reader = new StringReader(entry.Message.TrimEnd())) { for (var line = reader.ReadLine(); line != null; line = reader.ReadLine()) { res.AppendLine(line); } } res.AppendLine(); } } catch (Exception ex) when(!ex.IsCriticalException()) { res.AppendLine(" Failed to access event log."); res.AppendLine(ex.ToString()); res.AppendLine(); } } res.AppendLine("Loaded assemblies:"); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().OrderBy(assem => assem.FullName)) { cancel.ThrowIfCancellationRequested(); AssemblyFileVersionAttribute assemFileVersion; var error = "(null)"; try { assemFileVersion = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false) .OfType <AssemblyFileVersionAttribute>() .FirstOrDefault(); } catch (Exception e) when(!e.IsCriticalException()) { assemFileVersion = null; error = string.Format("{0}: {1}", e.GetType().Name, e.Message); } res.AppendLine(string.Format(" {0}, FileVersion={1}", assembly.FullName, assemFileVersion?.Version ?? error )); } res.AppendLine(); string globalAnalysisLog = PythonTypeDatabase.GlobalLogFilename; if (File.Exists(globalAnalysisLog)) { res.AppendLine("Global Analysis:"); try { res.AppendLine(File.ReadAllText(globalAnalysisLog)); } catch (Exception ex) when(!ex.IsCriticalException()) { res.AppendLine("Error reading the global analysis log."); res.AppendLine("Please wait for analysis to complete and try again."); res.AppendLine(ex.ToString()); } } res.AppendLine(); if (!skipAnalysisLog) { res.AppendLine("Environment Analysis Logs: "); foreach (var provider in knownProviders) { foreach (var factory in provider.GetInterpreterFactories().OfType <IPythonInterpreterFactoryWithDatabase>()) { cancel.ThrowIfCancellationRequested(); res.AppendLine(factory.Configuration.Description); string analysisLog = factory.GetAnalysisLogContent(CultureInfo.InvariantCulture); if (!string.IsNullOrEmpty(analysisLog)) { res.AppendLine(analysisLog); } res.AppendLine(); } } } return(res.ToString()); }