Ejemplo n.º 1
0
        private static IEnumerable<SledSyntaxCheckerEntry> CheckFiles(IEnumerable<SledProjectFilesFileType> files, SledSyntaxCheckerVerbosity verbosity, object userData, SledUtil.BoolWrapper shouldCancel)
        {
            SledHiPerfTimer timer = null;

            var enumeratedFiles = new List<SledProjectFilesFileType>(files);
            
            var errors = new List<SledSyntaxCheckerEntry>();
            var fileCount = enumeratedFiles.Count;

            try
            {
                if (verbosity > SledSyntaxCheckerVerbosity.None)
                {
                    timer = new SledHiPerfTimer();
                    timer.Start();
                }
                
                var allWorkItems = new SyntaxCheckerWorkItem[fileCount];

                for (var i = 0; i < fileCount; ++i)
                    allWorkItems[i] = new SyntaxCheckerWorkItem(enumeratedFiles[i], verbosity, userData, shouldCancel);

                var workerCount = Math.Min(ProducerConsumerQueue.WorkerCount, fileCount);
                using (var pcQueue = new ProducerConsumerQueue(workerCount, shouldCancel))
                {
                    pcQueue.EnqueueWorkItems(allWorkItems);
                }

                if (shouldCancel.Value)
                    return EmptyEnumerable<SledSyntaxCheckerEntry>.Instance;

                // gather all results from all work items
                foreach (var workItem in allWorkItems)
                    errors.AddRange(workItem.Errors);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    "{0}: Exception syntax checking files: {1}",
                    typeof(SledLuaSyntaxCheckerService), ex.Message);
            }
            finally
            {
                if ((timer != null) && (!shouldCancel.Value))
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        "[Lua] Syntax checked {0} files in {1} seconds",
                        fileCount, timer.Elapsed);
                }
            }

            return errors;
        }
        private static IEnumerable <SledSyntaxCheckerEntry> CheckFiles(IEnumerable <SledProjectFilesFileType> files, SledSyntaxCheckerVerbosity verbosity, object userData, SledUtil.BoolWrapper shouldCancel)
        {
            SledHiPerfTimer timer = null;

            var enumeratedFiles = new List <SledProjectFilesFileType>(files);

            var errors    = new List <SledSyntaxCheckerEntry>();
            var fileCount = enumeratedFiles.Count;

            try
            {
                if (verbosity > SledSyntaxCheckerVerbosity.None)
                {
                    timer = new SledHiPerfTimer();
                    timer.Start();
                }

                var allWorkItems = new SyntaxCheckerWorkItem[fileCount];

                for (var i = 0; i < fileCount; ++i)
                {
                    allWorkItems[i] = new SyntaxCheckerWorkItem(enumeratedFiles[i], verbosity, userData, shouldCancel);
                }

                var workerCount = Math.Min(ProducerConsumerQueue.WorkerCount, fileCount);
                using (var pcQueue = new ProducerConsumerQueue(workerCount, shouldCancel))
                {
                    pcQueue.EnqueueWorkItems(allWorkItems);
                }

                if (shouldCancel.Value)
                {
                    return(EmptyEnumerable <SledSyntaxCheckerEntry> .Instance);
                }

                // gather all results from all work items
                foreach (var workItem in allWorkItems)
                {
                    errors.AddRange(workItem.Errors);
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    "{0}: Exception syntax checking files: {1}",
                    typeof(SledLuaSyntaxCheckerService), ex.Message);
            }
            finally
            {
                if ((timer != null) && (!shouldCancel.Value))
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        "[Lua] Syntax checked {0} files in {1} seconds",
                        fileCount, timer.Elapsed);
                }
            }

            return(errors);
        }