public void GenerateFile(string filename, string scale, string title) { var cf = new PlantUmlResult(); WriteSkin(cf); cf.Top.Writeln("scale " + scale); if (!string.IsNullOrEmpty(title)) { cf.Top.Writeln("title"); cf.Top.Writeln(' ' + title); cf.Top.Writeln("end title"); } var iter = _types.OrderBy(a => a.Value.OrderIndex).Select(a => a.Key) .ToListCastOrConvert(_types.Count); var alreadyProcessed = new HashSet <Type>(); void Process1(IEnumerable <Type> typesList) { foreach (var t in typesList) { var list = AddTypeToGraph(cf, t, cf.relations, alreadyProcessed); Process1(list); } } Process1(iter); cf.SaveIfDifferent(filename); }
private static void WriteSkin(PlantUmlResult r) { var cf = r.Top; cf.Writeln("skinparam classFontSize 18"); cf.Writeln("skinparam class {"); cf.Writeln("FontSize 20"); cf.Writeln("ArrowFontSize 20"); cf.Writeln("FontName Buxton Sketch"); cf.Writeln("ArrowFontName Buxton Sketch"); cf.Writeln("BackgroundColor white"); cf.Writeln("BorderColor #000040"); cf.Writeln("}"); cf.Writeln("skinparam handwritten true"); }
private IEnumerable <Type> AddTypeToGraph(PlantUmlResult rr, Type t, List <UmlRelation> relations, HashSet <Type> processed) { var result = new List <Type>(); if (!_types.TryGetValue(t, out var info)) { return(result); } if (!processed.Add(t)) { return(result); } var cf = rr.Classes; cf.Open(GetClassOpen(t)); foreach (var pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (SkipDrawing(t, pi.DeclaringType)) { continue; } var att = pi.GetCustomAttribute <UmlRelationAttribute>(); var kind = att?.Kind ?? UmlRelationKind.AggregationWithArrow; var rel = FindRelation(pi.PropertyType, kind, att, pi.Name, t); if (rel != null) { relations.Add(rel); result.Add(pi.PropertyType); continue; } cf.Writeln(GetTypeName(pi.PropertyType) + " " + pi.Name); } foreach (var mi in t.GetMethods(BindingFlags.Instance | BindingFlags.Public)) { if (mi.IsSpecialName) { continue; } if (mi.DeclaringType == typeof(object)) { continue; } if (SkipDrawing(t, mi.DeclaringType)) { continue; } cf.Writeln(MethodToUml(mi)); var att = mi.GetCustomAttribute <UmlRelationAttribute>(); if (att != null) { var kind = att.Kind; var rel = FindRelation(mi.ReturnType, kind, att, mi.Name + "() >", t); if (rel != null) { var a = rel.Arrow; a.Dotted = true; rel.Arrow = a; relations.Add(rel); result.Add(mi.ReturnType); } } } foreach (var i in t.GetCustomAttributes <UmlAddRelationAttribute>()) { var rel = new UmlRelation { Left = new UmlRelationEnd(GetTypeName(t)), Right = new UmlRelationEnd(GetTypeName(i.RelatedType)), Arrow = UmlRelationArrow.GetRelationByKind(i.Kind), Label = i.Name, Note = i.Note, NoteColor = i.NoteColor }; relations.Add(rel); } cf.Close(); foreach (var i in t.GetCustomAttributes <UmlNoteAttribute>()) { // cf.Writeln("-- note --"); cf.Writeln("note bottom of " + GetTypeName(t)); foreach (var line in i.Text.Split('\n', '\r')) { if (!string.IsNullOrEmpty(line)) { cf.Writeln(line); } } cf.Writeln("end note"); } if (t.BaseType != null && _types.ContainsKey(t.BaseType)) { relations.Add(Inherits(t.BaseType, t).With(UmlArrowDirections.Up)); } foreach (var i in t.GetInterfaces()) { if (_types.ContainsKey(i)) { relations.Add(Inherits(i, t).With(UmlArrowDirections.Up)); } } return(result); }