Beispiel #1
0
        /// <summary>
        /// Gets if async package is supported in the current instance of Visual Studio
        /// </summary>
        /// <param name="serviceProvider">an IServiceProvider instance, usually a Package instance</param>
        /// <returns>true if async packages are supported</returns>
        public static bool IsAsyncPackageSupported(this IServiceProvider serviceProvider)
        {
            IAsyncServiceProvider asyncServiceProvider =
                serviceProvider.GetService(typeof(SAsyncServiceProvider)) as IAsyncServiceProvider;

            return(asyncServiceProvider != null);
        }
Beispiel #2
0
        private static VsContainedLanguageComponentsFactory CreateInstance(IOleAsyncServiceProvider serviceProvider = null, IUnconfiguredProjectVsServices projectVsServices = null, IActiveWorkspaceProjectContextHost projectContextHost = null)
        {
            projectVsServices  = projectVsServices ?? IUnconfiguredProjectVsServicesFactory.Create();
            projectContextHost = projectContextHost ?? IActiveWorkspaceProjectContextHostFactory.Create();

            return(new VsContainedLanguageComponentsFactory(IVsServiceFactory.Create <SAsyncServiceProvider, IOleAsyncServiceProvider>(serviceProvider),
                                                            projectVsServices,
                                                            projectContextHost));
        }
        private static VsContainedLanguageComponentsFactory CreateInstance(IOleAsyncServiceProvider serviceProvider = null, IUnconfiguredProjectVsServices projectVsServices = null, IProjectHostProvider projectHostProvider = null, ILanguageServiceHost languageServiceHost = null)
        {
            projectVsServices   = projectVsServices ?? IUnconfiguredProjectVsServicesFactory.Create();
            projectHostProvider = projectHostProvider ?? IProjectHostProviderFactory.Create();
            languageServiceHost = languageServiceHost ?? ILanguageServiceHostFactory.Create();

            return(new VsContainedLanguageComponentsFactory(IVsServiceFactory.Create <SAsyncServiceProvider, IOleAsyncServiceProvider>(serviceProvider),
                                                            projectVsServices,
                                                            projectHostProvider,
                                                            languageServiceHost));
        }
Beispiel #4
0
 public IVsTask Initialize(Microsoft.VisualStudio.Shell.Interop.IAsyncServiceProvider asyncServiceProvider,
                           IProfferAsyncService pProfferService, IAsyncProgressCallback pProgressCallback)
 {
     return(ThreadHelper.JoinableTaskFactory.RunAsync <object>(async() =>
     {
         BackgroundThreadInitialization();
         await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
         MainThreadInitialization();
         return null;
     }).AsVsTask());
 }
        /// <summary>
        /// Helper method to use async/await with IAsyncServiceProvider implementation
        /// </summary>
        /// <param name="asyncServiceProvider">IAsyncServciceProvider instance</param>
        /// <param name="serviceType">Type of the Visual Studio service requested</param>
        /// <returns>Service object as type of T</returns>
        public static async Task <T> GetServiceAsync <T>(this IAsyncServiceProvider asyncServiceProvider, Type serviceType) where T : class
        {
            T returnValue = null;

            await ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
            {
                var serviceTypeGuid = serviceType.GUID;
                var serviceInstance = await asyncServiceProvider.QueryServiceAsync(ref serviceTypeGuid);

                // We have to make sure we are on main UI thread before trying to cast as underlying implementation
                // can be an STA COM object and doing a cast would require calling QueryInterface/AddRef marshaling
                // to main thread via COM.
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                returnValue = serviceInstance as T;
            });

            return(returnValue);
        }
Beispiel #6
0
        /// <summary>
        /// Performs the asynchronous initialization for the package in cases where IDE supports AsyncPackage.
        ///
        /// This method is always called from background thread initially.
        /// </summary>
        /// <param name="asyncServiceProvider">Async service provider instance to query services asynchronously</param>
        /// <param name="pProfferService">Async service proffer instance</param>
        /// <param name="IAsyncProgressCallback">Progress callback instance</param>
        /// <returns></returns>
        public IVsTask Initialize(Microsoft.VisualStudio.Shell.Interop.IAsyncServiceProvider asyncServiceProvider,
                                  IProfferAsyncService pProfferService, IAsyncProgressCallback pProgressCallback)
        {
            if (!isAsyncLoadSupported)
            {
                throw new InvalidOperationException("Async Initialize method should not be called when async load is not supported.");
            }

            return(ThreadHelper.JoinableTaskFactory.RunAsync <object>(async() =>
            {
                BackgroundThreadInitialization();

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                MainThreadInitialization();
                return null;
            }).AsVsTask());
        }
Beispiel #7
0
        private async Task <IVsContainedLanguageFactory> GetContainedLanguageFactoryAsync()
        {
            Guid languageServiceId = await GetLanguageServiceId();

            if (languageServiceId == Guid.Empty)
            {
                return(null);
            }

            IOleAsyncServiceProvider serviceProvider = await _serviceProvider.GetValueAsync();

            object service = await serviceProvider.QueryServiceAsync(ref languageServiceId);

            // NOTE: While this type is implemented in Roslyn, we force the cast on
            // the UI thread because they are free to change this to an STA object
            // which would result in an RPC call from a background thread.
            await _projectVsServices.ThreadingService.SwitchToUIThread();

            return((IVsContainedLanguageFactory)service);
        }
Beispiel #8
0
        public IVsTask Initialize(IAsyncServiceProvider pServiceProvider, IProfferAsyncService pProfferService,
                                  IAsyncProgressCallback pProgressCallback)
        {
            if (!_wakaTime.IsAsyncLoadSupported)
            {
                throw new InvalidOperationException("Async Initialize method should not be called when async load is not supported.");
            }

            return(ThreadHelper.JoinableTaskFactory.RunAsync <object>(async() =>
            {
                _wakaTime.Logger.Debug("Initializing async.");
                InitializeAsync();

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                OnOnStartupComplete();

                return null;
            }).AsVsTask());
        }
Beispiel #9
0
 /// <summary>
 /// Gets if async package is supported in the current instance of Visual Studio
 /// </summary>
 /// <param name="serviceProvider">an IServiceProvider instance, usually a Package instance</param>
 /// <returns>true if async packages are supported</returns>
 public static bool IsAsyncPackageSupported(this IServiceProvider serviceProvider)
 {
     Microsoft.VisualStudio.Shell.Interop.IAsyncServiceProvider asyncServiceProvider = serviceProvider.GetService(typeof(SAsyncServiceProvider)) as Microsoft.VisualStudio.Shell.Interop.IAsyncServiceProvider;
     return(asyncServiceProvider != null);
 }