|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.IO; |
|
19 using System.Text; |
|
20 using System.Collections.Generic; |
|
21 using System.Data; |
|
22 using CrashAnalyserEngine.Tabs; |
|
23 using CrashAnalyserEngine.Engine; |
|
24 using CrashAnalyserEngine.Interfaces; |
|
25 using CrashAnalyserEngine.Plugins; |
|
26 using SymbianXmlInputLib.Elements; |
|
27 using SymbianXmlInputLib.Parser; |
|
28 using SymbianXmlInputLib.Parser.Nodes; |
|
29 using SymbianUtils.FileSystem; |
|
30 |
|
31 namespace CrashAnalyserConsole |
|
32 { |
|
33 internal class CACommandLineUI : IEngineUIManager |
|
34 { |
|
35 #region Constructors & destructor |
|
36 public CACommandLineUI( string[] aArguments, FSLog aLog ) |
|
37 { |
|
38 iLog = aLog; |
|
39 |
|
40 // Create engine |
|
41 iEngine = new CAEngine( aArguments ); |
|
42 |
|
43 // Work out if we are in verbose mode |
|
44 CheckArgsForVerbose(); |
|
45 |
|
46 // Associate engine and UI with one another - this causes |
|
47 // plugins to be loaded |
|
48 iEngine.UIManager = this; |
|
49 } |
|
50 #endregion |
|
51 |
|
52 #region API |
|
53 public int Run() |
|
54 { |
|
55 iLog.TraceAlways( "[CmdExe] Run() - START" ); |
|
56 int error = CAPlugin.KErrCommandLineNone; |
|
57 // |
|
58 CAPlugin plugin = LocatePlugin(); |
|
59 iLog.TraceAlways( "[CmdExe] Run() - plugin: " + plugin ); |
|
60 if ( plugin != null ) |
|
61 { |
|
62 iLog.TraceAlways( "[CmdExe] Run() - executing plugin command line operations..." ); |
|
63 error = plugin.RunCommandLineOperations(); |
|
64 } |
|
65 else |
|
66 { |
|
67 iLog.TraceAlways( "[CmdExe] Run() - plugin not found!" ); |
|
68 error = CAPlugin.KErrCommandLinePluginNotFound; |
|
69 } |
|
70 // |
|
71 iLog.TraceAlways( "[CmdExe] Run() - END - error: " + error ); |
|
72 return error; |
|
73 } |
|
74 #endregion |
|
75 |
|
76 #region Properties |
|
77 public bool Verbose |
|
78 { |
|
79 get { return iLog.Verbose; } |
|
80 private set |
|
81 { |
|
82 iLog.Verbose = value; |
|
83 iLog.TraceAlways( "[CmdExe] Verbose Mode: " + value.ToString() ); |
|
84 } |
|
85 } |
|
86 #endregion |
|
87 |
|
88 #region IEngineUIManager Members |
|
89 public void UIManagerMenuItemAdd( TEngineUIMenuPane aPane, string aCaption, UIMenuItemClickHandler aClickHandler, object aTag ) |
|
90 { |
|
91 } |
|
92 |
|
93 public void UIManagerMenuItemAdd( TEngineUIMenuPane aPane, string aCaption, UIMenuItemClickHandler aClickHandler, object aTag, CATab aHost ) |
|
94 { |
|
95 } |
|
96 |
|
97 public void UIManagerContentAdd( CATab aTab ) |
|
98 { |
|
99 } |
|
100 |
|
101 public void UIManagerContentClose( CATab aTab ) |
|
102 { |
|
103 } |
|
104 |
|
105 public Version UIVersion |
|
106 { |
|
107 get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; } |
|
108 } |
|
109 |
|
110 public string UICommandLineArguments |
|
111 { |
|
112 get { return Environment.CommandLine; } |
|
113 } |
|
114 |
|
115 public bool UIIsSilent |
|
116 { |
|
117 get { return true; } |
|
118 } |
|
119 |
|
120 public void UITrace( string aMessage ) |
|
121 { |
|
122 iLog.Trace( aMessage ); |
|
123 } |
|
124 |
|
125 public void UITrace( string aFormat, params object[] aParams ) |
|
126 { |
|
127 string msg = string.Format( aFormat, aParams ); |
|
128 UITrace( msg ); |
|
129 } |
|
130 #endregion |
|
131 |
|
132 #region Internal constants |
|
133 private const string KParamVerbose = "-V"; |
|
134 private const string KParamPlugin = "-PLUGIN"; |
|
135 #endregion |
|
136 |
|
137 #region Internal methods |
|
138 private void CheckArgsForVerbose() |
|
139 { |
|
140 string[] args = iEngine.CommandLineArguments; |
|
141 for ( int i = 0; i < args.Length; i++ ) |
|
142 { |
|
143 string cmd = args[ i ].Trim().ToUpper(); |
|
144 string nextArg = ( i < args.Length - 1 ? args[ i + 1 ].Trim().ToUpper() : string.Empty ); |
|
145 // |
|
146 try |
|
147 { |
|
148 if ( cmd == KParamVerbose ) |
|
149 { |
|
150 Verbose = true; |
|
151 break; |
|
152 } |
|
153 } |
|
154 catch ( Exception ) |
|
155 { |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 private CAPlugin LocatePlugin() |
|
161 { |
|
162 // -nogui -plugin CRASH_ANALYSIS -input d:\ca_fullsummary.xml |
|
163 CAPlugin ret = null; |
|
164 // |
|
165 string[] args = iEngine.CommandLineArguments; |
|
166 for( int i=0; i<args.Length; i++ ) |
|
167 { |
|
168 string cmd = args[ i ].Trim().ToUpper(); |
|
169 string nextArg = ( i < args.Length - 1 ? args[ i + 1 ].Trim().ToUpper() : string.Empty ); |
|
170 // |
|
171 try |
|
172 { |
|
173 if ( cmd == KParamPlugin && nextArg != string.Empty ) |
|
174 { |
|
175 ret = LocatePluginByName( nextArg ); |
|
176 break; |
|
177 } |
|
178 } |
|
179 catch ( Exception ) |
|
180 { |
|
181 } |
|
182 } |
|
183 // |
|
184 return ret; |
|
185 } |
|
186 |
|
187 private CAPlugin LocatePluginByName( string aName ) |
|
188 { |
|
189 CAPlugin ret = null; |
|
190 // |
|
191 foreach ( CAPlugin plugin in iEngine ) |
|
192 { |
|
193 bool isHandler = plugin.IsCommandLineHandler( aName ); |
|
194 if ( isHandler ) |
|
195 { |
|
196 ret = plugin; |
|
197 break; |
|
198 } |
|
199 } |
|
200 // |
|
201 return ret; |
|
202 } |
|
203 #endregion |
|
204 |
|
205 #region Data members |
|
206 private readonly CAEngine iEngine; |
|
207 private readonly FSLog iLog; |
|
208 #endregion |
|
209 } |
|
210 } |