-
Notifications
You must be signed in to change notification settings - Fork 0
/
QvSvnLogConnection.cs
97 lines (82 loc) · 3.21 KB
/
QvSvnLogConnection.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Created by SharpDevelop. Licensed under Apache License 2.0, see license.txt for more information.
* User: Miku Laitinen
* Date: 9.11.2012
* Time: 11:33
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using QlikView.Qvx.QvxLibrary;
using SharpSvn;
namespace QvSvnLogConnector
{
/// <summary>
/// Defines the table structure and initializes the connection.
/// </summary>
public class QvSvnLogConnection : QvxConnection
{
public override void Init()
{
QvxLog.SetLogLevels(true, true);
QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Init()");
QvxField[] svnLogFields = new QvxField[]
{
new QvxField("Author", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
new QvxField("LogMessage", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
new QvxField("Revision", QvxFieldType.QVX_SIGNED_INTEGER, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.INTEGER),
new QvxField("Time", QvxFieldType.QVX_IEEE_REAL, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.DATE)
};
MTables = new List<QvxTable>
{
new QvxTable
{
TableName = "SvnLogEntries",
GetRows = GetSvnLogEntries,
Fields = svnLogFields
}
};
}
/// <summary>
/// Gets the svn log entries from the repository.
/// </summary>
/// <returns>An IEnumerable of the QvxDataRows.</returns>
private IEnumerable<QvxDataRow> GetSvnLogEntries()
{
QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetSvnLogEntries()");
string username, password, server;
this.MParameters.TryGetValue("UserId", out username);
this.MParameters.TryGetValue("Password", out password);
this.MParameters.TryGetValue("Server", out server);
System.Net.NetworkCredential creds = new System.Net.NetworkCredential(username, password);
SvnClient client = new SvnClient();
client.Authentication.DefaultCredentials = creds;
SvnUriTarget target = new SvnUriTarget(server);
Collection<SvnLogEventArgs> logEntries = new Collection<SvnLogEventArgs>();
bool result = client.GetLog(target.Uri, out logEntries);
if(!result)
{
throw new SvnClientException("Retrieving Subversion log failed");
}
foreach(SvnLogEventArgs entry in logEntries)
{
yield return MakeEntry(entry, FindTable("SvnLogEntries", MTables));
}
}
/// <summary>
/// Creates a Qvx data entry from an Svn log entry.
/// </summary>
/// <param name="item">The Svn log entry to be used as a source</param>
/// <param name="table">The destination Qvx table</param>
/// <returns>The resulting row</returns>
private QvxDataRow MakeEntry(SvnLogEventArgs entry, QvxTable table)
{
QvxDataRow row = new QvxDataRow();
row[table.Fields[0]] = entry.Author;
row[table.Fields[1]] = entry.LogMessage;
row[table.Fields[2]] = entry.Revision;
row[table.Fields[3]] = entry.Time.ToOADate();
return row;
}
}
}