public static Task <ICompilierResult[]> CompileAsync(this Project project, IProgress <ICompilierResult> progress = default, System.Threading.CancellationToken cancellationToken = default)
        {
            var factory = new CompilerFactory();
            var tasks   = new Stack <Task <ICompilierResult> >();

            foreach (string path in Directory.EnumerateFiles(project.DirectoryName, "*", SearchOption.AllDirectories))
            {
                foreach (IItemGroup itemGroup in project.GetItempGroups())
                {
                    if (itemGroup.Enabled && itemGroup.CanAccept(path))
                    {
                        foreach (ICompilierOptions options in itemGroup.CreateCompilerOptions(path))
                        {
                            ICompiler compiler = factory.CreateInstance(options);
                            tasks.Push(Task.Run(() =>
                            {
                                using (compiler)
                                {
                                    if (compiler.CanExecute(options))
                                    {
                                        ICompilierResult result = compiler.Execute(options);
                                        progress?.Report(result);
                                        return(result);
                                    }

                                    return(new EmptyResult());
                                }
                            }, cancellationToken));
                        }
                    }
                }
            }

            return(Task.WhenAll(tasks));
        }
Exemple #2
0
        protected void HandleMessage(ICompilierOptions options)
        {
            foreach (Type type in _factory.GetCompilerTypesThatSupports(options))
            {
                ICompiler fileOperator = (_compilers.Contains(type.Name) ? ((ICompiler)_compilers[type.Name]) : _factory.CreateInstance(type));

                if (fileOperator.CanExecute(options))
                {
                    if (!_compilers.Contains(type.Name))
                    {
                        _compilers.Add(type.Name, fileOperator);
                    }

                    ICompilierResult result = fileOperator.Execute(options);
                    _reporter?.Report(new ProgressToken(result));
                    break;
                }
            }
        }
Exemple #3
0
        internal void Process(ICompilierOptions options)
        {
            foreach (Type type in _factory.GetCompilerTypesThatSupports(options))
            {
                ICompiler fileOperator = _factory.CreateInstance(type);

                if (fileOperator.CanExecute(options))
                {
                    _totalActiveOperations++;
                    _preCompilationHandler?.Invoke(options, _project?.DirectoryName);
                    Task.Run(() =>
                    {
                        using (fileOperator)
                        {
                            ICompilierResult result = fileOperator.Execute(options);
                            _postCompilationHandler?.Invoke(new ProgressToken(result), _project?.DirectoryName);
                            _totalActiveOperations--;
                        }
                    });
                    break;
                }
            }
        }