/// <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 async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            _dte = await GetServiceAsync <DTE>();

            var serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte);
            var dialogService   = new VisualStudioDialogService(serviceProvider);
            var commandService  = await GetServiceAsync <IMenuCommandService>();

            var projectService  = new VcProjectService();
            var settingsService = new VisualStudioSettingsService(this);

            _solution = await GetServiceAsync <SVsSolution>() as IVsSolution;

            _solutionEventsHandler = new SolutionEventsHandler(this);
            _solution.AdviseSolutionEvents(_solutionEventsHandler, out var _solutionEventsCookie);

            _addConanDepends             = new AddConanDepends(commandService, dialogService, projectService, settingsService);
            _showPackageListCommand      = new ShowPackageListCommand(this, commandService, dialogService);
            _integrateIntoProjectCommand = new IntegrateIntoProjectCommand(commandService, dialogService, projectService);

            Logger.Initialize(serviceProvider, "Conan");

            SubscribeToEvents();
        }
 protected override void Dispose(bool disposing)
 {
     if (_solutionEventsCookie != 0)
     {
         VsSolution.UnadviseSolutionEvents(_solutionEventsCookie);
         _solutionEventsCookie = 0;
     }
     _solutionEventsHandler = null;
     base.Dispose(disposing);
 }
    private void ListeToSolutionEvents() {
      var vsSolution2 = GetVsSolution();
      if (vsSolution2 == null)
        return;

      var handler = new SolutionEventsHandler(this);
      uint cookie;
      var hr = vsSolution2.AdviseSolutionEvents(handler, out cookie);
      if (ErrorHandler.Succeeded(hr)) {
        _visualStudioPackageProvider.Package.DisposeContainer.Add(
          () => vsSolution2.UnadviseSolutionEvents(cookie));
      }
    }
