protected void Patch(IEnumerable<String> paths, FrameworkEntity e, IEnumerable<PatchReplace> replacements) { foreach (var path in paths) { if (!File.Exists (path)) { continue; } this.Log (Level.Verbose, String.Format ("Probing '{0}'...", e.name)); String contents = File.ReadAllText (path); bool modified = false; foreach (PatchReplace replacement in replacements) { String source = replacement.Source; String with = replacement.With; if (contents.Contains (source)) { contents = contents.Replace (source, with); modified |= true; } } if (modified) { this.Log (Level.Info, String.Format ("Patching '{0}'...", e.name)); File.WriteAllText (path, contents); } else { this.Log (Level.Verbose, String.Format ("Skipping '{0}'...", e.name)); } } }
protected void PatchDiscussion(String baseFolder, DocSet docSet, Framework f, FrameworkEntity entity) { String path = entity.GetPath (baseFolder, this.Type); if (path == null || !File.Exists(path)) { return; } String contents = File.ReadAllText (path); bool modified = false; // Search for discussion parts int index = 0; int beginning = 0; int ending = 0; while ((beginning = contents.IndexOf(DISCUSSION_BEGIN, index)) != -1) { ending = contents.IndexOf (DISCUSSION_END, beginning); String content = contents.Substring (beginning, ending + DISCUSSION_END.Length - beginning); String replacement = content; // Count opening and closing paragraphs int opening = DISCUSSION_OPENING_REGEX.Matches (replacement).Count; int closing = DISCUSSION_CLOSING_REGEX.Matches (replacement).Count; if (opening < closing) { throw new NotSupportedException (); } if (opening > closing) { replacement = replacement.Replace ("<!-- begin discussion -->", String.Empty); replacement = replacement.Replace ("<!-- end discussion -->", String.Empty); for (int i = closing; i < opening; i++) { replacement += "</p>"; } replacement = "<!-- begin discussion -->" + replacement; replacement = replacement + "<!-- end discussion -->"; contents = contents.Replace (content, replacement); modified |= true; } index = beginning + replacement.Length; } if (modified) { this.Log (Level.Info, String.Format ("Patching {0} for '{1}'...", this.Type, entity.name)); File.WriteAllText (path, contents); } else { this.Log (Level.Debug, String.Format ("Skipping {0} for '{1}'...", this.Type, entity.name)); } }
public static void CopyDocument(this FrameworkEntity entity, String baseFolder, DocumentType sourceType, DocumentType destinationType) { if (entity == null) { throw new ArgumentNullException("entity"); } String sourcePath = entity.GetPath(baseFolder, sourceType); String destintationPath = entity.GetPath(baseFolder, destinationType); if (!File.Exists(sourcePath)) { // Do nothing } else if (!File.Exists(destintationPath)) { File.Copy(sourcePath, destintationPath, true); } else if (File.GetLastWriteTimeUtc(destintationPath) < File.GetLastWriteTimeUtc(sourcePath)) { File.Copy(sourcePath, destintationPath, true); } }
protected void Patch(String baseFolder, FrameworkEntity entity, IEnumerable<PatchReplace> replacements) { String path = entity.GetPath (baseFolder, this.Type); if (path == null) { return; } IList<String> paths = new List<String>(); switch(this.Type) { case DocumentType.Generated: paths.Add(path + ".cs"); paths.Add(path + ".Class.cs"); paths.Add(path + ".Constants.cs"); paths.Add(path + ".Constructors.cs"); paths.Add(path + ".Protocol.cs"); paths.Add(path + ".Protocols.cs"); break; default: paths.Add(path); break; } this.Patch(paths, entity, replacements); }
private IXhtmlTypeParser GetTypeParser(Framework f, FrameworkEntity e, TextWriter writer) { switch (f.style) { case PageStyle.Cocoa: return new XhtmlCocoaTypeParser (this.settings, this.typeManager, writer); case PageStyle.Classic: return new XhtmlClassicTypeParser (this.settings, this.typeManager, writer); case PageStyle.Doxygen: return new XhtmlDoxygenTypeParser (this.settings, this.typeManager, writer); default: throw new NotSupportedException ("No style defined for " + f.name); } }
private void Convert(Framework f, FrameworkEntity e, String sourcePath, String destinationPath, TextWriter writer = null) { switch (e.type) { case FrameworkEntityType.T: { IXhtmlTypeParser parser = this.GetTypeParser (f, e, writer); TypedEntity entity = new TypedEntity (); entity.Namespace = f.name; entity.Name = e.name; entity.Nature = e.type; parser.Parse (entity, sourcePath); entity.SaveTo (destinationPath); } break; case FrameworkEntityType.C: { IXhtmlClassParser parser = this.GetClassParser (f, e, writer); ClassEntity entity = new ClassEntity (); entity.Namespace = f.name; entity.Name = e.name; entity.Nature = e.type; parser.Parse (entity, sourcePath); entity.SaveTo (destinationPath); } break; case FrameworkEntityType.P: { IXhtmlClassParser parser = this.GetProtocolParser (f, e, writer); ProtocolEntity entity = new ProtocolEntity (); entity.Namespace = f.name; entity.Name = e.name; entity.Nature = e.type; parser.Parse (entity, sourcePath); entity.SaveTo (destinationPath); } break; default: break; } }