1 | | // project created on 5/13/2004 at 10:00 PM |
---|
| 1 | // SvnTest, a client program used to test SubversionSharp library |
---|
| 2 | // Copyright 2004 by SOFTEC sa |
---|
| 3 | // |
---|
| 4 | // This program is free software; you can redistribute it and/or |
---|
| 5 | // modify it under the terms of the GNU General Public License as |
---|
| 6 | // published by the Free Software Foundation; either version 2 of |
---|
| 7 | // the License, or (at your option) any later version. |
---|
| 8 | // |
---|
| 9 | // This program is distributed in the hope that it will be useful, |
---|
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
| 12 | // See the GNU General Public License for more details. |
---|
| 13 | // |
---|
| 14 | // You should have received a copy of the GNU General Public |
---|
| 15 | // License along with this program; if not, write to the Free Software |
---|
| 16 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | // |
---|
| 18 | // Sources, support options and lastest version of the complete library |
---|
| 19 | // is available from: |
---|
| 20 | // http://www.softec.st/SubversionSharp |
---|
| 21 | // |
---|
| 22 | // |
---|
| 23 | // Initial authors : |
---|
| 24 | // Denis Gervalle |
---|
| 25 | // Olivier Desaive |
---|
| 26 | // |
---|
13 | | Debug.Listeners.Add(new TextWriterTraceListener(Console.Out)); |
---|
14 | | |
---|
15 | | SvnClient client = new SvnClient(); |
---|
16 | | |
---|
17 | | client.AddSimpleProvider(); |
---|
18 | | client.AddUsernameProvider(); |
---|
19 | | client.AddSslServerTrustFileProvider(); |
---|
20 | | client.AddSslClientCertFileProvider(); |
---|
21 | | client.AddSslClientCertPwFileProvider(); |
---|
22 | | client.AddPromptProvider( |
---|
23 | | new SvnAuthProviderObject.SimplePrompt(SimpleAuth), |
---|
24 | | IntPtr.Zero, 2); |
---|
25 | | client.AddPromptProvider( |
---|
26 | | new SvnAuthProviderObject.UsernamePrompt(UsernameAuth), |
---|
27 | | IntPtr.Zero, 2); |
---|
28 | | client.AddPromptProvider( |
---|
29 | | new SvnAuthProviderObject.SslServerTrustPrompt(SslServerTrustAuth), |
---|
30 | | IntPtr.Zero); |
---|
31 | | client.OpenAuth(); |
---|
32 | | |
---|
33 | | client.Context.NotifyFunc = new SvnDelegate(new SvnWcNotify.Func(NotifyCallback)); |
---|
34 | | client.Context.LogMsgFunc = new SvnDelegate(new SvnClient.GetCommitLog(GetCommitLogCallback)); |
---|
35 | | client.Context.CancelFunc = new SvnDelegate(new Svn.CancelFunc(CancelCallback)); |
---|
36 | | |
---|
37 | | client.Checkout("https://www.softec.st/svn/test", |
---|
38 | | "test", |
---|
39 | | 100, true); |
---|
40 | | client.Update("test", |
---|
41 | | Svn.Revision.Head, true); |
---|
42 | | |
---|
43 | | client.Pool.Destroy(); |
---|
44 | | } |
---|
45 | | |
---|
46 | | public static void NotifyCallback(IntPtr baton, SvnPath Path, |
---|
47 | | SvnWcNotify.Action action, Svn.NodeKind kind, |
---|
48 | | AprString mimeType, SvnWcNotify.State contentState, |
---|
49 | | SvnWcNotify.State propState, int revNum) |
---|
50 | | { |
---|
51 | | } |
---|
52 | | |
---|
53 | | public static SvnError GetCommitLogCallback(out AprString logMessage, out SvnPath tmpFile, |
---|
54 | | AprArray commitItems, IntPtr baton, |
---|
55 | | AprPool pool) |
---|
56 | | { |
---|
57 | | if (!commitItems.IsNull) |
---|
58 | | { |
---|
59 | | foreach (SvnClientCommitItem item in commitItems) |
---|
| 36 | public class SubCommand { |
---|
| 37 | public string LongName; |
---|
| 38 | public string ShortName; |
---|
| 39 | public string Description; |
---|
| 40 | public Type Impl; |
---|
| 41 | public SubCommand(string longName, string shortName, string desc, Type impl) |
---|
106 | | line = username.ToString(); |
---|
107 | | valid = true; |
---|
108 | | } |
---|
109 | | else if (line.Trim().Length > 0) |
---|
110 | | { |
---|
111 | | valid = true; |
---|
112 | | } |
---|
113 | | } |
---|
114 | | |
---|
115 | | cred = SvnAuthCredSimple.Alloc(pool); |
---|
116 | | cred.Username = new AprString(line, pool); |
---|
117 | | Console.Write("Enter Password: "); |
---|
118 | | cred.Password = new AprString(Console.ReadLine(), pool); |
---|
119 | | cred.MaySave = maySave; |
---|
120 | | return(SvnError.NoError); |
---|
121 | | } |
---|
122 | | |
---|
123 | | public static SvnError UsernameAuth(out SvnAuthCredUsername cred, IntPtr baton, |
---|
124 | | AprString realm, bool maySave, AprPool pool) |
---|
125 | | { |
---|
126 | | Console.WriteLine("Username Authentication:"); |
---|
127 | | Console.WriteLine("------------------------"); |
---|
128 | | Console.WriteLine("Realm: {0}", realm); |
---|
129 | | Console.WriteLine(""); |
---|
130 | | |
---|
131 | | bool valid = false; |
---|
132 | | string line = ""; |
---|
133 | | |
---|
134 | | while(!valid) |
---|
135 | | { |
---|
136 | | Console.Write("Enter Username: "); |
---|
137 | | |
---|
138 | | line = Console.ReadLine(); |
---|
139 | | |
---|
140 | | if (line.Trim().Length > 0) |
---|
141 | | { |
---|
142 | | valid = true; |
---|
143 | | } |
---|
144 | | } |
---|
145 | | |
---|
146 | | cred = SvnAuthCredUsername.Alloc(pool); |
---|
147 | | cred.Username = new AprString(line, pool); |
---|
148 | | cred.MaySave = maySave; |
---|
149 | | return(SvnError.NoError); |
---|
150 | | } |
---|
151 | | |
---|
152 | | public static SvnError SslServerTrustAuth(out SvnAuthCredSslServerTrust cred, |
---|
153 | | IntPtr baton, AprString realm, |
---|
154 | | SvnAuthCredSslServerTrust.CertFailures failures, |
---|
155 | | SvnAuthSslServerCertInfo certInfo, |
---|
156 | | bool maySave, IntPtr pool) |
---|
157 | | { |
---|
158 | | Console.WriteLine("Ssl Server Trust Prompt:"); |
---|
159 | | Console.WriteLine("------------------------"); |
---|
160 | | Console.WriteLine(""); |
---|
161 | | |
---|
162 | | Console.WriteLine("Error validating server certificate for '{0}':", realm); |
---|
163 | | if ((failures & SvnAuthCredSslServerTrust.CertFailures.UnknownCA) > 0) |
---|
164 | | Console.WriteLine(" - The certificate is not issued by a trusted authority"); |
---|
165 | | if ((failures & SvnAuthCredSslServerTrust.CertFailures.CNMismatch) > 0) |
---|
166 | | Console.WriteLine(" - The certificate hostname does not match"); |
---|
167 | | if ((failures & SvnAuthCredSslServerTrust.CertFailures.NotYetValid) > 0) |
---|
168 | | Console.WriteLine(" - The certificate is not yet valid"); |
---|
169 | | if ((failures & SvnAuthCredSslServerTrust.CertFailures.Expired) > 0) |
---|
170 | | Console.WriteLine(" - The certificate has expired"); |
---|
171 | | if ((failures & SvnAuthCredSslServerTrust.CertFailures.Other) > 0) |
---|
172 | | Console.WriteLine(" - The certificate has an unknown error"); |
---|
173 | | |
---|
174 | | Console.WriteLine("Certificate informations:"); |
---|
175 | | Console.WriteLine("\tHostName: " + certInfo.Hostname); |
---|
176 | | Console.WriteLine("\tIssuer: " + certInfo.IssuerDName); |
---|
177 | | Console.WriteLine("\tValid From: " + certInfo.ValidFrom); |
---|
178 | | Console.WriteLine("\tValid Until: " + certInfo.ValidUntil); |
---|
179 | | Console.WriteLine("\tFingerprint: " + certInfo.Fingerprint); |
---|
180 | | |
---|
181 | | cred = SvnAuthCredSslServerTrust.Alloc(pool); |
---|
182 | | bool valid = false; |
---|
183 | | while (!valid) |
---|
184 | | { |
---|
185 | | if (maySave) |
---|
186 | | Console.WriteLine("(R)eject, accept (t)emporarily or accept (p)ermanently? "); |
---|
187 | | else |
---|
188 | | Console.WriteLine("(R)eject or accept (t)emporarily? "); |
---|
189 | | |
---|
190 | | string line = Console.ReadLine(); |
---|
191 | | if (line.Length > 0) |
---|
192 | | { |
---|
193 | | char choice = line.ToLower()[0]; |
---|
194 | | if (choice == 'r') |
---|
| 59 | object[] o; |
---|
| 60 | if((o = t.GetCustomAttributes(typeof(SubCommandAttribute),true)) != null |
---|
| 61 | && o.Length != 0) |
---|
214 | | return(SvnError.NoError); |
---|
| 70 | |
---|
| 71 | private WhatToDoNext UsageAppend(WhatToDoNext ret) |
---|
| 72 | { |
---|
| 73 | Console.Write("Subcommands: "); |
---|
| 74 | bool addSep = false; |
---|
| 75 | foreach(SubCommand sc in SubCommands.Values) |
---|
| 76 | { |
---|
| 77 | if( addSep ) |
---|
| 78 | Console.Write(", "); |
---|
| 79 | else |
---|
| 80 | addSep = true; |
---|
| 81 | Console.Write(sc.LongName); |
---|
| 82 | if( sc.ShortName != string.Empty ) |
---|
| 83 | Console.Write("[{0}]",sc.ShortName); |
---|
| 84 | } |
---|
| 85 | Console.WriteLine("\nFor help on subcommands, use the -?/--help subcommand option."); |
---|
| 86 | return(ret); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public override WhatToDoNext DoUsage() |
---|
| 90 | { |
---|
| 91 | return WhatToDoNext.GoAhead; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | public override WhatToDoNext DoHelp() |
---|
| 95 | { |
---|
| 96 | mPendingHelp = true; |
---|
| 97 | return WhatToDoNext.GoAhead; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | public int Run(string[] args) |
---|
| 101 | { |
---|
| 102 | ProcessArgs(args); |
---|
| 103 | |
---|
| 104 | if( RemainingArguments.Length == 0 ) |
---|
| 105 | { |
---|
| 106 | if( mPendingHelp ) |
---|
| 107 | UsageAppend(base.DoHelp()); |
---|
| 108 | else |
---|
| 109 | UsageAppend(base.DoUsage()); |
---|
| 110 | return(0); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | SubCommand sc; |
---|
| 114 | if ((sc = (SubCommand) SubCommands[RemainingArguments[0].ToLower()]) == null) |
---|
| 115 | { |
---|
| 116 | string shortCmd = (string) ShortCommands[RemainingArguments[0].ToLower()]; |
---|
| 117 | if( shortCmd == null |
---|
| 118 | || (sc = (SubCommand) SubCommands[shortCmd]) == null ) |
---|
| 119 | { |
---|
| 120 | if( mPendingHelp ) |
---|
| 121 | UsageAppend(base.DoHelp()); |
---|
| 122 | else |
---|
| 123 | UsageAppend(base.DoUsage()); |
---|
| 124 | return(1); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | ConstructorInfo ctor = sc.Impl.GetConstructor(new Type[0]); |
---|
| 129 | MethodInfo run = sc.Impl.GetMethod("Run",new Type[] { typeof(SubCommand), typeof(string[]) }); |
---|
| 130 | |
---|
| 131 | if(ctor == null || run == null || run.ReturnType != typeof(int)) |
---|
| 132 | throw new InvalidOperationException("Invalid subcommand class"); |
---|
| 133 | |
---|
| 134 | return((int)run.Invoke(ctor.Invoke(new object[0]),new object[] { sc, args })); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | public static int Main(string[] args) |
---|
| 138 | { |
---|
| 139 | Application progInst = new Application(); |
---|
| 140 | return( progInst.Run(args) ); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | [AttributeUsage(AttributeTargets.Class)] |
---|
| 145 | public class SubCommandAttribute : Attribute |
---|
| 146 | { |
---|
| 147 | public string ShortName; |
---|
| 148 | public string LongName; |
---|
| 149 | public string Description; |
---|
| 150 | |
---|
| 151 | public SubCommandAttribute(string longName) |
---|
| 152 | { |
---|
| 153 | ShortName = string.Empty; |
---|
| 154 | LongName = longName.ToLower(); |
---|
| 155 | Description = string.Empty; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | public SubCommandAttribute(string longName, string shortName) |
---|
| 159 | { |
---|
| 160 | ShortName = shortName.ToLower(); |
---|
| 161 | LongName = longName.ToLower(); |
---|
| 162 | Description = string.Empty; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | public SubCommandAttribute(string longName, string shortName, string desc) |
---|
| 166 | { |
---|
| 167 | ShortName = shortName.ToLower(); |
---|
| 168 | LongName = longName.ToLower(); |
---|
| 169 | Description = desc; |
---|
| 170 | } |
---|