1
<%@ WebService language="C#" class="Editing" %>
3
// MonoDoc Editing WebService
5
// (C) 2003 by Johannes Roith
6
// Author: Johannes Roith
10
// Editing edit = new Editing();
11
// Response response = edit.Submit("Johannes Roith", "johannes@jroith.de",
12
// "This is a change through monodoc editing.", xml);
15
// a server status message (response.Message)
16
// a statuscode (response.Status)
20
// 1 - everything went right
21
// 2 - the xml is not well-formed.
22
// 3 - some data is missing (email, name, etc.).
23
// 4 - the data was already posted
24
// 5 - Some internal Server error
28
using System.Web.Services;
29
using System.Xml.Serialization;
32
using System.Security.Cryptography;
34
[WebService(Namespace="http://www.go-mono.org/monodoc")]
35
public class Editing {
38
public Response Submit(string author, string email, string personalmessage, string xmldata) {
41
string newsum = GetMd5Sum(xmldata);
44
string today = Convert.ToString(DateTime.Now.DayOfYear);
49
oldposts = new XmlDocument();
50
oldposts.Load("oldposts.xml");
52
dataroot = oldposts.DocumentElement;
54
// Eventually only block in certain time frame?
55
// XmlNodeList datanodes = dataroot.SelectNodes("/oldposts/post[@date='" + today + "']");
57
XmlNodeList datanodes = dataroot.SelectNodes("/oldposts/post");
59
foreach(XmlNode datanode in datanodes) {
60
if (datanode.Attributes["md5"].Value == newsum) {
62
response = new Response();
64
response.Message = "This was already posted.";
73
response = new Response();
75
response.Message = "Xml not well-formed. No data was posted.";
80
XmlDocument doc = new XmlDocument();
83
XmlElement root = doc.DocumentElement;
84
XmlNodeList nodes = root.SelectNodes("/GlobalChangeset/DocSetChangeset");
86
// IMO it's best to generate different Mails for
87
// different DocSets, so the correct people can get their hands on it.
88
// e.g one mail for Gtk#, one for ecma docs.
90
foreach (XmlNode node in nodes) {
92
string datastring = "";
94
XmlNodeList filenodes = node.SelectNodes("FileChangeset");
97
foreach (XmlNode filenode in filenodes) {
98
datastring += RenderFileSet(filenode);
101
string target = node.Attributes["DocSet"].Value;
103
string header = "---------------------\n"
105
+ "---------------------\n\n"
106
+ "This mail was generated by monodoc.\n\n"
107
+ "--------------------------------------------------\n"
108
+ "Author: " + author + "\n"
109
+ "EMail: " + email + "\n"
110
+ "personal Message: " + personalmessage + "\n\n"
111
+ "--------------------------------------------------\n\n"
112
+ "Changes are listed below:\n\n"
113
+ "*************************************\n\n";
115
string footer = "\n\n---------------------------------------\n"
116
+ "Monodoc Editing WebService";
118
SendMail("Monodoc: " + target, header + datastring + footer);
125
response = new Response();
127
response.Message = "An unknown error occured.";
134
XmlNode rootnode = dataroot.SelectSingleNode("/oldposts");
136
XmlElement newentry = oldposts.CreateElement("post");
137
newentry.SetAttribute("md5", newsum);
138
newentry.SetAttribute("date", today);
139
rootnode.AppendChild(newentry);
140
oldposts.Save("oldposts.xml");
142
response = new Response();
144
response.Message = "Your changes were sent to Mono Docs List.\n"
145
+ "They will be reviewed as soon as possible.";
151
string RenderFileSet(XmlNode filenode) {
153
// Rendering should be improved eventually,
154
// so no xml remains.
156
return "FILE: " + filenode.Attributes["RealFile"] + "\n\n"
158
+ "\n\n*************************************\n\n";
161
public class Response {
164
public string Message;
167
public void SendMail(string subject, string body) {
169
System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();
171
// NOTE: I have made this "groith@tcrz.net",
172
// so it won't be blocked.
173
// Should be changed later.
175
mailMessage.From = "groith@tcrz.net";
176
mailMessage.To = "mono-docs-list@ximian.com";
177
mailMessage.Subject = subject;
178
mailMessage.Body = body;
179
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text;
181
System.Web.Mail.SmtpMail.SmtpServer = "post.tcrz.net";
182
System.Web.Mail.SmtpMail.Send(mailMessage);
187
// from http://weblog.stevex.org/radio/stories/2002/12/08/
188
// cCodeSnippetCreatingAnMd5HashString.html
190
public string GetMd5Sum(string str)
192
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
194
byte[] unicodeText = new byte[str.Length * 2];
195
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
197
MD5 md5 = new MD5CryptoServiceProvider();
198
byte[] result = md5.ComputeHash(unicodeText);
200
StringBuilder sb = new StringBuilder();
201
for (int i=0;i<result.Length;i++)
203
sb.Append(result[i].ToString("X2"));
206
return sb.ToString();