public void UpdateIssue(IssueUpdate update, NetworkCredential credential,
Action<string> stdout, Action<string> stderr)
{
var client = new WebClient();
if (token == null)
{
System.Collections.Specialized.NameValueCollection data = new System.Collections.Specialized.NameValueCollection(1);
data.Add("accountType", "GOOGLE");
data.Add("Email", credential.UserName);
data.Add("Passwd", credential.Password);
data.Add("service", "code");
data.Add("source", "opensource-gurtlereloaded-1");
string[] result = ByteArrayToString(client.UploadValues("https://www.google.com/accounts/ClientLogin", data)).Split('\n');
for (int i = 0; i < result.Length; i++)
{
if (result[i].StartsWith("auth=", StringComparison.InvariantCultureIgnoreCase))
{
token = result[i];
break;
}
}
}
var doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(dec);
XmlSchema schema = new XmlSchema();
schema.Namespaces.Add("xmlns", "http://www.w3.org/2005/Atom");
schema.Namespaces.Add("issues", "http://schemas.google.com/projecthosting/issues/2009");
doc.Schemas.Add(schema);
XmlElement entry = doc.CreateElement("entry", "http://www.w3.org/2005/Atom");
doc.AppendChild(entry);
XmlElement author = doc.CreateElement("author", "http://www.w3.org/2005/Atom");
entry.AppendChild(author);
XmlElement name = doc.CreateElement("name", "http://www.w3.org/2005/Atom");
name.InnerText = "empty";
author.AppendChild(name);
if (update.Comment.Length > 0)
{
XmlElement content = doc.CreateElement("content", "http://www.w3.org/2005/Atom");
XmlAttribute contentType = doc.CreateAttribute("type");
contentType.InnerText = "html";
content.Attributes.Append(contentType);
content.InnerText = update.Comment;
entry.AppendChild(content);
}
XmlElement updates = doc.CreateElement("issues", "updates", "http://schemas.google.com/projecthosting/issues/2009");
entry.AppendChild(updates);
XmlElement status = doc.CreateElement("issues", "status", "http://schemas.google.com/projecthosting/issues/2009");
status.InnerText = update.Status;
updates.AppendChild(status);
client.Headers.Add("Content-Type", "application/atom+xml");
client.Headers.Add("Authorization", "GoogleLogin " + token);
client.UploadString(new Uri("https://code.google.com/feeds/issues/p/" + ProjectName + "/issues/"+ update.Issue.Id +"/comments/full"), doc.InnerXml);
}