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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DotNetExpansions.Forms; // For the fading MessageBox.
// You can get the code at
// http://dotnet-snippets.de/dns/fading-messagebox-ohne-buttons-SID694.aspx
// Or check out a copy of my DotNetExpansions project at // http://cyrons.svn.beanstalkapp.com/general/DotNetExpansions/trunk
namespace ConvertCode2HelpExample
{
public static class CodeConverter
{
// Facade
public static string ConvertTextToXmlExample(string text)
{
var lines = SplitText2LinesOf(text);
lines = PrependXmlCommentSignsTo(lines);
var result = Concatenate(lines);
result = PrependExampleHeaderTo(result);
return AppendExampleFooterTo(result);
}
private static IEnumerable<string> SplitText2LinesOf(string text)
{
char[] splitCharacters = { '\n' };
if(text == null)
return null;
string[] lines = text.Split(splitCharacters);
var query = lines.Select(value => value.TrimEnd('\r'));
return query;
}
public static void CopyToClipboard(string result)
{
try
{
Clipboard.SetDataObject(result, true);
IFadingMessageBox fmb = new FadingMessageBox();
fmb.ShowAndFade("Das Ergebnis wurde im Clipboard gespeichert.",
"Hinweis", 1.0, FadingMessageBox.FadingMessageBoxIcon.Information);
}
catch(Exception)
{
if(DialogResult.Retry ==
MessageBox.Show("Das System ist zur Zeit überlastet." +
" Der Clip wurde nicht gespeichert. Bitte noch einmal probieren.",
"FEHLER!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning))
{
CopyToClipboard(result);
}
}
}
private static IEnumerable<string> PrependXmlCommentSignsTo(IEnumerable<string> lines)
{
if(lines == null)
return null;
if(lines.Count() == 0)
return null;
var query = lines.Select(value => "/// " + value);
return query;
}
private static string Concatenate(IEnumerable<string> lines)
{
if(lines == null)
return null;
if(lines.Count() == 0)
return null;
string query = lines.Aggregate((build, line) => build + "\r\n" + line);
query += "\r\n";
return query;
}
private static string PrependExampleHeaderTo(string text)
{
const string exampleHeader = "/// <example>\r\n"
+ "/// <code>\r\n"
+ "/// <![CDATA[\r\n";
return exampleHeader + text;
}
private static string AppendExampleFooterTo(string text)
{
const string exampleFooter = "/// ]]>\r\n"
+ "/// </code>\r\n"
+ "/// </example>";
return text + exampleFooter;
}
}
}
|