private static IEnumerable<SledLanguageParserResult> ParseFiles(IEnumerable<SledProjectFilesFileType> files, SledLanguageParserVerbosity verbosity, object userData, SledUtil.BoolWrapper shouldCancel)
        {
            SledHiPerfTimer timer = null;

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

            var results = new List<SledLanguageParserResult>();
            var fileCount = enumeratedFiles.Count;

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

                var allWorkItems = new ParserWorkItem[fileCount];

                for (var i = 0; i < fileCount; ++i)
                    allWorkItems[i] = new ParserWorkItem(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<SledLanguageParserResult>.Instance;

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

            return results;
        }
Example #2
0
        private static IEnumerable <SledLanguageParserResult> ParseFiles(IEnumerable <SledProjectFilesFileType> files, SledLanguageParserVerbosity verbosity, object userData, SledUtil.BoolWrapper shouldCancel)
        {
            SledHiPerfTimer timer = null;

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

            var results   = new List <SledLanguageParserResult>();
            var fileCount = enumeratedFiles.Count;

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

                var allWorkItems = new ParserWorkItem[fileCount];

                for (var i = 0; i < fileCount; ++i)
                {
                    allWorkItems[i] = new ParserWorkItem(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 <SledLanguageParserResult> .Instance);
                }

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

            return(results);
        }