public CompilingProgressManager(ICompilingProgressReporter reporter, int numClips) { this.reporter = reporter; this.numPgses = numClips; this.threadLimit = new Semaphore(Environment.ProcessorCount, Environment.ProcessorCount); //this.threadLimit = new Semaphore(1, 1); }
public async Task <bool> Compile(ICompilingProgressReporter reporter, Guid projectId, DirectoryInfo outputDir, params DocumentClipDescriptor[] clips) { AssertNotDisposed(); var tPgsNum = clips.Sum(xClip => xClip.Tracks.Count); var tProgressManager = new CompilingProgressManager(reporter, tPgsNum); ProjectSettings tProjSettings = new ProjectSettings() { OutputDir = outputDir, TempDir = settings.TempDir.NavigateTo(string.Format(PesMuxOutputPath, projectId)) }; Project tProj = new Project(tProjSettings); var tPesDir = settings.TempDir.NavigateTo(string.Format(PesEncOutputPath, projectId)).SafeCreate(string.Empty); var tClipTasks = (from iClip in clips select CompileDocumentClip(tProgressManager, iClip, tPesDir)).ToArray(); var tPgsEncTask = Task.WhenAll(tClipTasks); try { await tPgsEncTask; } catch { } if (tPgsEncTask.Exception != null || reporter.IsCanceled) { ReportSummary(reporter, tPgsEncTask.Exception); return(false); } tProj.AddClipList(tClipTasks.Select(xClipTask => xClipTask.Result)); var tPesMuxTask = this.GetPesMuxer().Mux(tProj, tProgressManager); try { await tPesMuxTask; } catch { } if (tPesMuxTask.Exception != null || reporter.IsCanceled) { ReportSummary(reporter, tPesMuxTask.Exception); return(false); } ReportSummary(reporter, null); return(true); }
private void ReportSummary(ICompilingProgressReporter reporter, AggregateException ex) { if (ex != null) { foreach (var iEx in ex.InnerExceptions) { this.logger.Log(iEx); } this.logger.Log(128, "Project compiling failed."); } else if (reporter.IsCanceled) { this.logger.Log(128, "Project compiling canceled."); } else { this.logger.Log(128, "Project compiled successful."); } reporter.OnTaskEnd(); }