1 // Copyright © Microsoft Corporation.
2 // This source file is subject to the Microsoft Permissive License.
3 // See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
4 // All other rights reserved.
8 using System
.Reflection
;
9 using System
.Xml
.XPath
;
11 namespace Microsoft
.Ddue
.Tools
.CommandLine
{
13 public static class ConsoleApplication
{
15 public static XPathDocument
GetConfigurationFile() {
16 return (GetConfigurationFile(Assembly
.GetCallingAssembly().Location
+ ".config"));
19 public static XPathDocument
GetConfigurationFile(string file
) {
20 return (new XPathDocument(file
));
23 public static string[] GetFiles(string filePattern
) {
25 // get the full path to the relevent directory
26 string directoryPath
= Path
.GetDirectoryName(filePattern
);
27 if ((directoryPath
== null) || (directoryPath
.Length
== 0)) directoryPath
= Environment
.CurrentDirectory
;
28 directoryPath
= Path
.GetFullPath(directoryPath
);
30 // get the file name, which may contain wildcards
31 string filePath
= Path
.GetFileName(filePattern
);
33 // look up the files and load them
34 string[] files
= Directory
.GetFiles(directoryPath
, filePath
);
40 // Write the name, version, and copyright information of the calling assembly
42 public static void WriteBanner() {
43 Assembly application
= Assembly
.GetCallingAssembly();
44 AssemblyName applicationData
= application
.GetName();
45 Console
.WriteLine("{0} (v{1})", applicationData
.Name
, applicationData
.Version
);
46 Object
[] copyrightAttributes
= application
.GetCustomAttributes(typeof(AssemblyCopyrightAttribute
), true);
47 foreach (AssemblyCopyrightAttribute copyrightAttribute
in copyrightAttributes
) {
48 Console
.WriteLine(copyrightAttribute
.Copyright
);
52 public static void WriteMessage(LogLevel level
, string message
) {
53 Console
.WriteLine("{0}: {1}", level
, message
);
56 public static void WriteMessage(LogLevel level
, string format
, params object[] arg
)
58 Console
.Write("{0}: ", level
);
59 Console
.WriteLine(format
, arg
);