private static void ProcessFiles( IFixer fixer, IEnumerable <string> projectFilePaths, bool dryRun = false) { foreach (string projectFile in projectFilePaths) { try { var project = new Project(projectFile); fixer.Fix(project); if (!project.IsDirty) { Console.WriteLine($"{projectFile}: no action necessary"); continue; } if (!dryRun) { project.Save(); Console.WriteLine($"{projectFile}: updated"); } else { Console.WriteLine($"{projectFile}: would update"); } } catch (Exception e) { Console.Error.WriteLine($"{projectFile}: {e.Message}"); } } }
/// <summary> /// </summary> public static int Main(string[] args) { var parser = new CustomParserProxy(Console.Error); IEnumerable <string> validPaths = null; if (!parser.TryParse(args, out Options options) || !parser.TrySelectCsprojFilePaths(options.ProjectFilePaths, out validPaths)) { Environment.Exit(1); } IFixer fixer = null; try { fixer = FixerImplementationSelector.SelectImplementation(options); } catch (InvalidOperationException e) { Console.Error.WriteLine(e.Message); Environment.Exit(1); } ProcessFiles(fixer, validPaths, options.DryRun); return(0); }
private async Task <bool> ProcessAsync(MSBuildWorkspace workspace, IFixer fixer, Solution solution, int fixerIndex, int fixersCount) { var projects = solution.Projects .Where(x => settings.ProjectNameFilter?.Invoke(x.Name) ?? true) .ToList(); var changesApplied = true; var currentProjectIndex = 0; foreach (var project in projects) { ++currentProjectIndex; log.Info($"Project {project!.Name}"); var documents = project.Documents.ToList(); var currentDocumentIndex = 0; foreach (var document in documents) { ++currentDocumentIndex; log.Debug($"{fixerIndex:00}/{fixersCount:00} - {currentProjectIndex:000}/{projects.Count:000} - {currentDocumentIndex:0000}/{documents.Count:0000} // {project.Name} // {document!.FilePath}"); if (!document.SupportsSyntaxTree) { continue; } var documentEditor = await DocumentEditor.CreateAsync(document); await fixer.FixAsync(document, documentEditor); var newDocument = documentEditor.GetChangedDocument(); changesApplied = workspace.TryApplyChanges(newDocument.Project.Solution) && changesApplied; } } return(changesApplied); }
public void Run(IGrabber grabber, IFixer fixer) { if (grabber == null) { throw new ArgumentNullException("grabber"); } if (fixer == null) { throw new ArgumentNullException("fixer"); } try { PreRunPrepare(); if (Options.Rebase) { grabber.FetchBranches(); } else if (!string.IsNullOrWhiteSpace(Options.RebaseBranch)) { grabber.FetchRebaseBraches(); } else { grabber.Clone(); } fixer.FixBranches(); fixer.FixTags(); fixer.FixTrunk(); fixer.OptimizeRepos(); } finally { PostRunCleanup(); } }
static int Main(string[] args) { try { var(success, config) = Configuration.TryParseCommandline(args); Console.WriteLine(config); if (!success) { Configuration.PrintUsage(); return((int)ExitCode.ErrorParseArgs); } if (config.Debug) { Console.WriteLine("Press any key to continue..."); Console.Read(); } Action <string> log = Console.WriteLine; IFixer fixer = config.DryRun ? (IFixer) new DryRunFixer(log) : new TierFixer(log); var client = Utils.CreateBlobClient(config.ConnectionString); IBlobProvider provider; if (config.BlobPath != null) { provider = new SpecifiedBlobProvider(client, config.ContainerName, log, config.BlobPath); } else { //provider = new AllBlobProvider(client, config.ContainerName, log); provider = new WarmBlobProvider(client, config.ContainerName, log); } int numBlobs = 0; List <CloudBlockBlob> blobs = new List <CloudBlockBlob>(config.MaxBlobs); foreach (var blob in provider.Provide()) { numBlobs++; if (numBlobs > config.MaxBlobs) { throw new InvalidOperationException($"Number of provided blobs exceeds the limit {config.MaxBlobs}"); } else { blobs.Add(blob); } } foreach (var blob in blobs) { fixer.Fix(blob); } } catch (Exception e) { Console.Error.WriteLine($"An error happened: {e.ToString()}"); return((int)ExitCode.Other); } return((int)ExitCode.OK); }
// Initializes a new instance of the FixerHost class. public FixerHost(IFixer fix) { this.fix = fix; }
public void Run( IGrabber grabber, IFixer fixer, IStaleSvnBranchDeleter svnBranchDeleter, IGitPusher gitPusher, ILockBreaker lockBreaker ) { if (grabber == null) { throw new ArgumentNullException(nameof(grabber)); } if (fixer == null) { throw new ArgumentNullException(nameof(fixer)); } if (svnBranchDeleter == null) { throw new ArgumentNullException(nameof(svnBranchDeleter)); } if (lockBreaker == null) { throw new ArgumentNullException(nameof(lockBreaker)); } try { PreRunPrepare(); lockBreaker.BreakLocksIfEnabled(); if (Options.Rebase) { grabber.FetchBranches(); } else if (!string.IsNullOrWhiteSpace(Options.RebaseBranch)) { grabber.FetchRebaseBraches(); } else { grabber.Clone(); } fixer.FixBranches(); fixer.FixTags(); fixer.FixTrunk(); fixer.OptimizeRepos(); if (Options.StaleSvnBranchPurgeOption != StaleSvnBranchPurgeOptions.nothing) { IEnumerable <string> svnBranches = svnBranchDeleter.QueryHeadSvnBranches(); IEnumerable <string> gitBranchesToPurge = svnBranchDeleter.GetGitBranchesToPurge(svnBranches); svnBranches = null; svnBranchDeleter.PurgeGitBranches(gitBranchesToPurge); gitBranchesToPurge = null; if (Options.StaleSvnBranchPurgeOption == StaleSvnBranchPurgeOptions.delete_local_and_remote) { gitPusher.PushPrune(); } } if (Options.PushWhenDone) { gitPusher.PushAll(); } } finally { PostRunCleanup(); } }
public ObjectField(String field_id, IFixer value) { this.FieldId = field_id; this.Value = value; }