public void OnFrameDestroyed(IVsWindowFrame frame)
 {
     if (_frame.Equals(frame))
     {
         _threadingService.ExecuteSynchronously(_editorModel.CloseCurrentEditorAsync);
     }
 }
        public CodeModel?GetCodeModel(Project project)
        {
            Requires.NotNull(project, nameof(project));

            return(_threadingService.ExecuteSynchronously(() =>
            {
                return GetCodeModelAsync(project);
            }));
        }
        public void Wait(string title, string message, bool allowCancel, Action <CancellationToken> action)
        {
            Requires.NotNull(title, nameof(title));
            Requires.NotNull(message, nameof(message));
            Requires.NotNull(action, nameof(action));

            Instance instance = _threadingService.ExecuteSynchronously(() => WaitForLoadedAsync());

            instance.Wait(title, message, allowCancel, action);
        }
 public void OnComplete(int hr, uint debugTargetCount, VsDebugTargetProcessInfo[] processInfoArray)
 {
     if (_targetsProvider is IDebugProfileLaunchTargetsProvider4 targetsProvider4)
     {
         _threadingService.ExecuteSynchronously(() => targetsProvider4.OnAfterLaunchAsync(_launchOptions, _activeProfile, processInfoArray));
     }
     else if (_targetsProvider is not null)
     {
         _threadingService.ExecuteSynchronously(() => _targetsProvider.OnAfterLaunchAsync(_launchOptions, _activeProfile));
     }
 }
 private void TextDocument_FileActionOccurred(object sender, TextDocumentFileActionEventArgs args)
 {
     if (args.FileActionType == FileActionTypes.ContentSavedToDisk)
     {
         _threadingService.ExecuteSynchronously(_editorState.SaveProjectFileAsync);
     }
 }
        public static void SetCpsProjectArguments(EnvDTE.Project project, string arguments)
        {
            IUnconfiguredProjectServices unconfiguredProjectServices;
            IProjectServices             projectServices;

            if (TryGetProjectServices(project, out unconfiguredProjectServices, out projectServices))
            {
                var launchSettingsProvider = unconfiguredProjectServices.ExportProvider.GetExportedValue <ILaunchSettingsProvider>();
                var activeLaunchProfile    = launchSettingsProvider?.ActiveProfile;

                if (activeLaunchProfile == null)
                {
                    return;
                }

                WritableLaunchProfile writableLaunchProfile = new WritableLaunchProfile(activeLaunchProfile);
                writableLaunchProfile.CommandLineArgs = arguments;

                // Does not work on VS2015, which should be okay ...
                // We don't hold references for VS2015, where the interface is called IThreadHandling
                IProjectThreadingService projectThreadingService = projectServices.ThreadingPolicy;
                projectThreadingService.ExecuteSynchronously(() =>
                {
                    return(launchSettingsProvider.AddOrUpdateProfileAsync(writableLaunchProfile, addToFront: false));
                });
            }
        }
 public void OnComplete(int hr, uint debugTargetCount, VsDebugTargetProcessInfo[] processInfoArray)
 {
     if (_targetProfile != null)
     {
         _threadingService.ExecuteSynchronously(() => _targetProfile.OnAfterLaunchAsync(_launchOptions, _activeProfile));
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Completing the output block before the action block means any final messages that are currently being produced
                // will not be sent out, which is what we want in this case.
                _broadcastBlock?.Complete();
                _dataSourceLink?.Dispose();

                if (_actionBlock != null)
                {
                    _actionBlock.Complete();

                    _threadingService.ExecuteSynchronously(async() =>
                    {
                        // Wait for any processing to finish so we don't fight over the cookies 🍪
                        await _actionBlock.Completion;

                        IVsAsyncFileChangeEx vsAsyncFileChangeEx = await _fileChangeService.GetValueAsync();

                        // Unsubscribe from all files
                        foreach (uint cookie in _fileWatcherCookies.Values)
                        {
                            await vsAsyncFileChangeEx.UnadviseFileChangeAsync(cookie);
                        }
                    });
                }
            }

            base.Dispose(disposing);
        }
