protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // Switches to the UI thread in order to consume some services used in command initialization
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            _runningDocTableEvents             = new RunningDocTableEvents(this);
            _runningDocTableEvents.BeforeSave += DocumentSavedSync;
            _dte = await GetServiceAsync(typeof(DTE)) as DTE;

            Assumes.Present(_dte);
            if (_dte == null)
            {
                return;
            }

            _eventsHandlers = _dte.Events.DocumentEvents;

            _commandEventsHandlers = _dte.Events.CommandEvents;

            var outputWindow = (OutputWindow)_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object;

            _outputPane = outputWindow.OutputWindowPanes.Add("Bsod Survivor Output");

            // Add our command handlers for menu (commands must exist in the .vsct file)
            if (await GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService mcs)
            {
                {
                    CommandID   selectionsMenuCommandID = new CommandID(GuidList.guidBsodSurvivorPluginCmdSet, (int)PkgCmdIDList.cmdidLink);
                    MenuCommand selectionsMenuItem      = new MenuCommand(OnLinkRequested, selectionsMenuCommandID);
                    mcs.AddCommand(selectionsMenuItem);
                }

                {
                    CommandID   selectionsMenuCommandID = new CommandID(GuidList.guidBsodSurvivorPluginMultiItemProjectCmdSet, (int)PkgCmdIDList.cmdidLink1);
                    MenuCommand selectionsMenuItem      = new MenuCommand(OnLinkRequested, selectionsMenuCommandID);
                    mcs.AddCommand(selectionsMenuItem);
                }
            }

            bool isSucceededToAccessDocuments = false;

            for (int i = 0; i < 100; i++)
            {
                try
                {
                    var a = _dte.Documents.Count;
                    isSucceededToAccessDocuments = true;
                    break;
                }
                catch (Exception)
                {
                    //System.Threading.Thread.Sleep(0);
                }
            }
            if (!isSucceededToAccessDocuments)
            {
                throw new Exception("Failed to access ComObject dte.Documents.Count");
            }
        }
예제 #2
0
        public DocumentService(
            IVsRunningDocumentTable iVsRunningDocumentTable,
            RunningDocTableEvents runningDocTableEvents,
            VisualStudioWorkspace workspace)
        {
            _iVsRunningDocumentTable = iVsRunningDocumentTable;
            _workspace = workspace;

            runningDocTableEvents.AfterSaved += OnAfterSaved;
        }
        public MutationExplorerWindowViewModel(
            EnvironmentService environmentService,
            ConfigService configService,
            RunningDocTableEvents runningDocTableEvents,
            IMediator mediator)
        {
            Mutations = new ObservableCollection <MutationRunItem>();

            _mutationRunDocumentService = new MutationRunDocumentService(environmentService, Mutations);
            _environmentService         = environmentService;
            _configService     = configService;
            _mediator          = mediator;
            _filterItems       = new List <MutationDocumentFilterItem>();
            _selectedMutations = new List <MutationRunItem>();

            RunMutationsCommand      = new DelegateCommand(() => RunMutations(Mutations));
            MutationSelectedCommand  = new DelegateCommand <MutationRunItem>(UpdateSelectedMutation);
            MutationsSelectedCommand = new DelegateCommand <System.Collections.IList>((mutations) => _selectedMutations = mutations.Cast <MutationRunItem>());

            GoToMutationCommand = new DelegateCommand <MutationRunItem>(
                mutation => _environmentService.GoToLine(mutation.Document.FilePath, mutation.Document.MutationDetails.Location.GetLineNumber()));

            HighlightChangedCommand          = new DelegateCommand <bool>(HightlightChanged);
            ToggleMutation                   = new DelegateCommand(() => IsMutationVisible = !IsMutationVisible);
            ShowMutationDetailsCommand       = new DelegateCommand(ShowMutationDetails);
            RemoveKilledMutationsCommand     = new DelegateCommand(RemovedKilledMutations);
            RunOnlySurvivingMutationsCommand = new DelegateCommand(RunOnlySurvivingMutations);
            RefreshMutationsCommand          = new DelegateCommand(() => Initialize(_originalFilterItems));
            RunSelectedMutationsCommand      = new DelegateCommand(RunSelectedMutations);
            SaveReportCommand                = new DelegateCommand(SaveReport);

            StopCommand = new DelegateCommand(() =>
            {
                IsStopButtonEnabled = false;
                _tokenSource.Cancel();
            });

            runningDocTableEvents.BeforeSave += RunningDocTableEventsOnBeforeSave;

            environmentService.JoinableTaskFactory.Run(async() =>
            {
                await environmentService.JoinableTaskFactory.SwitchToMainThreadAsync();
                environmentService.Dte.Events.SolutionEvents.BeforeClosing += ResetWindow;
            });

            _showhighlight = true;
        }
예제 #4
0
        public SolutionWatcher(AsyncPackage package)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            dte       = Package.GetGlobalService(typeof(SDTE)) as DTE2;
            statusBar = package.GetServiceAsync(typeof(SVsStatusbar)).Result as IVsStatusbar;

            try
            {
                var solutionDir = Path.GetDirectoryName(dte.Solution.FileName);
                repo = new Repository(solutionDir);
                rdte = new RunningDocTableEvents(package,
                                                 OnAfterSaveAll: () =>
                {
                    ThreadHelper.ThrowIfNotOnUIThread();

                    if (repo?.GetEnabled() ?? false)
                    {
                        print("Saving Story...");
                        try
                        {
                            repo?.Store(repo.GetEnabled());
                        }
                        catch (Exception e)
                        {
                            var errorPane = dte.ToolWindows.OutputWindow.OutputWindowPanes.PaneByName("VSIX: Errors");

                            errorPane.OutputString(e.ToString());
                        }
                    }
                });
            }
            catch
            {
                Dispose(true);
            }
        }
예제 #5
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            IComponentModel       componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
            RunningDocTableEvents runningDocTableEventListener = new RunningDocTableEvents();

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            IVsRunningDocumentTable iVsRunningDocumentTable =
                (IVsRunningDocumentTable)GetGlobalService(typeof(SVsRunningDocumentTable));

            iVsRunningDocumentTable.AdviseRunningDocTableEvents(runningDocTableEventListener, out uint mRdtCookie);

            DocumentService documentService =
                new DocumentService(iVsRunningDocumentTable, runningDocTableEventListener, componentModel.GetService <VisualStudioWorkspace>());

            OutputWindowHelper.LogWriteLine("XAMLator initialized.");

            VisualStudioIDE visualStudioIDE = new VisualStudioIDE(documentService);

            XAMLatorMonitor.Init(visualStudioIDE);
            XAMLatorMonitor.Instance.StartMonitoring();

            OutputWindowHelper.LogWriteLine("XAMLator Start monitoring...");
        }