コード例 #1
0
        public async Task OpenReportFolderAsync()
        {
            try
            {
                var toolWindow = (BenchmarkTreeWindow)_package.FindToolWindow(typeof(BenchmarkTreeWindow), 0, false);
                BenchmarkTreeNode selectedNode = toolWindow.SelectedItem;
                if (selectedNode == null)
                {
                    return;
                }

                string reportFolder = await BenchmarkResultCollection.GetReportFolderAsync(selectedNode.ProjectName);

                if (!Directory.Exists(reportFolder))
                {
                    return;
                }

                Process.Start(reportFolder);
            }
            catch (Exception ex)
            {
                await UIHelper.ShowErrorAsync(_package, ex.Message);
            }
        }
コード例 #2
0
        public async Task RunAsync(bool isDryRun)
        {
            try
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(_package.DisposalToken);

                var toolWindow = (BenchmarkTreeWindow)_package.FindToolWindow(typeof(BenchmarkTreeWindow), 0, false);
                BenchmarkTreeNode selectedNode = toolWindow.SelectedItem;

                var            dte2    = (DTE2)Package.GetGlobalService(typeof(SDTE));
                EnvDTE.Project project = GetProject(dte2, selectedNode.ProjectName);
                if (project == null)
                {
                    return;
                }

                var propertyProvider = await CreateProjectPropertyProviderAsync(project.Name);

                try
                {
                    if (!propertyProvider.IsOptimized)
                    {
                        await UIHelper.ShowErrorAsync(_package,
                                                      "The current build configuration does not have the \"Optimize code\" flag set and is therefore not suitable for running Benchmarks.\r\n\r\nPlease enable the the \"Optimize code\" flag (under Project Properties -> Build) or switch to a non-debug configuration (e.g. 'Release') before running a Benchmark.");

                        return;
                    }
                }
                catch (Exception)
                {
                }

                string configurationName = project.ConfigurationManager.ActiveConfiguration.ConfigurationName;
                dte2.Solution.SolutionBuild.BuildProject(configurationName, project.UniqueName, true);
                if (dte2.Solution.SolutionBuild.LastBuildInfo != 0)
                {
                    return;
                }

                var runParameters = new RunParameters
                {
                    OutputPath   = propertyProvider.OutputPath,
                    ProjectPath  = propertyProvider.ProjectPath,
                    Runtime      = propertyProvider.TargetRuntime,
                    AssemblyPath = propertyProvider.GetOutputFilename(),
                    IsDryRun     = isDryRun,
                    SelectedNode = selectedNode
                };
                BenchmarkRunController runController = new BenchmarkRunController(runParameters, GetOptions());
                await runController.RunAsync();
            }
            catch (Exception ex)
            {
                await UIHelper.ShowErrorAsync(_package, ex.Message);
            }
        }