private async Task <IVsOperationProgressStageStatusForSolutionLoad> GetProgressStageStatusAsync(CancellationToken cancellationToken)
            {
                var service = await _serviceProvider.GetServiceAsync <SVsOperationProgress, IVsOperationProgressStatusService>(throwOnFailure : false)
                              .WithCancellation(cancellationToken).ConfigureAwait(false);

                return(service?.GetStageStatusForSolutionLoad(CommonOperationProgressStageIds.Intellisense));
            }
Example #2
0
        public LogHubLogger([Import(typeof(SAsyncServiceProvider))] IAsyncServiceProvider2 asyncServiceProvider)
        {
            asyncServiceProvider.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>(throwOnFailure: true).ContinueWith(async(t) => {
                var serviceBroker = t.Result.GetFullAccessServiceBroker();
                Assumes.NotNull(serviceBroker);

                // Setup logging using the log hub
                using TraceConfiguration config = await TraceConfiguration.CreateTraceConfigurationInstanceAsync(serviceBroker, false);
                SourceLevels sourceLevels       = SourceLevels.Information | SourceLevels.ActivityTracing;
                LoggerOptions logOptions        = new(
                    requestedLoggingLevel: new LoggingLevelSettings(sourceLevels),
                    privacySetting: PrivacyFlags.MayContainPersonallyIdentifibleInformation | PrivacyFlags.MayContainPrivateInformation);

                this._traceSource = await config.RegisterLogSourceAsync(new LogId("Microsoft.PythonTools", serviceId: null), logOptions, traceSource: null, isBootstrappedService: true, default);
            });
        }
            public Service(IAsyncServiceProvider2 serviceProvider, IThreadingContext threadingContext, IAsynchronousOperationListener listener)
            {
                _serviceProvider  = serviceProvider;
                _threadingContext = threadingContext;

                _loadHubClientPackage = _threadingContext.JoinableTaskFactory.RunAsync(async() =>
                {
                    // Use the disposal token, since the caller's cancellation token will apply instead to the
                    // JoinAsync operation in GetProgressStageStatusAsync.
                    await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _threadingContext.DisposalToken);

                    // Make sure the HubClient package is loaded, since we rely on it for proffered OOP services
                    var shell = await _serviceProvider.GetServiceAsync <SVsShell, IVsShell7>().ConfigureAwait(true);
                    Assumes.Present(shell);

                    await shell.LoadPackageAsync(Guids.GlobalHubClientPackageGuid);
                });

                _progressStageStatus = _threadingContext.JoinableTaskFactory.RunAsync(async() =>
                {
                    // pre-emptively make sure event is subscribed. if APIs are called before it is done, calls will be blocked
                    // until event subscription is done
                    using var asyncToken = listener.BeginAsyncOperation("StatusChanged_EventSubscription");

                    await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true, _threadingContext.DisposalToken);
                    var service = await serviceProvider.GetServiceAsync <SVsOperationProgress, IVsOperationProgressStatusService>(throwOnFailure: false).ConfigureAwait(true);
                    if (service is null)
                    {
                        return(null);
                    }

                    var status              = service.GetStageStatusForSolutionLoad(CommonOperationProgressStageIds.Intellisense);
                    status.PropertyChanged += (_, _) => StatusChanged?.Invoke(this, EventArgs.Empty);

                    return(status);
                });
            }
Example #4
0
        /// <summary>
        /// Writes generated content to output files and deletes the old files that were not regenerated.
        /// </summary>
        /// <param name="inputFile">
        /// Full path to the template file.
        /// </param>
        /// <param name="outputFiles">
        /// A collection of <see cref="OutputFile"/> objects produced by the template.
        /// </param>
        async void ITransformationContextProvider.UpdateOutputFiles(string inputFile, OutputFile[] outputFiles)
        {
            if (inputFile == null)
            {
                throw new ArgumentNullException("inputFile");
            }

            if (!Path.IsPathRooted(inputFile))
            {
                throw new ArgumentException(Resources.InputFilePathMustBeAbsoluteMessage, "inputFile");
            }

            if (outputFiles == null)
            {
                throw new ArgumentNullException("outputFiles");
            }

            foreach (OutputFile newOutput in outputFiles)
            {
                if (newOutput == null)
                {
                    throw new ArgumentException(Resources.OutputFileIsNullMessage, "outputFiles");
                }
            }

            var dte = (DTE)await serviceProvider.GetServiceAsync(typeof(DTE)).ConfigureAwait(false);

            ITextTemplatingEngineHost textTemplatingEngineHost = (ITextTemplatingEngineHost)await this.serviceProvider.GetServiceAsync(typeof(STextTemplating)).ConfigureAwait(false);

            // Validate the output files immediately. Exceptions will be reported by the templating service.
            var manager = new OutputFileManager(
                this.serviceProvider,
                dte,
                textTemplatingEngineHost,
                inputFile,
                outputFiles
                );
            await manager.ValidateAsync();

            // Wait for the default output file to be generated
            var watcher = new FileSystemWatcher();

            watcher.Path   = Path.GetDirectoryName(inputFile);
            watcher.Filter = Path.GetFileNameWithoutExtension(inputFile) + "*." + await this.GetTransformationOutputExtensionFromHostAsync();

            FileSystemEventHandler runManager = (sender, args) =>
            {
                watcher.Dispose();

                // Store the actual output file name
                OutputFile defaultOutput = outputFiles.FirstOrDefault(output => string.IsNullOrEmpty(output.File));
                if (defaultOutput != null)
                {
                    defaultOutput.File = Path.GetFileName(args.FullPath);
                }

                // Finish updating the output files on the UI thread
                ThreadHelper.Generic.BeginInvoke(async() => await manager.DoWorkAsync());
            };

            watcher.Created            += runManager;
            watcher.Changed            += runManager;
            watcher.EnableRaisingEvents = true;
        }