wasSharpNET – Diff between revs 11 and 16

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 11 Rev 16
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6   6  
7 using System.Diagnostics; 7 using System.Diagnostics;
8 using System.Text; 8 using System.Text;
9 using System.Text.RegularExpressions; 9 using System.Text.RegularExpressions;
10   10  
11 namespace wasSharpNET.Platform.Windows.Commands.NetSH 11 namespace wasSharpNET.Platform.Windows.Commands.NetSH
12 { 12 {
13 public class URLACL 13 public class URLACL
14 { 14 {
15 public string domain; 15 private string domain;
16 public string URL; 16 private string URL;
17   17  
18 private readonly Regex URLReservationRegex; 18 private readonly Regex URLReservationRegex;
-   19 private string username;
19 public string username; 20 private int timeout;
20   21  
21 public URLACL(string URL, string username, string domain) 22 public URLACL(string URL, string username, string domain, int timeout)
22 { 23 {
23 this.URL = URL; 24 this.URL = URL;
24 this.username = username; 25 this.username = username;
25 this.domain = domain; 26 this.domain = domain;
-   27 this.timeout = timeout;
26   28  
27 URLReservationRegex = 29 URLReservationRegex =
28 new Regex( 30 new Regex(
29 string.Format(@"{0}.*{1}", Regex.Escape(URL), 31 string.Format(@"{0}.*{1}", Regex.Escape(URL),
30 Regex.Escape(string.Format(@"{0}\{1}", domain, username))), 32 Regex.Escape(string.Format(@"{0}\{1}", domain, username))),
31 RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | 33 RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
32 RegexOptions.Compiled); 34 RegexOptions.Compiled);
33 } 35 }
34   36  
35 public bool isReserved 37 public bool isReserved
36 { 38 {
37 get 39 get
38 { 40 {
39 var netSHOutput = new StringBuilder(); 41 var netSHOutput = new StringBuilder();
40 var checkProcess = new System.Diagnostics.Process(); 42 var checkProcess = new System.Diagnostics.Process();
41 checkProcess.StartInfo = new ProcessStartInfo("netsh", @"http show urlacl") 43 checkProcess.StartInfo = new ProcessStartInfo("netsh", @"http show urlacl")
42 { 44 {
43 RedirectStandardOutput = true, 45 RedirectStandardOutput = true,
44 CreateNoWindow = true, 46 CreateNoWindow = true,
45 WindowStyle = ProcessWindowStyle.Hidden, 47 WindowStyle = ProcessWindowStyle.Hidden,
46 UseShellExecute = false 48 UseShellExecute = false
47 }; 49 };
48   50  
49 checkProcess.OutputDataReceived += (sender, output) => 51 checkProcess.OutputDataReceived += (sender, output) =>
50 { 52 {
51 if (output?.Data != null) 53 if (output?.Data != null)
52 { 54 {
53 netSHOutput.Append(output.Data); 55 netSHOutput.Append(output.Data);
54 } 56 }
55 }; 57 };
56   58  
57 checkProcess.Start(); 59 checkProcess.Start();
58 checkProcess.BeginOutputReadLine(); 60 checkProcess.BeginOutputReadLine();
59 checkProcess.WaitForExit(); 61 checkProcess.WaitForExit(60000);
60   62  
61 return URLReservationRegex.IsMatch(netSHOutput.ToString()); 63 return URLReservationRegex.IsMatch(netSHOutput.ToString());
62 } 64 }
63 } 65 }
64   66  
65 public void Reserve() 67 public void Reserve()
66 { 68 {
67 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh", 69 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
68 string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username)) 70 string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username))
69 { 71 {
70 Verb = @"runas", 72 Verb = @"runas",
71 CreateNoWindow = true, 73 CreateNoWindow = true,
72 WindowStyle = ProcessWindowStyle.Hidden, 74 WindowStyle = ProcessWindowStyle.Hidden,
73 UseShellExecute = true 75 UseShellExecute = false
74 }).WaitForExit(); 76 }).WaitForExit(timeout);
75 } 77 }
76   78  
77 public void Release() 79 public void Release()
78 { 80 {
79 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh", 81 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
80 string.Format(@"http del urlacl url={0}", URL)) 82 string.Format(@"http del urlacl url={0}", URL))
81 { 83 {
82 Verb = @"runas", 84 Verb = @"runas",
83 CreateNoWindow = true, 85 CreateNoWindow = true,
84 WindowStyle = ProcessWindowStyle.Hidden, 86 WindowStyle = ProcessWindowStyle.Hidden,
85 UseShellExecute = true 87 UseShellExecute = false
86 }).WaitForExit(); 88 }).WaitForExit(timeout);
87 } 89 }
88 } 90 }
89 } 91 }
90   92