public void Apply(int?templateId) { if (templateId == null) { return; } //var p = Path.Combine(webRootPath, $"content\\Template{templateId}\\patch\\patch.json"); var p = CLICFileUtils.GetTemplatePath(webRootPath, templateId.ToString(), TemplatePathType.Patch) + "\\patch.json"; var results = LoadPatchJson(p); ApplyPatch(results, templateId); }
private void ProcessAureliaPatch(PatchResult f, int templateId, string sourcePath) { var dRoot = Path.Combine(ContentRootPath, $"Content\\{templateId}\\destination"); var sRel = $"\\content\\{templateId}\\source\\"; var dRel = $"\\content\\{templateId}\\destination\\"; var fromPath = CLICFileUtils.GetTemplatePath(ContentRootPath, templateId.ToString(), TemplatePathType.Destination) + f.DestinationFile.Replace(dRel, ""); var mappedSourceFile = tfm.MapSourceFile(f.SourceFile); var toPath = Path.Combine(sourcePath, mappedSourceFile.Replace(sRel, ""));//need to map the sourcepath file (which can be of a different name) to the destination (patched) file: Eg/ MyProject1.sln > Site.sln var d = Path.GetDirectoryName(toPath); if (!Directory.Exists(d)) { Directory.CreateDirectory(d); } if (f.PatchResultType == PatchResultType.CopyFile && (!File.Exists(toPath))) { File.Copy(fromPath, toPath, true); Console.WriteLine($"Copying: {toPath}"); return; } if (f.PatchResultType == PatchResultType.Identical) { return; } if (f.PatchList == null) { return; } var content = File.ReadAllText(toPath); var dmp = new diff_match_patch(); var r = dmp.patch_apply(f.PatchList, content); //Apply any text transforms var newContent = r[0]; File.WriteAllText(toPath, newContent.ToString()); Console.WriteLine($"Patched: {toPath}"); }
//https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-iterate-through-a-directory-tree public List <PatchResult> GeneratePatchForTemplate(int?templateId) { if (templateId == null) { return(null); } patchResults = new List <PatchResult>(); //var p = Path.Combine(webRootPath, $"content\\{templateId}\\destination"); var p = CLICFileUtils.GetTemplatePath(webRootPath, templateId.ToString(), TemplatePathType.Destination); ProcessFolder(p); SavePatchJson(templateId); return(patchResults); }
private void SavePatchJson(int?templateId) { if (templateId == null) { return; } //var p = Path.Combine(webRootPath, $"content\\{templateId}\\patch\\"); var p = CLICFileUtils.GetTemplatePath(webRootPath, templateId.ToString(), TemplatePathType.Patch); var json = JsonConvert.SerializeObject(patchResults); if (!Directory.Exists(Path.GetDirectoryName(p))) { Directory.CreateDirectory(Path.GetDirectoryName(p)); } File.WriteAllText($"{p}\\patch.json", json); }
public void ApplyPatch(List <PatchResult> result, int?templateId) { if (templateId == null) { return; } //Copy over all original files first //var od = Path.Combine(webRootPath, $"content\\Template{templateId}\\source"); var od = CLICFileUtils.GetTemplatePath(webRootPath, templateId.ToString(), TemplatePathType.Source); //var fd = Path.Combine(webRootPath, $"content\\Template{templateId}\\patchedSource"); var fd = CLICFileUtils.GetTemplatePath(webRootPath, templateId.ToString()) + "\\patchedSource"; DirectoryCopy(od, fd, true); foreach (var f in result) { GeneratePatch(f); } }