1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Diagnostics
;
20 /// Summary description for SvnLook.
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
));
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");
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
));
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");
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
, "\" ",
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
)
98 case SvnLookCommand
.Author
:
101 case SvnLookCommand
.Cat
:
104 case SvnLookCommand
.Changed
:
107 case SvnLookCommand
.Date
:
110 case SvnLookCommand
.Diff
:
113 case SvnLookCommand
.DirsChanged
:
114 return "dirs-changed";
116 case SvnLookCommand
.History
:
119 case SvnLookCommand
.Info
:
122 case SvnLookCommand
.Lock
:
125 case SvnLookCommand
.Log
:
128 case SvnLookCommand
.PropertyGet
:
131 case SvnLookCommand
.PropertyList
:
134 case SvnLookCommand
.Tree
:
137 case SvnLookCommand
.UUID
:
140 case SvnLookCommand
.Youngest
:
144 throw new ArgumentOutOfRangeException("command");
150 private readonly String SvnLookPath
;
151 private readonly String RepositoryPath
;