OpenKeyWord  Version: 426, Datum:
Log2Console.cs
1 #region Header
2 /*
3  ==============================================================================
4  Author: Zoltan Hrabovszki <zh@openkeyword.de>
5 
6  Copyright © 2012, 2013, 2014, 2015 IT-Beratung Hrabovszki
7  www.OpenKeyWord.de
8  ==============================================================================
9 
10  This file is part of OpenKeyWord.
11 
12  OpenKeyWord is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  OpenKeyWord is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with OpenKeyWord. If not, see <http://www.gnu.org/licenses/>.
24 
25  Diese Datei ist Teil von OpenKeyWord.
26 
27  OpenKeyWord ist Freie Software: Sie können es unter den Bedingungen
28  der GNU General Public License, wie von der Free Software Foundation,
29  Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
30  veröffentlichten Version, weiterverbreiten und/oder modifizieren.
31 
32  OpenKeyWord wird in der Hoffnung, dass es nützlich sein wird, aber
33  OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
34  Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
35  Siehe die GNU General Public License für weitere Details.
36 
37  Sie sollten eine Kopie der GNU General Public License zusammen mit
38  OpenKeyWord erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
39 */
40 #endregion Header
41 
42 namespace OKW.Log
43 {
44  using System;
45  using System.Collections.Generic;
46  using System.Text;
47 
48  /* http://www.csharp-examples.net/indent-string-with-spaces/ */
49 
69  public class Log2Console : ILogger
70  {
71  #region Fields
72 
73  string BlanksBefore = string.Empty;
74  int LevelCounter = 0;
75 
76  #endregion Fields
77 
78  #region Methods
79 
85  public void LogError(string fps_Message)
86  {
87  Console.ForegroundColor = ConsoleColor.Red;
88  Console.Write(this.BlanksBefore + "Error: ");
89  Console.ResetColor();
90  Console.WriteLine(fps_Message);
91  }
92 
98  public void LogException(string fps_Message)
99  {
100  Console.ForegroundColor = ConsoleColor.Magenta;
101  Console.Write(this.BlanksBefore + "Exception: ");
102  Console.ResetColor();
103  Console.WriteLine(fps_Message);
104  }
105 
111  public void LogFunctionEnd()
112  {
113  this.LogPrint("-------");
114  this.ResCloseList();
115  }
116 
122  public void LogFunctionEnd(string fps_Return)
123  {
124  this.ResOpenList("Return...");
125  this.LogPrint(fps_Return);
126  this.ResCloseList();
127  this.LogPrint("-------");
128  this.ResCloseList();
129  }
130 
136  public void LogFunctionEnd(bool fpb_Return)
137  {
138  this.ResOpenList("Return...");
139  this.LogPrint(fpb_Return.ToString());
140  this.ResCloseList();
141  this.LogPrint("-------");
142  this.ResCloseList();
143  }
144 
150  public void LogFunctionEnd(List<string> fpls_Return)
151  {
152  this.ResOpenList("Return...");
153 
154  foreach (string Value in fpls_Return)
155  {
156  this.LogPrint(Value);
157  }
158 
159  this.ResCloseList();
160  this.LogPrint("-------");
161  this.ResCloseList();
162  }
163 
169  public void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
170  {
171  this.ResOpenList(fps_FunctionName);
172  this.ResOpenList("Parameter...");
173 
174  for (int i = 0; i < fpsParameter.Length; i += 2)
175  {
176  this.LogPrint(fpsParameter[i] + ": >>" + fpsParameter[i + 1] + "<<");
177  }
178 
179  this.ResCloseList();
180  this.LogPrint("-------");
181 
182  return;
183  }
184 
190  public void LogKeyWordEnd()
191  {
192  this.ResCloseList();
193  }
194 
200  public void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
201  {
202  String String2Print = fps_KeyWordName;
203 
204  // Keyword without parameter
205  if (fpsParameter.Length == 0)
206  {
207  // Keyword with one Parameter
208  String2Print = String2Print + "()";
209  }
210  // Keyword with one Parameter
211  else if (fpsParameter.Length == 1)
212  {
213  String2Print = String2Print + ": \"" + fpsParameter[0] + "\"";
214  }
215  // Keyword with two Parameters
216  else if (fpsParameter.Length == 2)
217  {
218  String2Print = String2Print + ": \"" + fpsParameter[0] + "\" = \"" + fpsParameter[1] + "\"";
219  }
220  // Keyword with more then two Parameters
221  else
222  {
223  String2Print = String2Print + "(\"" + fpsParameter[0] + "\"";
224 
225  for (int i = 1; i < fpsParameter.Length; i++)
226  {
227  String2Print = String2Print + ", \"" + fpsParameter[i] + "\"";
228  }
229 
230  String2Print = String2Print + ")";
231  }
232 
233  this.ResOpenList(String2Print);
234 
235  return;
236  }
237 
243  public void LogPrint(string fps_Message)
244  {
245  Console.ResetColor();
246  Console.WriteLine(this.BlanksBefore + fps_Message);
247  }
248 
254  public void LogVerify(string fps_Actual, string fps_Expected)
255  {
256  Console.WriteLine(this.BlanksBefore + "Expected = >>" + fps_Expected + "<<");
257 
258  if (fps_Actual == fps_Expected)
259  {
260  Console.ForegroundColor = ConsoleColor.DarkGreen;
261  }
262  else
263  {
264  Console.ForegroundColor = ConsoleColor.Red;
265  }
266 
267  Console.WriteLine(this.BlanksBefore + " Actual = >>" + fps_Actual + "<<");
268  Console.ResetColor();
269  }
270 
276  public void LogWarning(string fps_Message)
277  {
278  Console.ForegroundColor = ConsoleColor.Yellow;
279  Console.Write(this.BlanksBefore + "Warning: ");
280  Console.ResetColor();
281  Console.WriteLine(fps_Message);
282  }
283 
289  public void ResCloseList()
290  {
291  if (this.LevelCounter > 0)
292  {
293  this.LevelCounter--;
294  }
295  else
296  {
297  this.LevelCounter = 0;
298  }
299 
300  this.BlankBefore();
301  }
302 
308  public void ResOpenList(string fps_Name)
309  {
310  this.LogPrint(fps_Name);
311  this.LevelCounter++;
312  this.BlankBefore();
313  }
314 
320  private void BlankBefore()
321  {
322  this.BlanksBefore = new string(' ', this.LevelCounter);
323  }
324 
325  #endregion Methods
326  }
327 }
void LogPrint(string fps_Message)
LogPrint Function: Prints the values of expressions to the results file.
Definition: Log2Console.cs:243
void ResCloseList()
Closes the outline level.
Definition: Log2Console.cs:289
void LogFunctionEnd(string fps_Return)
Definition: Log2Console.cs:122
void LogWarning(string fps_Message)
LogWarning Function: Logs a warning to the results file.
Definition: Log2Console.cs:276
void LogException(string fps_Message)
LogException Function: Logs a Script Exception to the results file.
Definition: Log2Console.cs:98
void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
Definition: Log2Console.cs:200
void LogFunctionEnd(bool fpb_Return)
Definition: Log2Console.cs:136
void LogVerify(string fps_Actual, string fps_Expected)
Definition: Log2Console.cs:254
Klasse zur Ausgabe in die Console.
Definition: Log2Console.cs:69
void LogFunctionEnd(List< string > fpls_Return)
Definition: Log2Console.cs:150
void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
Definition: Log2Console.cs:169
void ResOpenList(string fps_Name)
Definition: Log2Console.cs:308
Debug Logs are not a part of Interface. This functions are Implemented in Logger.cs a Log*Debug funct...
Definition: ILogger.cs:62
void LogError(string fps_Message)
LogError Function: Logs an error message to the results file.
Definition: Log2Console.cs:85
Definition: Core.cs:40