Skip to content

Commit a67d35a

Browse files
authored
Merge pull request #14 from ahwm/develop
Fixed a few references, fixed SVN calls
2 parents a1ed144 + 9b19b5c commit a67d35a

File tree

8 files changed

+71
-36
lines changed

8 files changed

+71
-36
lines changed

src/SvnManager.WebUI/Bootstrapper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class Bootstrapper: DefaultNancyBootstrapper
1919
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
2020
{
2121
base.ApplicationStartup(container, pipelines);
22+
pipelines.OnError += (ctx, ex) =>
23+
{
24+
Notification.SendError(ex);
25+
return null;
26+
};
2227
//CookieBasedSessions.Enable(pipelines);
2328

2429
//var cryptographyConfiguration = new CryptographyConfiguration(new RijndaelEncryptionProvider(new PassphraseKeyGenerator("k60S3wal**7I2IVD$n1V", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })), new DefaultHmacProvider(new PassphraseKeyGenerator("51t!1w2DH^Ge$iR8G^4w", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })));
@@ -53,7 +58,7 @@ void OnConfigurationBuilder(NancyInternalConfiguration x)
5358
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
5459
{
5560
base.ConfigureApplicationContainer(container);
56-
ResourceViewLocationProvider.RootNamespaces.Add(Assembly.GetAssembly(typeof(RepositoriesModule)), "SvnManager.Api.Views");
61+
ResourceViewLocationProvider.RootNamespaces.Add(Assembly.GetAssembly(typeof(RepositoriesModule)), "SvnManager.WebUI.Views");
5762
}
5863
}
5964
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Nancy;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Configuration;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace SvnManager.WebUI.Code
10+
{
11+
/// <summary>
12+
/// Base module class that inherits from NancyModule but includes basic common properties
13+
/// </summary>
14+
public class SvnBaseModule : NancyModule
15+
{
16+
protected static string RepoPath => ConfigurationManager.AppSettings["Manager.RepoPath"];
17+
protected static string SvnLocation => ConfigurationManager.AppSettings["SvnLocation"];
18+
19+
public SvnBaseModule(string modulePath) : base(modulePath)
20+
{ }
21+
22+
public SvnBaseModule() : base()
23+
{ }
24+
}
25+
}

src/SvnManager.WebUI/MainModule.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Nancy;
2+
using SvnManager.WebUI.Code;
23
using System;
34
using System.Collections.Generic;
4-
using System.Configuration;
55
using System.Diagnostics;
66
using System.IO;
77
using System.Linq;
@@ -10,10 +10,8 @@
1010

