Beispiel #1
0
        public void Push_UpdatesFileWriteTime()
        {
            var queue = new CompilationQueue();

            queue.Push(new QueueItem("FileName", ImmutableHashSet <string> .Empty, "", false));

            queue.Push(new QueueItem("FileName", ImmutableHashSet <string> .Empty, "", true));

            Assert.Equal(1, queue.Count);
            Assert.True(queue.Pop()?.IgnoreFileWriteTime);
        }
Beispiel #2
0
        public void Push_Adds()
        {
            var queue = new CompilationQueue();

            queue.Push(new QueueItem("FileName", ImmutableHashSet <string> .Empty, "", false));

            Assert.Equal(1, queue.Count);
        }
Beispiel #3
0
        public void RemoveSpecific_Removes()
        {
            var queue = new CompilationQueue();

            queue.Push(new QueueItem("FileName", ImmutableHashSet <string> .Empty, "", false));

            queue.RemoveSpecific("FileName");

            Assert.Equal(0, queue.Count);
        }
        private Task ProcessCompileQueueAsync(CancellationToken token)
        {
            int compileCount       = 0;
            int initialQueueLength = _queue.Count;
            var compileStopWatch   = Stopwatch.StartNew();

            return(_activeWorkspaceProjectContextHost.OpenContextForWriteAsync(async accessor =>
            {
                while (true)
                {
                    if (IsDisposing || IsDisposed)
                    {
                        return;
                    }

                    // we don't want to pop if we've been cancelled in the time it took to take the write lock, so check just in case.
                    // this may be overkill
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    // Grab the next file to compile off the queue
                    QueueItem?item = _queue.Pop();
                    if (item == null)
                    {
                        break;
                    }

                    bool cancelled = false;
                    string outputFileName = GetOutputFileName(item.FileName, item.TempPEOutputPath);
                    try
                    {
                        if (await CompileDesignTimeInputAsync(accessor.Context, item.FileName, outputFileName, item.SharedInputs, item.IgnoreFileWriteTime, token))
                        {
                            compileCount++;
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        cancelled = true;
                    }

                    if (cancelled || token.IsCancellationRequested)
                    {
                        // if the compilation was cancelled, we need to re-add the file so we catch it next time
                        _queue.Push(item);
                        break;
                    }
                }

                LogTelemetry(cancelled: token.IsCancellationRequested);
            }));

            void LogTelemetry(bool cancelled)
            {
                compileStopWatch !.Stop();
                _telemetryService.PostProperties(TelemetryEventName.TempPEProcessQueue, new[]
                {
                    (TelemetryPropertyName.TempPECompileCount, (object)compileCount),
                    (TelemetryPropertyName.TempPEInitialQueueLength, initialQueueLength),
                    (TelemetryPropertyName.TempPECompileWasCancelled, cancelled),
                    (TelemetryPropertyName.TempPECompileDuration, compileStopWatch.ElapsedMilliseconds)
                });