-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvnMethods.cs
280 lines (250 loc) · 8.21 KB
/
svnMethods.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using System;
using System.Windows.Forms;
using SharpSvn;
using System.Threading;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace ModSync
{
/// <summary>
/// Description of svnMethods.
/// </summary>
public class svnMethods
{
public svnMethods()
{
checkIfReachable(Properties.Settings.Default.svnserver);
}
SvnUpdateResult result;
private volatile bool _shouldStop;
private bool _done = false;
public bool _IsReachable;
public bool done {
get
{
return _done;
}
set
{
_done = value;
}
}
public void RequestStop()
{
_shouldStop = true;
}
public void endThread()
{
checkout.Abort();
}
public Thread checkout;
delegate void delegateVoid();
public void startUpdate(Uri from, string to) {
if (_IsReachable)
{
if (!IsWorkingCopy(to))
{
checkout = new Thread(new ThreadStart(() => svnCheckout(from, to)));
}
else
{
checkout = new Thread(new ThreadStart(() => svnUpdate(to)));
}
checkout.Start();
while (!checkout.IsAlive) ;
}
else
{
MessageBox.Show("Der Server '" + Properties.Settings.Default.svnserver + "' konnte nicht erreicht werden.");
}
}
private int retrys = 0;
private void svnUpdate(string target_repo)
{
while (!_shouldStop)
{
using (SvnClient client = new SvnClient())
{
try
{
client.Progress += new EventHandler<SvnProgressEventArgs>(cl_Progress);
SvnUpdateArgs sua = new SvnUpdateArgs();
sua.AllowObstructions = true;
//sua.Depth = SvnDepth.Infinity;
SvnUpdateResult result;
client.Update(target_repo, sua, out result);
}
catch (SvnException se)
{
if (retrys < 2)
{
performCleanup(client, target_repo);
svnUpdate(target_repo);
retrys++;
}
else
{
MessageBox.Show("Ein Fehler ist aufgetreten:" + se.Message);
}
}
SvnRevertArgs sra = new SvnRevertArgs();
sra.Depth = SvnDepth.Infinity;
client.Revert(target_repo, sra);
}
this.RequestStop();
}
_done = true;
_shouldStop = false;
}
private void notifyme(object sender, SvnNotifyEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Action.ToString());
}
private void svnCheckout(Uri from, string to) {
while (!_shouldStop) {
using (SvnClient client = new SvnClient()) {
try
{
client.Progress += new EventHandler<SvnProgressEventArgs>(cl_Progress);
//client.Notify += new EventHandler<SvnNotifyEventArgs>(notifyme);
SvnCheckOutArgs sco = new SvnCheckOutArgs();
//sco.Depth = SvnDepth.Infinity;
sco.AllowObstructions = false;
client.CheckOut(from, to, out result);
}
catch (SvnException se)
{
if (retrys < 2)
{
performCleanup(client, to);
svnCheckout(from, to);
retrys++;
}
else
{
MessageBox.Show("Ein Fehler ist aufgetreten:" + se.Message);
}
}
SvnRevertArgs sra = new SvnRevertArgs();
sra.Depth = SvnDepth.Infinity;
client.Revert(to, sra);
}
this.RequestStop();
}
_done = true;
_shouldStop = false;
}
private void performCleanup(SvnClient client, string to) {
try
{
client.CleanUp(to);
}
catch (SvnException svne)
{
MessageBox.Show(svne.Message);
}
}
public List<SvnListEventArgs> getFiles()
{
bool gotList;
List<SvnListEventArgs> files = new List<SvnListEventArgs>();
using (SvnClient client = new SvnClient())
{
System.Collections.ObjectModel.Collection<SvnListEventArgs> list;
gotList = client.GetList(Properties.Settings.Default.svnserver, out list);
if (gotList)
{
foreach (SvnListEventArgs item in list)
{
files.Add(item);
}
}
}
return files;
}
private SvnProgressEventArgs progress;
private void cl_Progress(object sender, SvnProgressEventArgs e) {
progress = e;
}
public SvnProgressEventArgs getProgress() {
return progress;
}
public static bool IsWorkingCopy(string path)
{
using (SvnClient client = new SvnClient())
{
var uri = client.GetUriFromWorkingCopy(path);
return uri != null;
}
}
public void checkIfReachable(string remote_repo)
{
if (remote_repo != "" && remote_repo != null)
{
SvnInfoEventArgs repo;
using (SvnClient client = new SvnClient())
{
try
{
client.GetInfo(remote_repo, out repo);
_IsReachable = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
_IsReachable = false;
}
}
}
else
{
_IsReachable = false;
}
}
public SvnInfoEventArgs[] svnGetDiff(string local_repo, string remote_repo)
{
SvnInfoEventArgs[] repos = new SvnInfoEventArgs[2];
if (_IsReachable)
{
using (SvnClient client = new SvnClient())
{
if (IsWorkingCopy(local_repo))
{
client.GetInfo(local_repo, out repos[0]);
client.GetInfo(remote_repo, out repos[1]);
}
else
{
repos[0] = null;
client.GetInfo(remote_repo, out repos[1]);
}
}
}
else
{
MessageBox.Show("Der Server '" + Properties.Settings.Default.svnserver + "' konnte nicht erreicht werden.");
}
return repos;
}
public Collection<SvnLogEventArgs> GetLatestCommitMessages(Uri repository, int count)
{
System.Collections.ObjectModel.Collection<SvnLogEventArgs> logEntries = null;
if (_IsReachable)
{
using (var client = new SvnClient())
{
var args = new SvnLogArgs()
{
Limit = count
};
client.GetLog(repository, args, out logEntries);
}
}
else
{
MessageBox.Show("Der Server '" + Properties.Settings.Default.svnserver + "' konnte nicht erreicht werden.");
}
return logEntries;
}
}
}