1111
namespace SvnManager.WebUI
1212
{
13-
public class MainModule : NancyModule
13+
public class MainModule : SvnBaseModule
1414
{
15-
private static string RepoPath => ConfigurationManager.AppSettings["Manager.RepoPath"];
16-
private static string SvnLocation => ConfigurationManager.AppSettings["SvnLocation"];
1715
public MainModule()
1816
{
1917
Get["/"] = x =>
@@ -59,33 +57,34 @@ private void CreateRepo(string name)
5957
{
6058
using (Process p = new Process())
6159
{
62-
p.StartInfo = new ProcessStartInfo($@"{SvnLocation}\svnadmin", $@"create {name}")
60+
p.StartInfo = new ProcessStartInfo($@"{SvnLocation}\svnadmin", $@"create {Path.Combine(RepoPath, name)}")
6361
{
64-
WorkingDirectory = RepoPath,
62+
UseShellExecute = false,
63+
WorkingDirectory = SvnLocation,
6564
RedirectStandardError = true
6665
};
6766
p.Start();
6867
p.WaitForExit();
6968
}
7069

7170
// This gives all users read/write access
72-
string svnAuthz = File.ReadAllText($@"C:\Repositories\{name}\conf\SvnAuthz.ini");
71+
string svnAuthz = File.ReadAllText($@"{RepoPath}\{name}\conf\authz");
7372
svnAuthz += "\r\n\r\n[/]\r\n*=rw";
74-
File.WriteAllText($@"C:\Repositories\{name}\conf\SvnAuthz.ini", svnAuthz);
73+
File.WriteAllText($@"{RepoPath}\{name}\conf\authz", svnAuthz);
7574

7675
// pre-commit hook to require commit messages
77-
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.Api.SvnHooks.pre-commit.cmd"))
76+
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.WebUI.SvnHooks.pre-commit.cmd"))
7877
{
79-
using (var file = new FileStream($@"C:\Repositories\{name}\hooks\pre-commit.cmd", FileMode.Create, FileAccess.Write))
78+
using (var file = new FileStream($@"{RepoPath}\{name}\hooks\pre-commit.cmd", FileMode.Create, FileAccess.Write))
8079
{
8180
resource.CopyTo(file);
8281
}
8382
}
8483

8584
// pre-revprop-change hook to allow for using svnsync
86-
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.Api.SvnHooks.pre-revprop-change.cmd"))
85+
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.WebUI.SvnHooks.pre-revprop-change.cmd"))
8786
{
88-
using (var file = new FileStream($@"C:\Repositories\{name}\hooks\pre-revprop-change.cmd", FileMode.Create, FileAccess.Write))
87+
using (var file = new FileStream($@"{RepoPath}\{name}\hooks\pre-revprop-change.cmd", FileMode.Create, FileAccess.Write))
8988
{
9089
resource.CopyTo(file);
9190
}

src/SvnManager.WebUI/RepositoriesModule.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
using Nancy;
2+
using SvnManager.WebUI.Code;
23
using System.Collections.Generic;
3-
using System.Configuration;
44
using System.Diagnostics;
55
using System.IO;
66
using System.Linq;
77
using System.Reflection;
88

99
namespace SvnManager.WebUI
1010
{
11-
public class RepositoriesModule : NancyModule
11+
public class RepositoriesModule : SvnBaseModule
1212
{
13-
private static string RepoPath => ConfigurationManager.AppSettings["Manager.RepoPath"];
14-
private static string SvnLocation => ConfigurationManager.AppSettings["SvnLocation"];
15-
1613
public RepositoriesModule() : base("/api/repositories")
1714
{
1815
Get["/"] = x =>
@@ -25,33 +22,34 @@ public RepositoriesModule() : base("/api/repositories")
2522
{
2623
using (Process p = new Process())
2724
{
28-
p.StartInfo = new ProcessStartInfo($@"{SvnLocation}\svnadmin", $@"create {x.name}")
25+
p.StartInfo = new ProcessStartInfo($@"{SvnLocation}\svnadmin", $@"create {Path.Combine(RepoPath, x.name)}")
2926
{
30-
WorkingDirectory = RepoPath,
27+
UseShellExecute = false,
28+
WorkingDirectory = SvnLocation,
3129
RedirectStandardError = true
3230
};
3331
p.Start();
3432
p.WaitForExit();
3533
}
3634

3735
// This gives all users read/write access
38-
string svnAuthz = File.ReadAllText($@"C:\Repositories\{x.name}\conf\SvnAuthz.ini");
36+
string svnAuthz = File.ReadAllText($@"{RepoPath}\{x.name}\conf\authz");
3937
svnAuthz += "\r\n\r\n[/]\r\n*=rw";
40-
File.WriteAllText($@"C:\Repositories\{x.name}\conf\SvnAuthz.ini", svnAuthz);
38+
File.WriteAllText($@"{RepoPath}\{x.name}\conf\authz", svnAuthz);
4139

4240
// pre-commit hook to require commit messages
43-
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.Api.SvnHooks.pre-commit.cmd"))
41+
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.WebUI.SvnHooks.pre-commit.cmd"))
4442
{
45-
using (var file = new FileStream($@"C:\Repositories\{x.name}\hooks\pre-commit.cmd", FileMode.Create, FileAccess.Write))
43+
using (var file = new FileStream($@"{RepoPath}\{x.name}\hooks\pre-commit.cmd", FileMode.Create, FileAccess.Write))
4644
{
4745
resource.CopyTo(file);
4846
}
4947
}
5048

5149
// pre-revprop-change hook to allow for using svnsync
52-
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.Api.SvnHooks.pre-revprop-change.cmd"))
50+
using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("SvnManager.WebUI.SvnHooks.pre-revprop-change.cmd"))
5351
{
54-
using (var file = new FileStream($@"C:\Repositories\{x.name}\hooks\pre-revprop-change.cmd", FileMode.Create, FileAccess.Write))
52+
using (var file = new FileStream($@"{RepoPath}\{x.name}\hooks\pre-revprop-change.cmd", FileMode.Create, FileAccess.Write))
5553
{
5654
resource.CopyTo(file);
5755
}

src/SvnManager.WebUI/SvnManager.WebUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
</ItemGroup>
5959
<ItemGroup>
6060
<Compile Include="Bootstrapper.cs" />
61+
<Compile Include="Code\SvnBaseModule.cs" />
6162
<Compile Include="ExcDetails.cs" />
6263
<Compile Include="MainModule.cs" />
6364
<Compile Include="NancyHostControl.cs" />

src/SvnManager.WebUI/UserApiModule.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CryptSharp;
22
using Nancy;
3+
using SvnManager.WebUI.Code;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -9,7 +10,7 @@
910

1011
namespace SvnManager.WebUI
1112
{
12-
public class UserApiModule : NancyModule
13+
public class UserApiModule : SvnBaseModule
1314
{
1415
public UserApiModule() : base("/api/user")
1516
{

src/SvnManager.WebUI/UserModule.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using CryptSharp;
22
using Nancy;
3+
using SvnManager.WebUI.Code;
34
using System;
45
using System.Collections.Generic;
5-
using System.Configuration;
66
using System.IO;
77

88
namespace SvnManager.WebUI
99
{
10-
public class UserModule : NancyModule
10+
public class UserModule : SvnBaseModule
1111
{
1212
public UserModule() : base("/user")
1313
{
@@ -29,9 +29,9 @@ public UserModule() : base("/user")
2929
string strPassword = password;
3030
string userPasswordHash = Crypter.MD5.Crypt(strPassword, new CrypterOptions { { CrypterOption.Variant, MD5CrypterVariant.Apache } });
3131

32-
var pwds = File.ReadAllText($@"{ConfigurationManager.AppSettings["Manger.RepoPath"].TrimEnd('\\')}\htpasswd");
32+
var pwds = File.ReadAllText($@"{RepoPath.TrimEnd('\\')}\htpasswd");
3333
pwds += $"{name}:{userPasswordHash}{Environment.NewLine}";
34-
File.WriteAllText($@"{ConfigurationManager.AppSettings["Manger.RepoPath"].TrimEnd('\\')}\htpasswd", pwds);
34+
File.WriteAllText($@"{RepoPath.TrimEnd('\\')}\htpasswd", pwds);
3535
}
3636
catch (Exception ex)
3737
{
@@ -48,8 +48,14 @@ private List<dynamic> GetUsers()
4848
{
4949
var users = new List<dynamic>();
5050

51+
if (!File.Exists($@"{RepoPath.TrimEnd('\\')}\htpasswd"))
52+
{
53+
File.CreateText($@"{RepoPath.TrimEnd('\\')}\htpasswd");
54+
return users;
55+
}
56+
5157
string line;
52-
using (StreamReader fs = new StreamReader($@"{ConfigurationManager.AppSettings["Manger.RepoPath"].TrimEnd('\\')}\htpasswd"))
58+
using (StreamReader fs = new StreamReader($@"{RepoPath.TrimEnd('\\')}\htpasswd"))
5359
{
5460
while ((line = fs.ReadLine()) != null)
5561
{

src/SvnManager/SvnManagerService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ namespace SvnManager
1010
{
1111
public partial class SvnManagerService : ServiceBase
1212
{
13-
private static string Source => ConfigurationManager.AppSettings["Manger.EventSourceName"];
13+
private static string Source => ConfigurationManager.AppSettings["Manager.EventSourceName"];
1414

1515
Timer _backupTimer = new Timer(900_000); // check every 15 minutes (reduce time creep)
1616
BackgroundWorker _worker = new BackgroundWorker();
1717
NancyHostControl host;
1818
static ConfigMonitor monitor;
1919

20-
private string InterfaceUrlHost => ConfigurationManager.AppSettings["Manger.InterfaceUrlHost"];
21-
private int InterfaceUrlPort => Convert.ToInt32(ConfigurationManager.AppSettings["Manger.InterfaceUrlPort"]);
22-
private bool InterfaceUrlHttps => Convert.ToBoolean(ConfigurationManager.AppSettings["Manger.InterfaceUrlHttps"]);
20+
private string InterfaceUrlHost => ConfigurationManager.AppSettings["Manager.InterfaceUrlHost"];
21+
private int InterfaceUrlPort => Convert.ToInt32(ConfigurationManager.AppSettings["Manager.InterfaceUrlPort"]);
22+
private bool InterfaceUrlHttps => Convert.ToBoolean(ConfigurationManager.AppSettings["Manager.InterfaceUrlHttps"]);
2323

2424
public SvnManagerService()
2525
{

0 commit comments

Comments
 (0)