public Project(ProjectModuleOptions options, string projDir, SatelliteAssemblyFinder satelliteAssemblyFinder) { if (options == null) throw new ArgumentNullException(); this.options = options; this.projDir = projDir; this.satelliteAssemblyFinder = satelliteAssemblyFinder; this.files = new List<ProjectFile>(); this.defaultNamespace = new DefaultNamespaceFinder(options.Module).Find(); this.filename = Path.Combine(projDir, Path.GetFileName(projDir) + options.Language.ProjectFileExtension); this.assemblyName = options.Module.Assembly == null ? string.Empty : options.Module.Assembly.Name.String; this.projectTypeGuids = new HashSet<Guid>(); this.PropertiesFolder = CalculatePropertiesFolder(); this.extraAssemblyReferences = new HashSet<string>(); this.languageGuid = CalculateLanguageGuid(options.Language); }
public Project(ProjectModuleOptions options, string projDir, SatelliteAssemblyFinder satelliteAssemblyFinder) { if (options == null) { throw new ArgumentNullException(); } this.options = options; this.projDir = projDir; this.satelliteAssemblyFinder = satelliteAssemblyFinder; this.files = new List <ProjectFile>(); this.defaultNamespace = new DefaultNamespaceFinder(options.Module).Find(); this.filename = Path.Combine(projDir, Path.GetFileName(projDir) + options.Language.ProjectFileExtension); this.assemblyName = options.Module.Assembly == null ? string.Empty : options.Module.Assembly.Name.String; this.projectTypeGuids = new HashSet <Guid>(); this.PropertiesFolder = CalculatePropertiesFolder(); this.extraAssemblyReferences = new HashSet <string>(); this.languageGuid = CalculateLanguageGuid(options.Language); }
public Project(ProjectModuleOptions options, string projDir, SatelliteAssemblyFinder satelliteAssemblyFinder, Func <TextWriter, IDecompilerOutput> createDecompilerOutput) { if (options == null) { throw new ArgumentNullException(nameof(options)); } this.Options = options; this.Directory = projDir; this.satelliteAssemblyFinder = satelliteAssemblyFinder; this.createDecompilerOutput = createDecompilerOutput; this.Files = new List <ProjectFile>(); this.DefaultNamespace = new DefaultNamespaceFinder(options.Module).Find(); this.Filename = Path.Combine(projDir, Path.GetFileName(projDir) + options.Language.ProjectFileExtension); this.AssemblyName = options.Module.Assembly == null ? string.Empty : options.Module.Assembly.Name.String; this.ProjectTypeGuids = new HashSet <Guid>(); this.PropertiesFolder = CalculatePropertiesFolder(); this.ExtraAssemblyReferences = new HashSet <string>(); this.LanguageGuid = CalculateLanguageGuid(options.Language); }
public void Create() { SatelliteAssemblyFinder satelliteAssemblyFinder = null; try { var opts = new ParallelOptions { CancellationToken = options.CancellationToken, MaxDegreeOfParallelism = options.NumberOfThreads <= 0 ? Environment.ProcessorCount : options.NumberOfThreads, }; var filenameCreator = new FilenameCreator(options.Directory); var ctx = new DecompileContext(options.CancellationToken, logger); satelliteAssemblyFinder = new SatelliteAssemblyFinder(); Parallel.ForEach(options.ProjectModules, opts, modOpts => { options.CancellationToken.ThrowIfCancellationRequested(); string name; lock (filenameCreator) name = filenameCreator.Create(modOpts.Module); var p = new Project(modOpts, name, satelliteAssemblyFinder, options.CreateDecompilerOutput); lock (projects) projects.Add(p); p.CreateProjectFiles(ctx); }); var jobs = GetJobs().ToArray(); bool writeSolutionFile = !string.IsNullOrEmpty(options.SolutionFilename); int maxProgress = jobs.Length + projects.Count; if (writeSolutionFile) { maxProgress++; } progressListener.SetMaxProgress(maxProgress); Parallel.ForEach(GetJobs(), opts, job => { options.CancellationToken.ThrowIfCancellationRequested(); try { job.Create(ctx); } catch (OperationCanceledException) { throw; } catch (Exception ex) { var fjob = job as IFileJob; if (fjob != null) { logger.Error(string.Format(dnSpy_Languages_Resources.MSBuild_FileCreationFailed3, fjob.Filename, job.Description, ex.Message)); } else { logger.Error(string.Format(dnSpy_Languages_Resources.MSBuild_FileCreationFailed2, job.Description, ex.Message)); } } progressListener.SetProgress(Interlocked.Increment(ref totalProgress)); }); Parallel.ForEach(projects, opts, p => { options.CancellationToken.ThrowIfCancellationRequested(); try { var writer = new ProjectWriter(p, p.Options.ProjectVersion ?? options.ProjectVersion, projects, options.UserGACPaths); writer.Write(); } catch (OperationCanceledException) { throw; } catch (Exception ex) { logger.Error(string.Format(dnSpy_Languages_Resources.MSBuild_FailedToCreateProjectFile, p.Filename, ex.Message)); } progressListener.SetProgress(Interlocked.Increment(ref totalProgress)); }); if (writeSolutionFile) { options.CancellationToken.ThrowIfCancellationRequested(); try { var writer = new SolutionWriter(options.ProjectVersion, projects, SolutionFilename); writer.Write(); } catch (OperationCanceledException) { throw; } catch (Exception ex) { logger.Error(string.Format(dnSpy_Languages_Resources.MSBuild_FailedToCreateSolutionFile, SolutionFilename, ex.Message)); } progressListener.SetProgress(Interlocked.Increment(ref totalProgress)); } Debug.Assert(totalProgress == maxProgress); progressListener.SetProgress(maxProgress); } finally { if (satelliteAssemblyFinder != null) { satelliteAssemblyFinder.Dispose(); } } }
public void Create() { SatelliteAssemblyFinder satelliteAssemblyFinder = null; try { var opts = new ParallelOptions { CancellationToken = options.CancellationToken, MaxDegreeOfParallelism = options.NumberOfThreads <= 0 ? Environment.ProcessorCount : options.NumberOfThreads, }; var filenameCreator = new FilenameCreator(options.Directory); var ctx = new DecompileContext(options.CancellationToken, logger); satelliteAssemblyFinder = new SatelliteAssemblyFinder(); Parallel.ForEach(options.ProjectModules, opts, modOpts => { AppCulture.InitializeCulture(); options.CancellationToken.ThrowIfCancellationRequested(); string name; lock (filenameCreator) name = filenameCreator.Create(modOpts.Module); var p = new Project(modOpts, name, satelliteAssemblyFinder); lock (projects) projects.Add(p); p.CreateProjectFiles(ctx); }); var jobs = GetJobs().ToArray(); bool writeSolutionFile = !string.IsNullOrEmpty(options.SolutionFilename); int maxProgress = jobs.Length + projects.Count; if (writeSolutionFile) maxProgress++; progressListener.SetMaxProgress(maxProgress); Parallel.ForEach(GetJobs(), opts, job => { AppCulture.InitializeCulture(); options.CancellationToken.ThrowIfCancellationRequested(); try { job.Create(ctx); } catch (OperationCanceledException) { throw; } catch (Exception ex) { var fjob = job as IFileJob; if (fjob != null) logger.Error(string.Format(Languages_Resources.MSBuild_FileCreationFailed3, fjob.Filename, job.Description, ex.Message)); else logger.Error(string.Format(Languages_Resources.MSBuild_FileCreationFailed2, job.Description, ex.Message)); } progressListener.SetProgress(Interlocked.Increment(ref totalProgress)); }); Parallel.ForEach(projects, opts, p => { AppCulture.InitializeCulture(); options.CancellationToken.ThrowIfCancellationRequested(); try { var writer = new ProjectWriter(p, p.Options.ProjectVersion ?? options.ProjectVersion, projects, options.UserGACPaths); writer.Write(); } catch (OperationCanceledException) { throw; } catch (Exception ex) { logger.Error(string.Format(Languages_Resources.MSBuild_FailedToCreateProjectFile, p.Filename, ex.Message)); } progressListener.SetProgress(Interlocked.Increment(ref totalProgress)); }); if (writeSolutionFile) { options.CancellationToken.ThrowIfCancellationRequested(); try { var writer = new SolutionWriter(options.ProjectVersion, projects, SolutionFilename); writer.Write(); } catch (OperationCanceledException) { throw; } catch (Exception ex) { logger.Error(string.Format(Languages_Resources.MSBuild_FailedToCreateSolutionFile, SolutionFilename, ex.Message)); } progressListener.SetProgress(Interlocked.Increment(ref totalProgress)); } Debug.Assert(totalProgress == maxProgress); progressListener.SetProgress(maxProgress); } finally { if (satelliteAssemblyFinder != null) satelliteAssemblyFinder.Dispose(); } }