public async Task <bool> UploadExceptionAsync(SerializableException exception, bool force = false) { if (IsTelemetryEnabled || force) { _editorContext.WriteToLog(Resources.ExceptionEncountered); _editorContext.WriteToLog(exception.GetDescription()); return(await UploadExceptionAsync(exception)); } else { return(false); } }
private bool TryLoadFrom(string path) { if (File.Exists(path)) { try { var text = File.ReadAllText(path); JsonConvert.PopulateObject(text, this); return(true); } catch (Exception e) { _editorContext.WriteToLog($"Could not load solution settings from: {path}.\r\n" + e.GetDescription()); } } return(false); }
public async Task <bool> TryInstallRelease(Release release) { try { _installerMutex.WaitOne(); var downloadPath = Path.Combine(Path.GetTempPath(), "AxoCover." + release.Version + ".vsix"); try { if (File.Exists(downloadPath)) { File.Delete(downloadPath); } } catch { _editorContext.WriteToLog($"Cannot write to {downloadPath}. Maybe another installation is in progress?"); return(false); } using (var webClient = new WebClient()) { await webClient.DownloadFileTaskAsync(release.AlternativeUri ?? release.Uri, downloadPath); } return(await Task.Run(async() => { try { InstallVsix(downloadPath); return true; } catch (Exception e) { await _telemetryManager.UploadExceptionAsync(e); return false; } })); } catch { return(false); } finally { _installerMutex.ReleaseMutex(); } }
public async Task <TestSolution> GetTestSolutionAsync(Solution solution, string testSettings) { try { Interlocked.Increment(ref _sessionCount); ScanningStarted?.Invoke(this, EventArgs.Empty); var testSolution = new TestSolution(solution.Properties.Item("Name").Value as string, solution.FileName); var testAdapters = new HashSet <ITestAdapter>(); var testAdapterModes = new HashSet <TestAdapterMode>(); var projects = solution.GetProjects(); foreach (Project project in projects) { var assemblyName = project.GetAssemblyName(); if (assemblyName == null) { continue; } var isTestSource = false; var testAdapterNames = new List <string>(); foreach (var testAdapter in _testAdapterRepository.Adapters.Values) { if (testAdapter.IsTestSource(project)) { testAdapters.Add(testAdapter); testAdapterModes.Add(testAdapter.Mode); testAdapterNames.Add(testAdapter.Name); isTestSource = true; } } if (isTestSource) { var outputFilePath = project.GetOutputDllPath(); var testProject = new TestProject(testSolution, project.Name, outputFilePath, testAdapterNames.ToArray()); testSolution.TestAssemblies.Add(assemblyName); } else { testSolution.CodeAssemblies.Add(assemblyName); } } if (testAdapterModes.Count == 1) { _options.TestAdapterMode = testAdapterModes.First(); } foreach (var testAdapter in testAdapters.ToArray()) { if (testAdapter.Mode != _options.TestAdapterMode) { testAdapters.Remove(testAdapter); } } await Task.Run(() => { try { var testDiscoveryTasks = testAdapters .Select(p => new TestDiscoveryTask() { TestAssemblyPaths = testSolution.Children .OfType <TestProject>() .Where(q => q.TestAdapters.Contains(p.Name)) .Select(q => q.OutputFilePath) .ToArray(), TestAdapterOptions = p .GetLoadingOptions() .Do(q => q.IsRedirectingAssemblies = _options.IsRedirectingFrameworkAssemblies) }) .ToArray(); using (var discoveryProcess = DiscoveryProcess.Create(AdapterExtensions.GetTestPlatformAssemblyPaths(_options.TestAdapterMode))) { _editorContext.WriteToLog(Resources.TestDiscoveryStarted); discoveryProcess.MessageReceived += (o, e) => _editorContext.WriteToLog(e.Value); discoveryProcess.OutputReceived += (o, e) => _editorContext.WriteToLog(e.Value); var discoveryResults = discoveryProcess.DiscoverTests(testDiscoveryTasks, testSettings); var testCasesByAssembly = discoveryResults .Distinct(_testCaseEqualityComparer) .GroupBy(p => p.Source) .ToDictionary(p => p.Key, p => p.ToArray(), StringComparer.OrdinalIgnoreCase); foreach (TestProject testProject in testSolution.Children.ToArray()) { var testCases = testCasesByAssembly.TryGetValue(testProject.OutputFilePath); if (testCases != null) { LoadTests(testProject, testCases); } var isEmpty = !testProject .Flatten <TestItem>(p => p.Children, false) .Any(p => p.Kind == CodeItemKind.Method); if (isEmpty) { testProject.Remove(); } } _editorContext.WriteToLog(Resources.TestDiscoveryFinished); } } catch (RemoteException exception) when(exception.RemoteReason != null) { _editorContext.WriteToLog(Resources.TestDiscoveryFailed); _telemetryManager.UploadExceptionAsync(exception.RemoteReason); } catch (Exception exception) { _editorContext.WriteToLog(Resources.TestDiscoveryFailed); _telemetryManager.UploadExceptionAsync(exception); } }); ScanningFinished?.Invoke(this, EventArgs.Empty); return(testSolution); } finally { Interlocked.Decrement(ref _sessionCount); } }
private void OnTestLogAdded(object sender, EventArgs <string> e) { _editorContext.WriteToLog(e.Value); }
private void OnTestLogAdded(object sender, LogAddedEventArgs e) { _editorContext.WriteToLog(e.Text); }