4 // Copyright (C) 2005 Novell, Inc.
5 // Copyright (C) 2006 Debajyoti Bera <dbera.web@gmail.com>
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 using System
.Reflection
;
37 public static void PrintUsageAndExit ()
40 "beagle-info: Statistics from the Beagle daemon.\n" +
41 "Web page: http://www.gnome.org/projects/beagle\n" +
42 "Copyright (C) 2004-2005 Novell, Inc.\n\n";
44 "Usage: beagle-info <OPTIONS>\n\n" +
46 " --daemon-version\t\tPrint the version of the running daemon.\n" +
47 " --status\t\t\tDisplay status of the running daemon.\n" +
48 " --index-info\t\t\tDisplay statistics of the Beagle indexes.\n" +
49 " --list-filters\t\tList the currently available filters.\n" +
50 " --help\t\t\tPrint this usage message.\n";
52 Console
.WriteLine (usage
);
54 System
.Environment
.Exit (0);
57 static int Main (string[] args
)
59 if (args
.Length
== 0 || Array
.IndexOf (args
, "--help") > -1)
62 if (Array
.IndexOf (args
, "--list-filters") > -1)
63 PrintFilterInformation ();
65 return PrintDaemonInformation (args
);
70 private static int PrintDaemonInformation (string[] args
)
72 DaemonInformationRequest request
= new DaemonInformationRequest ();
73 DaemonInformationResponse response
;
76 Console
.WriteLine ("Sending begins at:" + DateTime
.Now
);
77 response
= (DaemonInformationResponse
) request
.Send ();
78 Console
.WriteLine ("Sending done at:" + DateTime
.Now
);
79 } catch (Beagle
.ResponseMessageException
) {
80 Console
.WriteLine ("Could not connect to the daemon.");
84 if (Array
.IndexOf (args
, "--daemon-version") > -1)
85 Console
.WriteLine ("Daemon version: {0}", response
.Version
);
87 if (Array
.IndexOf (args
, "--status") > -1)
88 Console
.Write (response
.HumanReadableStatus
);
90 if (Array
.IndexOf (args
, "--index-info") > -1) {
91 Console
.WriteLine ("Index information:");
92 Console
.WriteLine (response
.IndexInformation
);
95 if (Array
.IndexOf (args
, "--is-indexing") > -1)
96 Console
.WriteLine ("Daemon indexing: {0}", response
.IsIndexing
);
101 private static void PrintFilterInformation ()
103 ReflectionFu
.ScanEnvironmentForAssemblies ("BEAGLE_FILTER_PATH", PathFinder
.FilterDir
, PrintFilterDetails
);
106 static void PrintFilterDetails (Assembly assembly
)
108 foreach (Type t
in ReflectionFu
.ScanAssemblyForClass (assembly
, typeof (Filter
))) {
109 Filter filter
= null;
112 filter
= (Filter
) Activator
.CreateInstance (t
);
113 } catch (Exception ex
) {
114 Logger
.Log
.Error ("Caught exception while instantiating {0}", t
);
115 Logger
.Log
.Error (ex
);
123 if (t
.FullName
.StartsWith (t
.Namespace
))
124 name
= t
.FullName
.Substring (t
.Namespace
.Length
+ 1);
128 Console
.WriteLine (name
+ " - Version " + filter
.Version
+ " (" + assembly
.Location
+ ")");
130 foreach (FilterFlavor flavor
in filter
.SupportedFlavors
) {
131 if (flavor
.MimeType
!= null)
132 Console
.WriteLine (" - " + flavor
.MimeType
);
133 if (flavor
.Extension
!= null)
134 Console
.WriteLine (" - *" + flavor
.Extension
);
137 Console
.WriteLine ();