Esempio n. 9
0
        /// <summary>
        /// Called when one of the project files changes. In our case since only one file is watched with each cookie so the list of files
        /// should be one.
        /// </summary>
        public int FilesChanged(uint cChanges, string[] rgpszFile, uint[] grfChange)
        {
            if (cChanges == 1 && (grfChange[0] & (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Time)) != 0)
            {
                IReloadableProject changedProject = null;
                lock (_registeredProjects)
                {
                    changedProject = _registeredProjects.FirstOrDefault(kv => kv.Key.ProjectFile.Equals(rgpszFile[0], StringComparison.OrdinalIgnoreCase)).Key;
                }

                if (changedProject != null)
                {
                    lock (_changedProjects)
                    {
                        if (!_changedProjects.Contains(changedProject))
                        {
                            _changedProjects.Add(changedProject);
                        }

                        ReloadDelayScheduler.ScheduleAsyncTask(async(ct) =>
                        {
                            // Grab the UI thread so that we block until the reload of this set of
                            // projects completes.
                            await _threadHandling.SwitchToUIThread();

                            if (ct.IsCancellationRequested)
                            {
                                return;
                            }

                            // Get the list of projects and create a new empty list to put new requests
                            List <IReloadableProject> changedProjects;
                            lock (_changedProjects)
                            {
                                changedProjects  = _changedProjects;
                                _changedProjects = new List <IReloadableProject>();
                            }

                            var failedProjects = new List <Tuple <IReloadableProject, ProjectReloadResult> >();
                            _threadHandling.ExecuteSynchronously(async() =>
                            {
                                foreach (var project in changedProjects)
                                {
                                    ProjectReloadResult result = await project.ReloadProjectAsync().ConfigureAwait(true);

                                    if (result == ProjectReloadResult.ReloadFailed || result == ProjectReloadResult.ReloadFailedProjectDirty)
                                    {
                                        failedProjects.Add(new Tuple <IReloadableProject, ProjectReloadResult>(project, result));
                                    }
                                }
                            });

                            ProcessProjectReloadFailures(failedProjects);
                        });
                    }
                }
            }
            return(VSConstants.S_OK);
        }
Esempio n. 10
0
        public CodeModel GetCodeModel(Project project)
        {
            Requires.NotNull(project, nameof(project));

            IWorkspaceProjectContext projectContext = _languageServiceHost.ActiveProjectContext;

            if (projectContext == null)
            {
                return(null);
            }

            return(_threadingService.ExecuteSynchronously(async() =>
            {
                await _threadingService.SwitchToUIThread();

                return _codeModelFactory.GetCodeModel(projectContext, project);
            }));
        }
 private static ProjectId?GetProjectId(IProjectThreadingService threadingService, IActiveWorkspaceProjectContextHost projectContextHost)
 {
     return(threadingService.ExecuteSynchronously(() =>
     {
         return projectContextHost.OpenContextForWriteAsync(accessor =>
         {
             return Task.FromResult(accessor.Context.Id);
         });
     }));
 }
