Added container accessor to Castle.Core
[castle.git] / Tools / SubversionHooks / Hooks / SvnLook.cs
blobbc065599be57378c8b0f7a21ed9ef35375b96881
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.SvnHooks
17 using System;
18 using System.Diagnostics;
19 /// <summary>
20 /// Summary description for SvnLook.
21 /// </summary>
22 public sealed class SvnLook
24 public SvnLook(String svnLookPath, String repositoryPath)
26 this.SvnLookPath = svnLookPath;
27 this.RepositoryPath = repositoryPath;
30 public Process Execute(SvnLookCommand command, int revision, String arguments)
32 Trace.WriteLine(String.Format("Excuting {0} with revision {1}", command, revision));
33 switch (command)
35 case SvnLookCommand.Lock:
36 throw new InvalidOperationException("Lock cannot be called with a revision number");
37 case SvnLookCommand.UUID:
38 throw new InvalidOperationException("UUID cannot be called with a revision number");
39 case SvnLookCommand.Youngest:
40 throw new InvalidOperationException("Youngest cannot be called with a revision number");
41 default: break;
44 arguments = String.Concat("-r ", revision, " ", arguments);
46 return Execute(command, arguments);
49 public Process Execute(SvnLookCommand command, Transaction transaction, String arguments)
51 Trace.WriteLine(String.Format("Excuting {0} with transaction {1}", command, transaction));
52 switch (command)
54 case SvnLookCommand.History:
55 throw new InvalidOperationException("History cannot be called with a transaction number");
56 case SvnLookCommand.Lock:
57 throw new InvalidOperationException("Lock cannot be called with a transaction number");
58 case SvnLookCommand.UUID:
59 throw new InvalidOperationException("UUID cannot be called with a transaction number");
60 case SvnLookCommand.Youngest:
61 throw new InvalidOperationException("Youngest cannot be called with a transaction number");
62 default: break;
65 arguments = String.Concat("-t ", transaction, " ", arguments);
67 return Execute(command, arguments);
70 public Process Execute(SvnLookCommand command, String arguments)
72 Trace.WriteLine(String.Format("Excuting {0} with arguments: {1}", command, arguments));
73 arguments = String.Concat(
74 GetCommandString(command), " \"",
75 RepositoryPath, "\" ",
76 arguments);
78 ProcessStartInfo info = new ProcessStartInfo();
79 info.Arguments = arguments;
80 info.FileName = SvnLookPath;
81 // Required for redirecting standard output
82 info.UseShellExecute = false;
83 // Required to be able to catch the output
84 info.RedirectStandardOutput = true;
85 // Required to keep the called program from
86 // writing errors that destroy formatting
87 // of *our* error messages.
88 info.RedirectStandardError = true;
90 return Process.Start(info);
93 private static String GetCommandString(SvnLookCommand command)
96 switch (command)
98 case SvnLookCommand.Author:
99 return "author";
101 case SvnLookCommand.Cat:
102 return "cat";
104 case SvnLookCommand.Changed:
105 return "changed";
107 case SvnLookCommand.Date:
108 return "date";
110 case SvnLookCommand.Diff:
111 return "diff";
113 case SvnLookCommand.DirsChanged:
114 return "dirs-changed";
116 case SvnLookCommand.History:
117 return "history";
119 case SvnLookCommand.Info:
120 return "info";
122 case SvnLookCommand.Lock:
123 return "lock";
125 case SvnLookCommand.Log:
126 return "log";
128 case SvnLookCommand.PropertyGet:
129 return "propget";
131 case SvnLookCommand.PropertyList:
132 return "proplist";
134 case SvnLookCommand.Tree:
135 return "tree";
137 case SvnLookCommand.UUID:
138 return "uuid";
140 case SvnLookCommand.Youngest:
141 return "youngest";
143 default:
144 throw new ArgumentOutOfRangeException("command");
150 private readonly String SvnLookPath;
151 private readonly String RepositoryPath;