~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-tools/webdoc/monodoc.asmx

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<%@ WebService language="C#" class="Editing" %>
2
 
 
3
 
// MonoDoc Editing WebService
4
 
//
5
 
// (C) 2003 by Johannes Roith
6
 
// Author: Johannes Roith
7
 
 
8
 
// Client API:
9
 
//
10
 
// Editing edit = new Editing();
11
 
// Response response = edit.Submit("Johannes Roith", "johannes@jroith.de",
12
 
//                      "This is a change through monodoc editing.", xml);
13
 
 
14
 
// response contains:
15
 
// a server status message (response.Message)
16
 
// a statuscode (response.Status)
17
 
 
18
 
// Statuscodes:
19
 
//
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
25
 
 
26
 
 
27
 
using System;
28
 
using System.Web.Services;
29
 
using System.Xml.Serialization;
30
 
using System.Xml;
31
 
using System.Text;
32
 
using System.Security.Cryptography;
33
 
 
34
 
[WebService(Namespace="http://www.go-mono.org/monodoc")]
35
 
public class Editing {
36
 
 
37
 
    [WebMethod]
38
 
    public Response Submit(string author, string email, string personalmessage, string xmldata) {
39
 
 
40
 
        Response response;
41
 
        string newsum = GetMd5Sum(xmldata);
42
 
        XmlElement dataroot;
43
 
        XmlDocument oldposts;
44
 
        string today = Convert.ToString(DateTime.Now.DayOfYear);
45
 
 
46
 
        try {
47
 
 
48
 
 
49
 
        oldposts = new XmlDocument();
50
 
        oldposts.Load("oldposts.xml");
51
 
 
52
 
        dataroot = oldposts.DocumentElement;
53
 
 
54
 
        // Eventually only block in certain time frame?
55
 
        // XmlNodeList datanodes = dataroot.SelectNodes("/oldposts/post[@date='" + today + "']");
56
 
 
57
 
        XmlNodeList datanodes = dataroot.SelectNodes("/oldposts/post");
58
 
 
59
 
        foreach(XmlNode datanode in datanodes) {
60
 
            if (datanode.Attributes["md5"].Value == newsum) {
61
 
 
62
 
                response = new Response();
63
 
                response.Status = 4;
64
 
                response.Message = "This was already posted.";
65
 
 
66
 
                return response;
67
 
            }
68
 
        }
69
 
 
70
 
        if (xmldata == "")
71
 
        {
72
 
 
73
 
            response = new Response();
74
 
            response.Status = 2;
75
 
            response.Message = "Xml not well-formed. No data was posted.";
76
 
 
77
 
            return response;
78
 
        }
79
 
 
80
 
        XmlDocument doc = new XmlDocument();
81
 
        doc.LoadXml(xmldata);
82
 
 
83
 
        XmlElement root = doc.DocumentElement;
84
 
        XmlNodeList nodes = root.SelectNodes("/GlobalChangeset/DocSetChangeset");
85
 
 
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.
89
 
 
90
 
        foreach (XmlNode node in nodes) {
91
 
 
92
 
            string datastring = "";
93
 
 
94
 
            XmlNodeList filenodes = node.SelectNodes("FileChangeset");
95
 
 
96
 
 
97
 
           foreach (XmlNode filenode in filenodes) {
98
 
            datastring += RenderFileSet(filenode);
99
 
           }
100
 
 
101
 
            string target = node.Attributes["DocSet"].Value;
102
 
 
103
 
            string header = "---------------------\n"
104
 
                        + "MonoDoc Change\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";
114
 
 
115
 
            string footer = "\n\n---------------------------------------\n"
116
 
                          + "Monodoc Editing WebService";
117
 
 
118
 
            SendMail("Monodoc: " + target, header + datastring + footer);
119
 
        }
120
 
 
121
 
        }
122
 
 
123
 
        catch {
124
 
 
125
 
            response = new Response();
126
 
            response.Status = 5;
127
 
            response.Message = "An unknown error occured.";
128
 
 
129
 
            return response;
130
 
 
131
 
        }
132
 
 
133
 
 
134
 
        XmlNode rootnode = dataroot.SelectSingleNode("/oldposts");
135
 
 
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");
141
 
 
142
 
        response = new Response();
143
 
        response.Status = 1;
144
 
        response.Message = "Your changes were sent to Mono Docs List.\n"
145
 
                        + "They will be reviewed as soon as possible.";
146
 
 
147
 
        return response;
148
 
 
149
 
    }
150
 
 
151
 
    string RenderFileSet(XmlNode filenode) {
152
 
 
153
 
    // Rendering should be improved eventually,
154
 
    // so no xml remains.
155
 
 
156
 
       return "FILE: " + filenode.Attributes["RealFile"] + "\n\n"
157
 
                  + filenode.InnerXml
158
 
                  + "\n\n*************************************\n\n";
159
 
    }
160
 
 
161
 
    public class Response {
162
 
 
163
 
        public int Status;
164
 
        public string Message;
165
 
    }
166
 
 
167
 
    public void SendMail(string subject, string body) {
168
 
 
169
 
        System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();
170
 
 
171
 
        // NOTE: I have made this "groith@tcrz.net", 
172
 
        //       so it won't be blocked.
173
 
        //       Should be changed later.
174
 
 
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;
180
 
 
181
 
        System.Web.Mail.SmtpMail.SmtpServer = "post.tcrz.net";
182
 
        System.Web.Mail.SmtpMail.Send(mailMessage);
183
 
 
184
 
 
185
 
    }
186
 
 
187
 
    // from http://weblog.stevex.org/radio/stories/2002/12/08/
188
 
    //      cCodeSnippetCreatingAnMd5HashString.html
189
 
 
190
 
    public string GetMd5Sum(string str)
191
 
    {
192
 
        Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
193
 
 
194
 
        byte[] unicodeText = new byte[str.Length * 2];
195
 
        enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
196
 
 
197
 
        MD5 md5 = new MD5CryptoServiceProvider();
198
 
        byte[] result = md5.ComputeHash(unicodeText);
199
 
 
200
 
        StringBuilder sb = new StringBuilder();
201
 
        for (int i=0;i<result.Length;i++)
202
 
        {
203
 
            sb.Append(result[i].ToString("X2"));
204
 
        }
205
 
 
206
 
        return sb.ToString();
207
 
}
208
 
 
209
 
 
210
 
}