Esempio n. 12
0
        public void Add(string bstrImport)
        {
            if (!_importsList.IsPresent(bstrImport))
            {
                _threadingService.ExecuteSynchronously(async() =>
                {
                    await _projectAccessor.OpenProjectXmlForWriteAsync(_unconfiguredProjectVSServices.Project, project =>
                    {
                        project.AddItem(ImportItemTypeName, bstrImport);
                    });

                    await _importsList.ReceiveLatestSnapshotAsync();
                });
            }
            else
            {
                throw new ArgumentException(string.Format("{0} - Namespace is already imported", bstrImport), nameof(bstrImport));
            }
        }
 public void Dispose()
 {
     if (_shouldClose)
     {
         _threadingService.ExecuteSynchronously(async() =>
         {
             DTE dte = await _dte.GetValueAsync();
             dte.UndoContext.Close();
         });
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Builds a temporary portable executable (PE) and returns its description in an XML string.
        /// </summary>
        public string BuildDesignTimeOutput(string bstrOutputMoniker)
        {
            if (DesignTimeInputsBuildManagerBridge?.AppliesTo(_unconfiguredProjectServices.Project.Capabilities) == true)
            {
                IDesignTimeInputsBuildManagerBridge bridge = DesignTimeInputsBuildManagerBridge.Value;

                // See comment above about why we don't need any thread switching here.
                return(_threadingService.ExecuteSynchronously(() => bridge.GetDesignTimeInputXmlAsync(bstrOutputMoniker)));
            }

            throw new NotImplementedException();
        }
Esempio n. 15
0
        private int Invoke(Func <IVsENCRebuildableProjectCfg2, HResult> action)
        {
            return(_threadingService.ExecuteSynchronously(async() =>
            {
                await _threadingService.SwitchToUIThread();

                return await _projectContextHost.OpenContextForWriteAsync(accessor =>
                {
                    return Task.FromResult(action((IVsENCRebuildableProjectCfg2)accessor.HostSpecificEditAndContinueService));
                });
            }));
        }
Esempio n. 16
0
        public IsoPublishProvider(
            IBuildSupport buildSupport,
            IBuildProject buildProject,
            IProjectThreadingService projectThreadingService,
            IBootableProperties bootableProperties)
            : base(buildSupport, buildProject)
        {
            _viewModel             = new IsoPublishSettingsViewModel();
            _viewModel.PublishPath = projectThreadingService.ExecuteSynchronously(bootableProperties.GetIsoFileFullPathAsync);

            _settingsControl             = new IsoPublishSettingsControl();
            _settingsControl.DataContext = _viewModel;
        }
Esempio n. 17
0
        private int Invoke(Func <IVsENCRebuildableProjectCfg2, HResult> action)
        {
            return(_threadingService.ExecuteSynchronously(async() =>
            {
                await _threadingService.SwitchToUIThread();

                var encProvider = (IVsENCRebuildableProjectCfg2)_host?.HostSpecificEditAndContinueService;
                if (encProvider != null)
                {
                    return action(encProvider);
                }

                return HResult.Unexpected;
            }));
        }
        public void Dispose()
        {
            // Build manager APIs require UI thread access.
            _threadingService.ExecuteSynchronously(async() =>
            {
                await _threadingService.SwitchToUIThread();

                if (_buildManager != null)
                {
                    // Unregister solution build events.
                    _buildManager.UnadviseUpdateSolutionEvents(_solutionEventsCookie);
                    _buildManager = null;
                }
            });
        }
 private string GetWorkspaceContextIdFromActiveContext()
 {
     return(_threadingService.ExecuteSynchronously(async() =>
     {
         try
         {
             // If we're never been set an active context, we just
             // pick one based on the active configuration.
             return await _activeWorkspaceProjectContextHost.OpenContextForWriteAsync(a => Task.FromResult(a.ContextId));
         }
         catch (OperationCanceledException)
         {   // Project unloading
             return null;
         }
     }));
 }
        private void TextDocument_FileActionOccurred(object sender, TextDocumentFileActionEventArgs args)
        {
            if (args.FileActionType != FileActionTypes.ContentSavedToDisk)
            {
                return;
            }
            Assumes.Is <ITextDocument>(sender);
            UIThreadHelper.VerifyOnUIThread();
            var textDocument = (ITextDocument)sender;
            var savedText    = textDocument.TextBuffer.CurrentSnapshot.GetText();

            _threadingService.ExecuteSynchronously(() => _msbuildAccessor.RunLockedAsync(true, () =>
            {
                _fileSystem.WriteAllText(_unconfiguredProject.FullPath, savedText);
                return(Task.CompletedTask);
            }));
        }
Esempio n. 21
0
        /// <summary>
        /// Retrieves the value or body of a macro based on the macro's name.
        /// </summary>
        /// <param name="bstrBuildMacroName">String containing the name of the macro.</param>
        /// <param name="pbstrBuildMacroValue">String containing the value or body of the macro.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public int GetBuildMacroValue(string bstrBuildMacroName, out string pbstrBuildMacroValue)
        {
            pbstrBuildMacroValue = null;
            var commonProperties = _configuredProject.Value.Services.ProjectPropertiesProvider.GetCommonProperties();

            pbstrBuildMacroValue = _threadingService.ExecuteSynchronously(() => commonProperties.GetEvaluatedPropertyValueAsync(bstrBuildMacroName));

            if (pbstrBuildMacroValue == null)
            {
                pbstrBuildMacroValue = string.Empty;
                return(VSConstants.E_FAIL);
            }
            else
            {
                return(VSConstants.S_OK);
            }
        }
        protected override void Initialize()
        {
            _activeConfiguredProjectProvider.Changed += OnActiveConfigurationChanged;

            ConfiguredProject?configuredProject = _activeConfiguredProjectProvider.ActiveConfiguredProject;

            if (configuredProject == null)
            {
                _threadingService.ExecuteSynchronously(async() =>
                {
                    configuredProject = await _project.GetSuggestedConfiguredProjectAsync();
                });
            }

            Assumes.NotNull(configuredProject);

            SetValueForConfiguration(configuredProject);
        }
Esempio n. 23
0
        public void Add(string bstrImport)
        {
            if (!_importsList.IsPresent(bstrImport))
            {
                _threadingService.ExecuteSynchronously(async() =>
                {
                    using (var access = await _lockService.WriteLockAsync())
                    {
                        var project = await access.GetProjectAsync(ConfiguredProject).ConfigureAwait(true);
                        await access.CheckoutAsync(project.Xml.ContainingProject.FullPath).ConfigureAwait(true);
                        project.AddItem(importItemTypeName, bstrImport);
                    }
                });

                OnImportAdded(bstrImport);
            }
            else
            {
                throw new ArgumentException(string.Format("{0} - Namespace is already imported", bstrImport), nameof(bstrImport));
            }
        }
        internal void ProcessDataflowChanges(IProjectVersionedValue <DesignTimeInputsDelta> obj)
        {
            // Cancel any in-progress queue processing
            _compilationCancellationSource?.Cancel();

            DesignTimeInputsDelta delta = obj.Value;

            // add all of the changes to our queue
            _queue.Update(delta.ChangedInputs, delta.Inputs, delta.SharedInputs, delta.TempPEOutputPath);

            // Create a cancellation source so we can cancel the compilation if another message comes through
            _compilationCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_project.Services.ProjectAsynchronousTasks.UnloadCancellationToken);

            JoinableTask task = _scheduler.ScheduleAsyncTask(ProcessCompileQueueAsync, _compilationCancellationSource.Token);

            // For unit testing purposes, optionally block the thread until the task we scheduled is complete
            if (CompileSynchronously)
            {
                _threadingService.ExecuteSynchronously(() => task.Task);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Retrieves the value or body of a macro based on the macro's name.
        /// </summary>
        /// <param name="bstrBuildMacroName">String containing the name of the macro.</param>
        /// <param name="pbstrBuildMacroValue">String containing the value or body of the macro.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public int GetBuildMacroValue(string bstrBuildMacroName, out string pbstrBuildMacroValue)
        {
            if (_configuredProject == null)
            {
                pbstrBuildMacroValue = null;
                return(HResult.Unexpected);
            }

            pbstrBuildMacroValue = null;
            ProjectSystem.Properties.IProjectProperties commonProperties = _configuredProject.Value.Services.ProjectPropertiesProvider.GetCommonProperties();
            pbstrBuildMacroValue = _threadingService.ExecuteSynchronously(() => commonProperties.GetEvaluatedPropertyValueAsync(bstrBuildMacroName));

            if (pbstrBuildMacroValue == null)
            {
                pbstrBuildMacroValue = string.Empty;
                return(HResult.Fail);
            }
            else
            {
                return(HResult.OK);
            }
        }
Esempio n. 26
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing && _subscription != null)
                {
                    // Build manager APIs require UI thread access.
                    _threadingService.ExecuteSynchronously(async() =>
                    {
                        await _threadingService.SwitchToUIThread();

                        if (_subscription != null)
                        {
                            // Unregister solution build events.
                            await _subscription.DisposeAsync();
                        }
                    });
                }

                _disposedValue = true;
            }
        }
Esempio n. 27
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing && _buildManager != null)
                {
                    // Build manager APIs require UI thread access.
                    _threadingService.ExecuteSynchronously(async() =>
                    {
                        await _threadingService.SwitchToUIThread();

                        if (_buildManager != null)
                        {
                            // Unregister solution build events.
                            _buildManager.UnadviseUpdateSolutionEvents(_solutionEventsCookie);
                            _buildManager = null;
                        }
                    });
                }

                _disposedValue = true;
            }
        }
Esempio n. 28
0
 private void WaitForAsync(Func <Task> asyncFunc) => _projectThreadingService.ExecuteSynchronously(asyncFunc);
Esempio n. 29
0
 private void EnsureInitialized()
 {
     _threadingService.ExecuteSynchronously(() => InitializeAsync(CancellationToken.None));
 }
Esempio n. 30
0
        public void OnPrioritizedProjectLoadedInHost()
        {
            _prioritizedProjectLoadedInHost.SetResult();

            _threadingService.ExecuteSynchronously(() => _prioritizedTasks.JoinTillEmptyAsync());
        }