public void BuildCommandNameTest()
 {
     Assert.AreEqual(
         "Genetibase.Shared.Tests.NuGenExtensibilityTests+CommandHolderMock.Command",
         NuGenExtensibility.BuildCommandIdentifier(typeof(CommandHolderMock), "Command")
         );
 }
Esempio n. 2
0
        /*
         * OnConnection
         */

        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            if (addInInst == null)
            {
                throw new ArgumentNullException("addInInst");
            }

            if (application is DTE2)
            {
                _applicationObject = (DTE2)application;
            }
            else
            {
                throw new ArgumentException(Resources.Argument_InvalidApplicationType);
            }

            if (addInInst is AddIn)
            {
                _addInInstance = (AddIn)addInInst;
            }
            else
            {
                throw new ArgumentException(Resources.Argument_InvalidAddInInstanceType);
            }

            _taskListIdentifier = NuGenExtensibility.BuildCommandIdentifier(this.GetType(), Resources.Menu_TaskList_Identifier);

            Events applicationObjectEvents = _applicationObject.Events;

            Debug.Assert(applicationObjectEvents != null, "applicationObjectEvents != null");

            _solution = applicationObjectEvents.SolutionEvents;
            Debug.Assert(_solution != null, "_Solution != null");

            _solution.BeforeClosing += _Solution_BeforeClosing;
            _solution.Opened        += _Solution_Opened;

            switch (connectMode)
            {
            case ext_ConnectMode.ext_cm_UISetup:
            {
                try
                {
                    NuGenExtensibility.RemoveAddInCommands(this.GetType(), _applicationObject);
                }
                catch (Exception e)
                {
                    if (_ErrorEnabled)
                    {
                        Trace.WriteLine("Error occured while removing add-in commands: " + e.Message);
                    }
                }

                try
                {
                    NuGenExtensibility.CreateAddInCommand(
                        _applicationObject,
                        _addInInstance,
                        Resources.Menu_TaskList_Identifier,
                        Resources.Menu_TaskList_Name,
                        Resources.Menu_TaskList_Description,
                        439
                        );
                }
                catch (Exception e)
                {
                    if (_ErrorEnabled)
                    {
                        Trace.WriteLine("Error occured while creating add-in commands: " + e.Message);
                    }
                }

                break;
            }

            case ext_ConnectMode.ext_cm_AfterStartup:
            case ext_ConnectMode.ext_cm_Startup:
            {
                CommandBar menuBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"];
                Debug.Assert(menuBar != null, "menuBar != null");

                CommandBarPopup menuPopup = (CommandBarPopup)menuBar.Controls[this.GetFullMenuName(Resources.Menu_ParentMenu_Name)];
                Debug.Assert(menuPopup != null, "menuPopup != null");

                CommandBar menuCommandBar = menuPopup.CommandBar;
                Debug.Assert(menuCommandBar != null, "menuCommandBar != null");

                Command taskListCommand = null;

                try
                {
                    taskListCommand = _applicationObject.Commands.Item(_taskListIdentifier, -1);
                }
                catch (ArgumentException)
                {
                    NuGenExtensibility.RemoveAddInCommands(this.GetType(), _applicationObject);
                    taskListCommand = NuGenExtensibility.CreateAddInCommand(
                        _applicationObject,
                        _addInInstance,
                        Resources.Menu_TaskList_Identifier,
                        Resources.Menu_TaskList_Name,
                        Resources.Menu_TaskList_Description,
                        439
                        );
                }

                Debug.Assert(taskListCommand != null, "taskListCommand != null");

                try
                {
                    _taskListMenuItem = NuGenExtensibility.CreateAddInMenu(
                        taskListCommand,
                        menuCommandBar,
                        1
                        );
                }
                catch (Exception e)
                {
                    Trace.WriteLineIf(
                        _ErrorEnabled,
                        "Error occured while creating menu item.: " + e.Message
                        );
                }

                try
                {
                    _addInUI = this.CreateToolWindow(
                        _addInInstance,
                        typeof(NuGenTaskListUI),
                        Resources.ToolWindow_Caption
                        );
                }
                catch (Exception e)
                {
                    Trace.WriteLineIf(
                        _ErrorEnabled,
                        "Error occured while creating tool window: " + e.Message
                        );
                }

                break;
            }
            }
        }
 public void BuildCommandNameArgumentNullExceptionTest()
 {
     NuGenExtensibility.BuildCommandIdentifier(null, "");
 }