public async Task Save(IEnumerable <RenderingResult> renderedItems) { output.Info($"Saving output to disk (items : {renderedItems.Count()})"); if (renderedItems.Any()) { int firstColmunWidth = renderedItems.Max(x => x.FilePath.Length) + 1; foreach (var item in renderedItems) { var filePathWithPadding = item.FilePath.PadRight(firstColmunWidth); if (!item.IsFilePathValid) { output.Error($"{filePathWithPadding} | File path is invalid"); continue; } var hasContentChanged = await HasContentChanged(item); if (hasContentChanged) { output.Info($"{filePathWithPadding} | File content has changed, saving to disk"); try { sourceControl.Checkout(item.FilePath); } catch (NotImplementedException ex) { output.Error(ex.Message); } await SaveToDisk(item); } else { output.Info($"{filePathWithPadding} | File content is the same. Skipping"); } } } output.Info("Saving output to disk completed"); }
private void UpgradeAssemblyFiles(IEnumerable<string> fileToModify,ISourceControl sourceControl,PatchInfo patchInfo) { Regex regex = null; Regex regexFileVersion = null; if (fileToModify.Any()) { regex = new Regex(@"assembly: AssemblyVersion\(""(\d+)\.(\d+)\.(\d+)\.(\d+)""\)",RegexOptions.Compiled); regexFileVersion = new Regex(@"assembly: AssemblyFileVersion\(""(\d+)\.(\d+)\.(\d+)\.(\d+)""\)", RegexOptions.Compiled); } List<string> filesModified = new List<string>(); foreach (var fileAssemblySetting in fileToModify) { var fileText = System.IO.File.ReadAllText(fileAssemblySetting); string newFile = fileText; var match = regex.Match(newFile); bool isCheckout = false; newFile = UpdateAssemblyFile(sourceControl, patchInfo.VersionPart, match, fileAssemblySetting, newFile, ref isCheckout); match = regexFileVersion.Match(newFile); newFile = UpdateAssemblyFile(sourceControl, patchInfo.VersionPart, match, fileAssemblySetting, newFile, ref isCheckout); if (isCheckout) { filesModified.Add(fileAssemblySetting); System.IO.File.WriteAllText(fileAssemblySetting, newFile); } } var versionControlFile = Path.Combine(patchInfo.FileSystemPath, VersionPathcerConsts.VersionControlFile); if (System.IO.File.Exists(versionControlFile)) { sourceControl.Checkout(versionControlFile); System.IO.File.WriteAllText(versionControlFile, string.Format("{0}{1}{2}", DateTime.Now, Environment.NewLine, string.Join(Environment.NewLine, filesModified))); } else { System.IO.File.WriteAllText(versionControlFile, string.Format("{0}{1}{2}", DateTime.Now, Environment.NewLine, string.Join(Environment.NewLine, filesModified))); sourceControl.Checkout(versionControlFile); } }
private string UpdateAssemblyFile(ISourceControl sourceControl, VersionPart versionPart, Match match, string fileAssemblySetting, string newFile, ref bool isCheckout) { if (match.Success) { if (!isCheckout) { sourceControl.Checkout(fileAssemblySetting); isCheckout = true; } do { var group = match.Groups[((int) versionPart) + 1]; int value = int.Parse(@group.Value); newFile = newFile.Substring(0, @group.Index) + (value + 1) + newFile.Substring(@group.Index + @group.Length); match = match.NextMatch(); } while (match.Success); } return newFile; }