示例#1
0
        private void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            var myCommand = sender as OleMenuCommand;

            if (null != myCommand)
            {
                UIHierarchy     uih           = Dte2.ToolWindows.SolutionExplorer;
                Array           selectedItems = (Array)uih.SelectedItems;
                UIHierarchyItem selectedItem  = selectedItems.GetValue(0) as UIHierarchyItem;
                Solution        sol           = selectedItem.Object as Solution;
                if (sol != null && RunTestsMenu.HasTestProjects(sol))
                {
                    myCommand.Visible = true;
                    return;
                }
                Project prj = selectedItem.Object as Project;
                if (prj == null || !RunTestsMenu.IsTestProject(prj))
                {
                    myCommand.Visible = false;
                    return;
                }

                myCommand.Visible = true;
            }
        }
示例#2
0
        private static void MenuItemCallback(object sender, EventArgs e)
        {
            RunTestsMenuCommand command      = (RunTestsMenuCommand)sender;
            UIHierarchy         uih          = command.Dte2.ToolWindows.SolutionExplorer;
            Array           selectedItems    = (Array)uih.SelectedItems;
            UIHierarchyItem selectedItem     = selectedItems.GetValue(0) as UIHierarchyItem;
            Solution        solution         = command.Dte2.Solution;
            Solution        selectedSolution = selectedItem.Object as Solution;

            if (LaunchCommand.Instance.Launcher.BuildBeforeLaunch)
            {
                solution.SolutionBuild.Build(true);
            }

            if (selectedSolution != null)
            {
                //System.Diagnostics.Debug.WriteLine("RunTestsMenuCommand.MenuItemCallback() running all test projects for the solution");
                foreach (Project p in selectedSolution.Projects)
                {
                    if (RunTestsMenu.IsTestProject(p))
                    {
                        RunTestProject(p, solution);
                    }
                }
                return;
            }
            Project project = selectedItem.Object as Project;

            if (project != null)
            {
                //System.Diagnostics.Debug.WriteLine("RunTestsMenuCommand.MenuItemCallback() running a single test project");
                RunTestProject(project, solution);
            }
        }
示例#3
0
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(Package package)
 {
     Instance = new RunTestsMenu(package);
 }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            DTE2 dte = (DTE2)FirstPackage.GetGlobalService(typeof(DTE));

            if (context == null)
            {
                context = new DynaTrace.CodeLink.Context(dte);
            }

            context.log("onConnection - Initialize");

            context.log(DynaTrace.CodeLink.Context.LOG_INFO + "CodeLink Version: " + context.VersionString);

            //from MS-Code only UISetup is necessary, but we need Startup because we have troubles with VS05 (show the menu item)
            // if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup) {

            if (!_bConnected)
            {
                object[] contextGUIDS = new object[] { };

                string toolsMenuName;
                // if ((!found && connectMode == ext_ConnectMode.ext_cm_Startup) || (connectMode == ext_ConnectMode.ext_cm_UISetup)) {
                bool found = false;
                if (!found)
                {
                    try
                    {
                        ResourceManager resourceManager = new ResourceManager("DynaTrace.CodeLink.CommandBar", Assembly.GetExecutingAssembly());
                        CultureInfo     cultureInfo     = new System.Globalization.CultureInfo(dte.LocaleID);
                        string          resourceName    = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                        toolsMenuName = resourceManager.GetString(resourceName);
                    }
                    catch
                    {
                        //We tried to find a localized version of the word Tools, but one was not found.
                        //  Default to the en-US word, which may work for the current culture.
                        toolsMenuName = "Tools";
                    }

                    // Place the command on the tools menu.
                    // Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
                    Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar =
                        ((Microsoft.VisualStudio.CommandBars.CommandBars)dte.CommandBars)["MenuBar"];

                    // Find the Tools command bar on the MenuBar command bar:
                    CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                    CommandBarPopup   toolsPopup   = (CommandBarPopup)toolsControl;

                    //// Create the menu entry for dynaTrace Configuration Dialog
                    //try
                    //{
                    //    try
                    //    {
                    //        _commandSetup = (Command)commands.Item(COMMAND_NAME + ".Setup", 0);
                    //    }
                    //    catch (Exception) { /* context.log("INFO " + e.ToString()); */}

                    //    if (_commandSetup == null)
                    //        _commandSetup = commands.AddNamedCommand2(_addInInstance, "Setup", "dynaTrace Configuration",
                    //            "Opens the configuration dialog for CodeLink & Launcher", false, 1,
                    //            ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    //            (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    //    else
                    //        _commandSetup = null;
                    //}
                    //catch (Exception e)
                    //{
                    //    //If we are here, then the exception is probably because a command with that name
                    //    //  already exists. If so there is no need to recreate the command and we can
                    //    //  safely ignore the exception.
                    //    context.log(Context.LOG_ERROR + e.ToString());
                    //}

                    //// Create the menu entry for the dynaTrace Launcher
                    //try
                    //{
                    //    try
                    //    {
                    //        _commandLauncher = (Command)commands.Item(COMMAND_NAME + ".dynaTraceLauncher", 0);
                    //    }
                    //    catch (System.Exception) { /* context.log("INFO " + e.ToString()); */}

                    //    //Add a command to the Commands collection:
                    //    if (_commandLauncher == null)
                    //        _commandLauncher = commands.AddNamedCommand2(_addInInstance, "dynaTraceLauncher", "dynaTrace Launcher", "Launches the startup project with dynaTrace Support", false, 1 /*59*/, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    //    else
                    //        _commandLauncher = null; // already there - therefore dont add it again to the tools menu
                    //}
                    //catch (System.Exception e)
                    //{
                    //    context.log(Context.LOG_ERROR + e.ToString());
                    //}

                    ////Add to tools menu
                    //if (toolsPopup != null)
                    //{
                    //    try
                    //    {
                    //        if (_commandSetup != null)
                    //            _commandSetup.AddControl(toolsPopup.CommandBar, 1);
                    //        if (_commandLauncher != null)
                    //            _commandLauncher.AddControl(toolsPopup.CommandBar, 1);
                    //    }
                    //    catch (Exception e)
                    //    {
                    //        context.log(Context.LOG_ERROR + e.ToString());
                    //    }
                    //}
                }
                _bConnected = true;
            }

            // create the launcher implementation class
//            if (_launcher == null)
//            {
//                _launcher = new dynaTraceLauncher.LauncherConnect(_applicationObject, _addInInstance);
//                _launcher.Context = context;
//            }
//            // In VS2010 also create the WebTestPlugin
//#if (VS_2010)
//            try
//            {
//                dynaTrace.VSTS.WebResultAddin.WebTestConnect webTestConnect = new dynaTrace.VSTS.WebResultAddin.WebTestConnect();
//                webTestConnect.OnConnection(application, connectMode, addInInst, ref custom);
//            }
//            catch (Exception e) {context.log(Context.LOG_ERROR + e.ToString());}
//#endifs

            if (context.Config.PluginEnabled)
            {
                context.connect();
            }

            LaunchCommand.Initialize(this);
            LaunchCommand.Instance.Launcher = new Launcher(dte, context);
            ConfigCommand.Initialize(this);
            ConfigCommand.Instance.Context  = context;
            ConfigCommand.Instance.Launcher = LaunchCommand.Instance.Launcher;
            RunTestsMenu.Initialize(this);
        }