Ejemplo n.º 1
0
        /// <inheritdoc />
        /// <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();

            _dte = (DTE)GetService(typeof(SDTE));

            _dteEvents = _dte.Events.DTEEvents;

            _dteEvents.OnStartupComplete += _dteEvents_OnStartupComplete;

            BridgeVsExtension bridge      = new BridgeVsExtension(_dte);
            bool isLinqBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_dte.Version);

            // Add our command handlers for menu(commands must exist in the.vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null == mcs)
            {
                return;
            }

            // Create the command for the menu item.
            CommandID      enableCommand  = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdEnableBridge);
            OleMenuCommand menuItemEnable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Enable), enableCommand);

            menuItemEnable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemEnable, CommandAction.Enable);

            CommandID disableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet,
                                                     (int)PkgCmdIdList.CmdIdDisableBridge);
            OleMenuCommand menuItemDisable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Disable), disableCommand);

            menuItemDisable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemDisable, CommandAction.Disable);

            CommandID      gettingStarted         = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdGettingStarted);
            OleMenuCommand menuItemGettingStarted = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs#getting-started"), gettingStarted);

            CommandID      sendFeedback         = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdFeedback);
            OleMenuCommand menuItemSendFeedback = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs/issues"), sendFeedback);

            mcs.AddCommand(menuItemEnable);
            mcs.AddCommand(menuItemDisable);
            mcs.AddCommand(menuItemGettingStarted);
            mcs.AddCommand(menuItemSendFeedback);
            //Initialize Object Exporter settings
            _packageSettings = (PackageSettings)GetDialogPage(typeof(PackageSettings));

            try
            {   //if first time user
                if (isLinqBridgeVsConfigured)
                {
                    return;
                }

                if (!IsElevated)
                {
                    // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                    if (Application.ResourceAssembly == null)
                    {
                        // ReSharper disable once HeuristicUnreachableCode
                        Application.ResourceAssembly = typeof(Welcome).Assembly;
                    }

                    _welcomePage = new Welcome(_dte);
                }
                else
                {
                    _installationResult = PackageConfigurator.Install(_dte.Version, _dte.Edition);
                }
            }
            catch (Exception e)
            {
                _error       = new Error();
                _error.Body  = $"{e.Message} %0A {e.StackTrace}";
                _error.Title = "Error during installation. 1.4.6";
                Exception innerException = e.InnerException;
                while (innerException != null)
                {
                    _error.Body   += $"%0A {innerException.Message} {innerException.StackTrace}";
                    innerException = innerException.InnerException;
                }
                _error.Body = _error.Body.Replace(Environment.NewLine, "%0A");
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <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();

            _dte = (DTE)GetService(typeof(SDTE));

            _dteEvents = _dte.Events.DTEEvents;

            _dteEvents.OnStartupComplete += _dteEvents_OnStartupComplete;

            BridgeVsExtension bridge      = new BridgeVsExtension(_dte);
            bool isLinqBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_dte.Version);

            // Add our command handlers for menu(commands must exist in the.vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null == mcs)
            {
                return;
            }

            // Create the command for the menu item.
            CommandID      enableCommand  = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdEnableBridge);
            OleMenuCommand menuItemEnable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Enable), enableCommand);

            menuItemEnable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemEnable, CommandAction.Enable);

            CommandID disableCommand = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet,
                                                     (int)PkgCmdIdList.CmdIdDisableBridge);
            OleMenuCommand menuItemDisable = new OleMenuCommand((s, e) => bridge.Execute(CommandAction.Disable), disableCommand);

            menuItemDisable.BeforeQueryStatus += (s, e) => bridge.UpdateCommand(menuItemDisable, CommandAction.Disable);

            CommandID      gettingStarted         = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdGettingStarted);
            OleMenuCommand menuItemGettingStarted = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs#getting-started"), gettingStarted);

            CommandID      sendFeedback         = new CommandID(GuidList.GuidBridgeVsExtensionCmdSet, (int)PkgCmdIdList.CmdIdFeedback);
            OleMenuCommand menuItemSendFeedback = new OleMenuCommand((s, e) => System.Diagnostics.Process.Start("https://github.com/codingadventures/LINQBridgeVs/issues"), sendFeedback);

            mcs.AddCommand(menuItemEnable);
            mcs.AddCommand(menuItemDisable);
            mcs.AddCommand(menuItemGettingStarted);
            mcs.AddCommand(menuItemSendFeedback);

            try
            {
                Log.Configure("LINQBridgeVs", "Extensions");

                //if first time user
                if (isLinqBridgeVsConfigured)
                {
                    return;
                }

                if (!IsElevated)
                {
                    // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                    if (Application.ResourceAssembly == null)
                    {
                        // ReSharper disable once HeuristicUnreachableCode
                        Application.ResourceAssembly = typeof(Welcome).Assembly;
                    }

                    _welcomePage = new Welcome(_dte);
                }
                else
                {
                    _installationResult = PackageConfigurator.Install(_dte.Version, _dte.Edition);
                }
            }
            catch (Exception e)
            {
                Log.Write(e, "Initialize Error...");
                MessageBox.Show("LINQBridgeVs wasn't successfully configured. Please restart Visual Studio");
            }
        }