/
DocumentationBuilder.cs
156 lines (131 loc) · 5.37 KB
/
DocumentationBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Text;
using System.Windows.Forms;
using SwqlStudio.Metadata;
namespace SwqlStudio
{
internal class DocumentationBuilder
{
public static Documentation Build(TreeNode node)
{
var data = node.Tag;
var connectedNode = node as TreeNodeWithConnectionInfo;
var provider = connectedNode?.Provider;
if (provider == null)
return Documentation.Empty;
if (data is SwisMetaDataProvider)
return ProviderDocumentation(provider);
if (data is string nameSpace)
return NamespaceDocumentation(nameSpace, node.Nodes.Count);
if (data is Entity entity)
return EntityDocumentation(provider, entity);
if (data is Property property)
return PropertyDocumentation(property);
if (data is Verb verb)
return VerbDocumentation(verb);
if (data is VerbArgument verbArg)
return VerbArgumentDocumentation(verbArg);
return Documentation.Empty;
}
private static Documentation VerbArgumentDocumentation(VerbArgument verbArg)
{
var docs = MetadataDocumentation(verbArg);
return new Documentation("Verb argument", docs);
}
private static Documentation VerbDocumentation(Verb verb)
{
var builder = new StringBuilder();
builder.AppendName(verb.Name);
builder.AppendObsoleteSection(verb);
builder.AppendSummaryParagraph(verb.Summary);
var docs = builder.ToString();
return new Documentation("Verb", docs);
}
private static Documentation EntityDocumentation(IMetadataProvider provider, Entity entity)
{
var builder = new StringBuilder();
builder.AppendName(entity.FullName);
builder.Append($"Base type: {entity.BaseType}\r\n");
builder.AppendAccessControl(provider.ConnectionInfo, entity);
builder.AppendObsoleteSection(entity);
builder.AppendSummaryParagraph(entity.Summary);
var docs = builder.ToString();
return new Documentation("Entity", docs);
}
private static Documentation NamespaceDocumentation(string nameSpace, int childrenCount)
{
var builder = new StringBuilder();
builder.AppendName(nameSpace);
var children = ChildrenText(childrenCount);
builder.Append(children);
var docs = builder.ToString();
return new Documentation("Namespace", docs);
}
private static Documentation PropertyDocumentation(Property property)
{
var builder = new StringBuilder();
builder.Append(MetadataDocumentation(property));
builder.AppendObsoleteSection(property);
return new Documentation("Property", builder.ToString());
}
private static Documentation ProviderDocumentation(IMetadataProvider provider)
{
var documents = $@"Connection: {provider.Name}";
return new Documentation("Database", documents);
}
private static string MetadataDocumentation(ITypedMetadata metadata)
{
var builder = new StringBuilder();
builder.AppendName(metadata.Name);
builder.AppendType(metadata.Type);
builder.AppendSummaryParagraph(metadata.Summary);
return builder.ToString();
}
public static string ToToolTip(ITypedMetadata metadata)
{
var builder = new StringBuilder();
builder.AppendSummary(metadata.Summary);
return builder.ToString();
}
public static string ToToolTip(ITypedMetadata metadata, IObsoleteMetadata obsoleteMetadata)
{
var builder = new StringBuilder();
builder.AppendSummary(metadata.Summary);
builder.AppendObsoleteSection(obsoleteMetadata);
return builder.ToString();
}
public static string ToToolTip(ConnectionInfo connection, Entity entity)
{
var builder = new StringBuilder();
builder.AppendSummary(entity.Summary);
builder.AppendObsoleteSection(entity);
return builder.ToString();
}
public static string ToToolTip(Verb verb)
{
var builder = new StringBuilder();
builder.AppendSummary(verb.Summary);
builder.AppendObsoleteSection(verb);
return builder.ToString();
}
public static string ToNodeText(string name, int childrenCount)
{
var children = ChildrenText(childrenCount);
return $"{name} ({children})";
}
private static string ChildrenText(int childrenCount)
{
var countSuffix = childrenCount > 1 ? "s" : String.Empty;
return $"{childrenCount} item{countSuffix}";
}
public static string ToNodeText(ITypedMetadata metadata)
{
return $"{metadata.Name} ({metadata.Type})";
}
public static string ToBaseNodeText(TreeNode baseNode, int childrenCount)
{
var entitiesSuffix = childrenCount > 1 ? "ies" : "y";
return $"{baseNode.Text} ({childrenCount} derived entit{entitiesSuffix})";
}
}
}