Exemple #4
0
        /// <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 async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            _dte = await GetServiceAsync <DTE>();

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            _solution = await GetServiceAsync <SVsSolution>() as IVsSolution;

            _solutionBuildManager = await GetServiceAsync <IVsSolutionBuildManager>() as IVsSolutionBuildManager3;

            var serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte);

            await TaskScheduler.Default;

            var commandService = await GetServiceAsync <IMenuCommandService>();

            _vcProjectService = new VcProjectService();
            _settingsService  = new VisualStudioSettingsService(this);
            _errorListService = new ErrorListService();
            _conanService     = new ConanService(_settingsService, _errorListService, _vcProjectService);

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            _solutionEventsHandler = new SolutionEventsHandler(this);
            _solution.AdviseSolutionEvents(_solutionEventsHandler, out var _solutionEventsCookie);

            _addConanDependsProject   = new AddConanDependsProject(commandService, _errorListService, _vcProjectService, _conanService);
            _addConanDependsSolution  = new AddConanDependsSolution(commandService, _errorListService, _vcProjectService, _conanService);
            _addConanDependsConanfile = new AddConanDependsConanfile(commandService, _errorListService, _vcProjectService, _conanService);

            _conanOptions = new ConanOptions(commandService, _errorListService, ShowOptionPage);

            await TaskScheduler.Default;

            Logger.Initialize(serviceProvider, "Conan");

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            SubscribeToEvents();

            EnableMenus(_dte.Solution != null && _dte.Solution.IsOpen);

            await TaskScheduler.Default;
        }
        private void ListenToSolutionEvents()
        {
            var vsSolution2 = GetVsSolution();

            if (vsSolution2 == null)
            {
                return;
            }

            var  handler = new SolutionEventsHandler(this);
            uint cookie;
            var  hr = vsSolution2.AdviseSolutionEvents(handler, out cookie);

            if (ErrorHandler.Succeeded(hr))
            {
                _visualStudioPackageProvider.Package.DisposeContainer.Add(
                    () => vsSolution2.UnadviseSolutionEvents(cookie));
            }
        }
        /// <summary>
        /// Initialize all Visual Studio Objects
        /// </summary>
        public void InitializeVsObjects()
        {
            Dte        = GetService(typeof(SDTE)) as DTE;
            Dte2       = GetService(typeof(SDTE)) as DTE2;
            VsSolution = GetService(typeof(SVsSolution)) as IVsSolution;

            if (Dte2 == null || Dte == null || VsSolution == null)
            {
                VsShell = GetService(typeof(SVsShell)) as IVsShell;
                _shellPropertyEventsHandler = new ShellPropertyEventsHandler(VsShell, InitializeVsObjects);
            }
            else
            {
                _shellPropertyEventsHandler = null;

                ToolWindowPane window = FindToolWindow(typeof(NAntRunnerToolWindow), 0, true);
                _solutionEventsHandler = new SolutionEventsHandler(window.Content as NAntRunnerToolWindowControl);
                VsSolution.AdviseSolutionEvents(_solutionEventsHandler, out _solutionEventsCookie);
            }
        }
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            NLogConfigurationService.ConfigureNLog();
            NLogConfigurationService.ConfigureMiniProfilerWithDefaultLogger();

            Logger logger = LogManager.GetLogger("error");

            logger.Info("Extension initalizing");

            EnvDTE = await GetServiceAsync(typeof(DTE)) as DTE2;

            Assumes.Present(EnvDTE);

            DteSemaphore.Release();

            Storage = new PackageStorage();

            var componentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

            Assumes.Present(componentModel);

            //Initialize public components, initialize instances that are dependent on any component
            TextManager = await GetServiceAsync(typeof(SVsTextManager)) as IVsTextManager;

            EditorAdaptersFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();

            DocumentNavigationInstance.InjectDTE(EnvDTE);
            //Prepare package events
            var indexingQueue   = new ProjectIndexingQueue();
            var workspaceEvents = new WorkspaceEvents(indexingQueue);

            Workspace = componentModel.GetService <VisualStudioWorkspace>();
            Workspace.WorkspaceChanged += (s, e) => ThreadHelper.JoinableTaskFactory.RunAsync(async() => await workspaceEvents.WorkspaceChangedAsync(s, e));

            var indexingWorkflow = new IndexingWorkflow(Storage.IndexingWorkflowOptions, new ProjectItemRetreiver(EnvDTE), Storage);

            _envDteEvents = EnvDTE.Events as Events2;
            if (_envDteEvents != null)
            {
                ProjectItemEventsActions projectItemEvents = new ProjectItemEventsActions();
                _envDteProjectItemsEvents              = _envDteEvents.ProjectItemsEvents;
                _envDteProjectItemsEvents.ItemAdded   += projectItemEvents.ItemAdded;
                _envDteProjectItemsEvents.ItemRemoved += projectItemEvents.ItemRemoved;
                _envDteProjectItemsEvents.ItemRenamed += projectItemEvents.ItemRenamed;

                EventHandlers.BuildEventsActions buildEvents = new EventHandlers.BuildEventsActions();
                _buildEvents = _envDteEvents.BuildEvents;
                _buildEvents.OnBuildBegin += buildEvents.OnBuildBegin;
            }

            var solutionEventsActions = new VSSolutionEventsActions(indexingWorkflow);

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            await ResultWindowCommand.InitializeAsync(this);

            OutputWindowLogger.Init(await GetServiceAsync(typeof(SVsOutputWindow)) as SVsOutputWindow);
            IStatusBar = await GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar;

            var svsSolution = await GetServiceAsync(typeof(SVsSolution));

            Solution = svsSolution as IVsSolution;
            Assumes.Present(Solution);

            await HandleSolutionAsync(svsSolution, solutionEventsActions, indexingQueue);


            _solutionEventsHandler = new SolutionEventsHandler(solutionEventsActions);
            Solution.AdviseSolutionEvents(_solutionEventsHandler, out _solutionEventsCookie);

            await Goto.InitializeAsync(this);

            await RenameModalWindowCommand.InitializeAsync(this);

            await RenameCommand.InitializeAsync(this);

            await PrettyPrintCommand.InitializeAsync(this);
        }