public Dictionary <string, List <GenericActionExecution> > Run(ProjectActions projectActions, ProjectType projectType) { IEnumerable <FileActions> fileActions = projectActions.FileActions; ConcurrentDictionary <string, List <GenericActionExecution> > actionsPerProject = new ConcurrentDictionary <string, List <GenericActionExecution> >(); var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = Constants.ThreadCount }; var fileActionsCount = fileActions.Count(); Parallel.ForEach(_sourceFileBuildResults, parallelOptions, sourceFileBuildResult => { try { var currentFileActions = fileActions.Where(f => f.FilePath == sourceFileBuildResult.SourceFileFullPath).FirstOrDefault(); var root = sourceFileBuildResult.SyntaxTree.GetRoot(); if (currentFileActions != null) { LogHelper.LogInformation("---------------------------------------------------------------------------"); LogHelper.LogInformation("Processing file " + sourceFileBuildResult.SourceFilePath); if (_projectConfiguration.PortCode) { RunCodeChanges(root, sourceFileBuildResult, currentFileActions, actionsPerProject); } else { GenerateCodeChanges(root, sourceFileBuildResult, currentFileActions, fileActionsCount, actionsPerProject); } } } catch (Exception ex) { var filePortingException = new FilePortingException(sourceFileBuildResult.SourceFilePath, ex); LogHelper.LogError(filePortingException); } }); var projectRunActions = new List <GenericActionExecution>(); if (_projectConfiguration.PortProject) { projectRunActions = ApplyProjectActions(projectActions, projectType); if (!actionsPerProject.TryAdd(Constants.Project, projectRunActions)) { LogHelper.LogError(new FilePortingException(Constants.Project, new Exception("Error adding project to actions collection"))); } } return(actionsPerProject.ToDictionary(a => a.Key, a => a.Value)); }
public Dictionary <string, List <GenericActionExecution> > Run(ProjectActions projectActions, ProjectType projectType) { IEnumerable <FileActions> fileActions = projectActions.FileActions; ConcurrentDictionary <string, List <GenericActionExecution> > actionsPerProject = new ConcurrentDictionary <string, List <GenericActionExecution> >(); var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = Constants.ThreadCount }; Parallel.ForEach(_sourceFileBuildResults, parallelOptions, sourceFileBuildResult => { try { var currentFileActions = fileActions.Where(f => f.FilePath == sourceFileBuildResult.SourceFileFullPath).FirstOrDefault(); var root = sourceFileBuildResult.SyntaxTree.GetRoot(); if (currentFileActions != null) { LogHelper.LogInformation("---------------------------------------------------------------------------"); LogHelper.LogInformation("Processing file " + sourceFileBuildResult.SourceFilePath); ActionsRewriter oneRewriter = new ActionsRewriter(sourceFileBuildResult.SemanticModel, sourceFileBuildResult.SyntaxGenerator, currentFileActions); root = oneRewriter.Visit(root); var result = root.NormalizeWhitespace().ToFullString(); //TODO : Can you send a result if (!_projectConfiguration.IsMockRun) { File.WriteAllText(sourceFileBuildResult.SourceFileFullPath, result); } var processedActions = ValidateActions(oneRewriter.allActions, result); processedActions = AddActionsWithoutExecutions(currentFileActions, oneRewriter.allActions); if (!actionsPerProject.TryAdd(sourceFileBuildResult.SourceFileFullPath, processedActions)) { throw new FilePortingException(sourceFileBuildResult.SourceFilePath, new Exception("File already exists in collection")); } } } catch (Exception ex) { var filePortingException = new FilePortingException(sourceFileBuildResult.SourceFilePath, ex); LogHelper.LogError(filePortingException); } }); var projectRunActions = new List <GenericActionExecution>(); //Project Level Actions foreach (var projectLevelAction in projectActions.ProjectLevelActions) { var projectActionExecution = new GenericActionExecution(projectLevelAction, _projectConfiguration.ProjectPath); projectActionExecution.TimesRun = 1; var runResult = string.Empty; if (!_projectConfiguration.IsMockRun) { if (projectLevelAction.ProjectLevelActionFunc != null) { try { runResult = projectLevelAction.ProjectLevelActionFunc(_projectConfiguration.ProjectPath, projectType); } catch (Exception ex) { var actionExecutionException = new ActionExecutionException(projectLevelAction.Name, projectLevelAction.Key, ex); projectActionExecution.InvalidExecutions = 1; LogHelper.LogError(actionExecutionException); } } else if (projectLevelAction.ProjectFileActionFunc != null) { try { runResult = projectLevelAction.ProjectFileActionFunc(_projectConfiguration.ProjectPath, projectType, _projectConfiguration.TargetVersions, projectActions.PackageActions.Distinct().ToDictionary(p => p.Name, p => p.Version), projectActions.ProjectReferenceActions.ToList()); } catch (Exception ex) { var actionExecutionException = new ActionExecutionException(projectLevelAction.Name, projectLevelAction.Key, ex); projectActionExecution.InvalidExecutions = 1; LogHelper.LogError(actionExecutionException); } } } if (!string.IsNullOrEmpty(runResult)) { projectActionExecution.Description = string.Concat(projectActionExecution.Description, ": ", runResult); projectRunActions.Add(projectActionExecution); LogHelper.LogInformation(projectLevelAction.Description); } } if (!actionsPerProject.TryAdd(Constants.Project, projectRunActions)) { LogHelper.LogError(new FilePortingException(Constants.Project, new Exception("Error adding project to actions collection"))); } return(actionsPerProject.ToDictionary(a => a.Key, a => a.Value)); }