<commit_before>﻿// Visual Studio Shared Project
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN  *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Automation;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
using Task = System.Threading.Tasks.Task;

namespace TestUtilities.UI {
    /// <summary>
    /// Provides wrappers for automating the VisualStudio UI.
    /// </summary>
    public class VisualStudioApp : AutomationWrapper, IDisposable {
        private SolutionExplorerTree _solutionExplorerTreeView;
        private ObjectBrowser _objectBrowser, _resourceView;
        private IntPtr _mainWindowHandle;
        private readonly DTE _dte;
        private List<Action> _onDispose;
        private bool _isDisposed, _skipCloseAll;

        public VisualStudioApp(IServiceProvider site)
            : this(new IntPtr(GetDTE(site).MainWindow.HWnd)) {
            // TODO: Make site non-optional
            ServiceProvider = site ?? Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider;
            _dte = GetDTE(site);

            foreach (var p in ((DTE2)_dte).ToolWindows.OutputWindow.OutputWindowPanes.OfType<OutputWindowPane>()) {
                p.Clear();
            }

            var uiShell = GetService<IVsUIShell>(typeof(IVsUIShell));
            IntPtr hwnd;
            ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out hwnd));
            if (hwnd != _mainWindowHandle) {
                using (var dlg = new AutomationDialog(this, AutomationElement.FromHandle(hwnd))) {
                    Console.WriteLine("Unexpected dialog at start of test");
                    DumpElement(dlg.Element);
                    dlg.WaitForClosed(TimeSpan.FromSeconds(5), dlg.CloseWindow);
                }
            }
        }

        private VisualStudioApp(IntPtr windowHandle)
            : base(AutomationElement.FromHandle(windowHandle)) {
            _mainWindowHandle = windowHandle;
        }

        private static DTE GetDTE(IServiceProvider site) {
            if (site == null) {
                Console.WriteLine("WARNING: Assuming global service provider");
                site = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider;
            }
            return (DTE)site.GetService(typeof(DTE));
        }

        public bool IsDisposed {
            get { return _isDisposed; }
        }

        public void OnDispose(Action action) {
            Debug.Assert(action != null);<commit_msg>click 'Continue without code' button to skip startup window (#5342)<commit_after>﻿// Visual Studio Shared Project
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN  *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Automation;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
using Task = System.Threading.Tasks.Task;

namespace TestUtilities.UI {
    /// <summary>
    /// Provides wrappers for automating the VisualStudio UI.
    /// </summary>
    public class VisualStudioApp : AutomationWrapper, IDisposable {
        private SolutionExplorerTree _solutionExplorerTreeView;
        private ObjectBrowser _objectBrowser, _resourceView;
        private IntPtr _mainWindowHandle;
        private readonly DTE _dte;
        private List<Action> _onDispose;
        private bool _isDisposed, _skipCloseAll;

        public VisualStudioApp(IServiceProvider site)
            : this(new IntPtr(GetDTE(site).MainWindow.HWnd)) {
            // TODO: Make site non-optional
            ServiceProvider = site ?? Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider;
            _dte = GetDTE(site);

            foreach (var p in ((DTE2)_dte).ToolWindows.OutputWindow.OutputWindowPanes.OfType<OutputWindowPane>()) {
                p.Clear();
            }

            var uiShell = GetService<IVsUIShell>(typeof(IVsUIShell));
            IntPtr hwnd;
            ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out hwnd));
            if (hwnd != _mainWindowHandle) {
                using (var dlg = new AutomationDialog(this, AutomationElement.FromHandle(hwnd))) {
                    //startup window popup, press button "Continue without code"
                    var cwc = dlg.FindByName("Continue without code");
                    if (cwc != null)
                    {
                        Invoke(cwc);
                        WaitForInputIdle();
                        return;
                    }
                    Console.WriteLine("Unexpected dialog at start of test");
                    DumpElement(dlg.Element);
                    dlg.WaitForClosed(TimeSpan.FromSeconds(5), dlg.CloseWindow);
                }
            }
        }

        private VisualStudioApp(IntPtr windowHandle)
            : base(AutomationElement.FromHandle(windowHandle)) {
            _mainWindowHandle = windowHandle;
        }

        private static DTE GetDTE(IServiceProvider site) {
            if (site == null) {
                Console.WriteLine("WARNING: Assuming global service provider");
                site = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider;
            }
            return (DTE)site.GetService(typeof(DTE));
        }

        public bool IsDisposed {
            get { return _isDisposed; }
        }

        public void OnDispose(Action action) {
            Debug.Assert(action != null);
{'fraction_non_alphanumeric': 0.08441896821261073, 'fraction_numerical': 0.003126628452318916, 'mean_word_length': 2.697976878612717, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '970238', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1943, 'n_words': 541}