OpenKeyWord  Version: 426, Datum:
Log2ConsoleFile.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.IO;
47  using System.Linq;
48  using System.Text;
49 
63  public class Log2ConsoleFile : ILogger
64  {
65  #region Fields
66 
67  string BlanksBefore = string.Empty;
68  int LevelCounter = 0;
69  StreamWriter myFile;
70  int myFileCounter = 0;
71  string myPathAndFile;
72 
73  #endregion Fields
74 
75  #region Constructors
76 
77  public Log2ConsoleFile(string PathAndFile)
78  {
79  // \todo TODO: Parser einbauen...
80  this.myPathAndFile = PathAndFile;
81  this.myFile = new StreamWriter(this.myPathAndFile, false);
82  this.myFile.Close();
83  }
84 
85  #endregion Constructors
86 
87  #region Methods
88 
94  public void LogError(string fps_Message)
95  {
96  this.FileOpen();
97 
98  this.myFile.Write(this.BlanksBefore + "Error: ");
99  this.myFile.WriteLine(fps_Message);
100 
101  this.FileClose();
102  }
103 
109  public void LogException(string fps_Message)
110  {
111  this.FileOpen();
112 
113  this.myFile.Write(this.BlanksBefore + "Exception: ");
114  this.myFile.WriteLine(fps_Message);
115 
116  this.FileClose();
117  }
118 
124  public void LogFunctionEnd()
125  {
126  this.FileOpen();
127 
128  this.ResCloseList();
129 
130  this.FileClose();
131  }
132 
138  public void LogFunctionEnd(string fps_Return)
139  {
140  this.FileOpen();
141 
142  this.ResOpenList("Return...");
143  this.LogPrint(">>" + fps_Return + "<<");
144  this.ResCloseList();
145 
146  this.ResCloseList();
147 
148  this.FileClose();
149  }
150 
156  public void LogFunctionEnd(bool fpb_Return)
157  {
158  string fpsBoolean = OKW_Helper.Boolean2String(fpb_Return);
159  this.FileOpen();
160 
161  this.ResOpenList("Return...");
162  this.LogPrint(">>" + fpsBoolean + "<<");
163  this.ResCloseList();
164 
165  this.ResCloseList();
166 
167  this.FileClose();
168  }
169 
175  public void LogFunctionEnd(List<string> fpls_Return)
176  {
177  this.FileOpen();
178 
179  this.ResOpenList("Return...");
180 
181  foreach (string Value in fpls_Return)
182  {
183  this.LogPrint(Value);
184  }
185 
186  this.ResCloseList();
187 
188  this.ResCloseList();
189 
190  this.FileClose();
191  }
192 
198  public void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
199  {
200  this.ResOpenList("Method: " + fps_FunctionName);
201 
202  if (0 < fpsParameter.Length)
203  {
204  this.ResOpenList("Parameter...");
205 
206  for (int i = 0; i < fpsParameter.Length; i += 2)
207  {
208  this.LogPrint(fpsParameter[i] + ": >>" + fpsParameter[i + 1] + "<<");
209  }
210 
211  this.ResCloseList();
212  this.LogPrint("-------");
213  }
214 
215  return;
216  }
217 
218 
224  public void LogKeyWordEnd()
225  {
226  this.ResCloseList();
227  }
228 
234  public void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
235  {
236  String String2Print = fps_KeyWordName;
237 
238  // Keyword without parameter
239  if (fpsParameter.Length == 0)
240  {
241  // Keyword with one Parameter
242  String2Print = String2Print + "()";
243  }
244  // Keyword with one Parameter
245  else if (fpsParameter.Length == 1)
246  {
247  String2Print = String2Print + ": \"" + fpsParameter[0] + "\"";
248  }
249  // Keyword with two Parameters
250  else if (fpsParameter.Length == 2)
251  {
252  String2Print = String2Print + ": \"" + fpsParameter[0] + "\" = \"" + fpsParameter[1] + "\"";
253  }
254  // Keyword with more then two Parameters
255  else
256  {
257  String2Print = String2Print + "(\"" + fpsParameter[0] + "\"";
258 
259  for (int i = 1; i < fpsParameter.Length; i++)
260  {
261  String2Print = String2Print + ", \"" + fpsParameter[i] + "\"";
262  }
263 
264  String2Print = String2Print + ")";
265  }
266 
267  this.ResOpenList(String2Print);
268 
269  return;
270  }
271 
272 
278  public void LogPrint(string fps_Message)
279  {
280  this.FileOpen();
281 
282  this.myFile.WriteLine(this.BlanksBefore + fps_Message);
283 
284  this.FileClose();
285  }
286 
292  public void LogVerify(string fps_Actual, string fps_Expected)
293  {
294  this.FileOpen();
295 
296  if (fps_Actual == fps_Expected)
297  {
298  this.ResOpenList("PASSED:");
299  }
300  else
301  {
302  this.ResOpenList("FAILED:");
303  }
304 
305  this.myFile.WriteLine(this.BlanksBefore + "Expected = >>" + fps_Expected + "<<");
306  this.myFile.WriteLine(this.BlanksBefore + " Actual = >>" + fps_Actual + "<<");
307 
308  this.ResCloseList();
309 
310  this.FileClose();
311  }
312 
318  public void LogWarning(string fps_Message)
319  {
320  this.FileOpen();
321 
322  this.myFile.Write(this.BlanksBefore + "Warning: ");
323  this.myFile.WriteLine(fps_Message);
324 
325  this.FileClose();
326  }
327 
333  public void ResCloseList()
334  {
335  if (this.LevelCounter > 0)
336  {
337  this.LevelCounter--;
338  }
339  else
340  {
341  this.LevelCounter = 0;
342  }
343 
344  this.BlankBefore();
345  }
346 
352  public void ResOpenList(string fps_Name)
353  {
354  this.FileOpen();
355 
356  this.LogPrint(fps_Name);
357  this.LevelCounter++;
358  this.BlankBefore();
359 
360  this.FileClose();
361  }
362 
368  private void BlankBefore()
369  {
370  this.BlanksBefore = new string('\t', this.LevelCounter);
371  }
372 
373  private void FileClose()
374  {
375  this.myFileCounter--;
376 
377  if (this.myFileCounter <= 0)
378  {
379  this.myFileCounter = 0;
380 
381  this.myFile.Flush();
382  this.myFile.Close();
383  }
384  }
385 
386  private void FileOpen()
387  {
388  if (this.myFileCounter <= 0)
389  {
390  this.myFileCounter = 1;
391  this.myFile = new StreamWriter(this.myPathAndFile, true);
392  }
393  else
394  {
395  this.myFileCounter++;
396  }
397  }
398 
399  #endregion Methods
400  }
401 }
void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
Klasse enthält OKW-Hilfsfunktionen.
Definition: OKW_Helper.cs:63
void LogError(string fps_Message)
LogError Function: Logs an error message to the results file.
void ResCloseList()
Closes the outline level.
void LogVerify(string fps_Actual, string fps_Expected)
void LogWarning(string fps_Message)
LogWarning Function: Logs a warning to the results file.
void LogPrint(string fps_Message)
LogPrint Function: Prints the values of expressions to the results file.
void LogException(string fps_Message)
LogException Function: Logs a Script Exception to the results file.
void LogFunctionEnd(List< string > fpls_Return)
void ResOpenList(string fps_Name)
Debug Logs are not a part of Interface. This functions are Implemented in Logger.cs a Log*Debug funct...
Definition: ILogger.cs:62
void LogFunctionEnd(bool fpb_Return)
Klasse zur Ausgabe in eine Datei.
void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
void LogFunctionEnd(string fps_Return)
static string Boolean2String(bool fpbTrueOrFalse)
Konvertiert bool true/false nach string "true"/"false".
Definition: OKW_Helper.cs:108
Definition: Core.cs:40