/
BuildMapper.cs
70 lines (57 loc) · 2.24 KB
/
BuildMapper.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
using System;
using System.Xml;
using Hudson.Domain;
using Hudson.Extensions;
namespace Hudson.Mappers
{
/// <summary>
/// Creates a new <see cref="Build"/> object from some XML.
/// </summary>
public class BuildMapper
{
/// <summary>
/// Maps the specified XML into a <see cref="Build"/> object.
/// </summary>
/// <param name="xml">The XML.</param>
/// <returns></returns>
public Build Map(XmlDocument xml)
{
Build build = null;
if (xml != null)
{
build = new Build
{
Description = xml.Find("//shortDescription"),
Building = bool.Parse(xml.Find("//building")),
Duration = xml.FindInteger("//duration"),
FullDisplayName = xml.Find("//fullDisplayName"),
KeepLog = bool.Parse(xml.Find("//keepLog")),
Number = xml.FindInteger("//number"),
Success = xml.Find("//result") == "SUCCESS",
Url = new Uri(xml.Find("//url")),
User = xml.FindLast("//author//fullName")
};
// Hudson Properties
DateTime created;
if (DateTime.TryParse(xml.Find("//date"), out created))
{
build.Created = created;
}
var seconds = Convert.ToDouble(xml.Find("//timestamp"));
build.Created = JavaTimeStampToDateTime(seconds);
// GIT Properties
var rev = xml.Find("//lastBuiltRevision//SHA1");
build.Revision = rev.Length > 5 ? rev.Substring(0, 5) : rev;
build.Comments = xml.FindLast("//msg");
}
return build;
}
public static DateTime JavaTimeStampToDateTime(double javaTimeStamp)
{
// Java timestamp is millisecods past epoch
var dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
dtDateTime = dtDateTime.AddSeconds(Math.Round(javaTimeStamp / 1000)).ToLocalTime();
return dtDateTime;
}
}
}