OpenKeyWord  Version: 426, Datum:
Log2HTMLFile.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 
50  public class Log2HTMLFile : ILogger
51  {
52  #region Fields
53 
54  string BlanksBefore = string.Empty;
55  int ID = 1;
56  int LevelCounter = 0;
57  StreamWriter myFile;
58  int myFileCounter = 0;
59  string myPathAndFile;
60 
61  #endregion Fields
62 
63  #region Constructors
64 
65  public Log2HTMLFile(string PathAndFile)
66  {
67  this.myPathAndFile = PathAndFile;
68  this.myFile = new StreamWriter(this.myPathAndFile, false);
69  this.myFile.Close();
70 
71  this.WriteHTMLHeader();
72  }
73 
74  ~Log2HTMLFile()
75  {
76  this.WriteHTMLFooter();
77  }
78 
79  #endregion Constructors
80 
81  #region Methods
82 
88  public void LogError(string fps_Message)
89  {
90  this.FileOpen();
91 
92  this.WriteBlockOpen("Error", "Error");
93  this.LevelCounter++;
94  this.BlankBefore();
95 
96  this.LogPrint(fps_Message);
97 
98  this.LevelCounter--;
99  this.BlankBefore();
100 
101  this.WriteBlockClose();
102  this.FileClose();
103  }
104 
110  public void LogException(string fps_Message)
111  {
112  this.FileOpen();
113 
114  this.WriteBlockOpen("Exception", "Exception");
115  this.LevelCounter++;
116  this.BlankBefore();
117 
118  this.LogPrint(fps_Message);
119 
120  this.LevelCounter--;
121  this.BlankBefore();
122 
123  this.WriteBlockClose();
124  this.FileClose();
125  }
126 
132  public void LogFunctionEnd()
133  {
134  this.FileOpen();
135 
136  this.WriteBlockClose();
137 
138  this.FileClose();
139  }
140 
146  public void LogFunctionEnd(string fps_Return)
147  {
148  this.FileOpen();
149 
150  this.ResOpenList("Return...");
151  this.LogPrint("\"" + fps_Return + "\"");
152  this.ResCloseList();
153 
154  this.WriteBlockClose();
155 
156  this.FileClose();
157  }
158 
164  public void LogFunctionEnd(bool fpb_Return)
165  {
166  string fpsBoolean = OKW_Helper.Boolean2String(fpb_Return);
167  this.FileOpen();
168 
169  this.ResOpenList("Return...");
170  this.LogPrint("\"" + fpsBoolean + "\"");
171  this.ResCloseList();
172 
173  this.WriteBlockClose();
174 
175  this.FileClose();
176  }
177 
183  public void LogFunctionEnd(List<string> fpls_Return)
184  {
185  this.FileOpen();
186 
187  this.ResOpenList("Return...");
188 
189  foreach (string Value in fpls_Return)
190  {
191  this.LogPrint(Value);
192  }
193 
194  this.ResCloseList();
195 
196  this.WriteBlockClose();
197 
198  this.FileClose();
199  }
200 
206  public void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
207  {
208  this.FileOpen();
209 
210  this.WriteBlockOpen("Method: " + fps_FunctionName, "Method");
211  this.ResOpenList("Parameter...");
212 
213  for (int i = 0; i < fpsParameter.Length; i += 2)
214  {
215  this.LogPrint(fpsParameter[i] + " = \"" + fpsParameter[i + 1] + "\"");
216  }
217 
218  this.ResCloseList();
219 
220  this.FileClose();
221 
222  return;
223  }
224 
230  public void LogKeyWordEnd()
231  {
232  this.FileOpen();
233  this.WriteBlockClose();
234  this.FileClose();
235  }
236 
242  public void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
243  {
244  String String2Print = fps_KeyWordName;
245 
246  // Keyword without parameter
247  if (fpsParameter.Length == 0)
248  {
249  // Keyword with one Parameter
250  String2Print = String2Print + "()";
251  }
252  // Keyword with one Parameter
253  else if (fpsParameter.Length == 1)
254  {
255  String2Print = String2Print + ": \"" + fpsParameter[0] + "\"";
256  }
257  // Keyword with two Parameters
258  else if (fpsParameter.Length == 2)
259  {
260  String2Print = String2Print + ": \"" + fpsParameter[0] + "\" = \"" + fpsParameter[1] + "\"";
261  }
262  // Keyword with more then two Parameters
263  else
264  {
265  String2Print = String2Print + "(\"" + fpsParameter[0] + "\"";
266 
267  for (int i = 1; i < fpsParameter.Length; i++)
268  {
269  String2Print = String2Print + ", \"" + fpsParameter[i] + "\"";
270  }
271 
272  String2Print = String2Print + ")";
273  }
274 
275  this.FileOpen();
276 
277  this.WriteBlockOpen(String2Print, "KeyWord");
278 
279  this.FileClose();
280 
281  return;
282  }
283 
289  public void LogPrint(string fps_Message)
290  {
291  this.FileOpen();
292 
293  this.myFile.WriteLine(this.BlanksBefore + "<p>");
294  this.myFile.WriteLine(this.BlanksBefore + fps_Message);
295  this.myFile.WriteLine(this.BlanksBefore + "</p>");
296 
297  this.FileClose();
298  }
299 
305  public void LogVerify(string fps_Actual, string fps_Expected)
306  {
307  this.FileOpen();
308 
309  if (fps_Actual == fps_Expected)
310  {
311  this.WriteBlockOpen("Passed", "Passed");
312  }
313  else
314  {
315  this.WriteBlockOpen("Error", "Error");
316  }
317 
318  this.LevelCounter++;
319  this.BlankBefore();
320 
321  this.myFile.WriteLine(this.BlanksBefore + "<p>");
322  this.myFile.WriteLine(this.BlanksBefore + "<code>Expected = " + fps_Expected + "</code><br/>");
323  this.myFile.WriteLine(this.BlanksBefore + "<code> Actual = " + fps_Actual + "</code>");
324  this.myFile.WriteLine(this.BlanksBefore + "</p>");
325 
326  this.LevelCounter--;
327  this.BlankBefore();
328 
329  this.WriteBlockClose();
330 
331  this.FileClose();
332  }
333 
339  public void LogWarning(string fps_Message)
340  {
341  this.FileOpen();
342 
343  this.WriteBlockOpen("Warning", "Warning");
344  this.LevelCounter++;
345  this.BlankBefore();
346 
347  this.LogPrint(fps_Message);
348 
349  this.LevelCounter--;
350  this.BlankBefore();
351 
352  this.WriteBlockClose();
353  this.FileClose();
354  }
355 
361  public void ResCloseList()
362  {
363  if (this.LevelCounter > 0)
364  {
365  this.LevelCounter--;
366  }
367  else
368  {
369  this.LevelCounter = 0;
370  throw new System.DivideByZeroException();
371  }
372 
373  this.BlankBefore();
374 
375  this.FileOpen();
376  this.WriteBlockClose();
377  this.FileClose();
378 
379  return;
380  }
381 
387  public void ResOpenList(string fps_Name)
388  {
389  this.FileOpen();
390  this.WriteBlockOpen(fps_Name, "Normal");
391  this.FileClose();
392 
393  this.LevelCounter++;
394  this.BlankBefore();
395  return;
396  }
397 
403  private void BlankBefore()
404  {
405  this.BlanksBefore = new string('\t', this.LevelCounter);
406  }
407 
408  private void FileClose()
409  {
410  this.myFileCounter--;
411 
412  if (this.myFileCounter <= 0)
413  {
414  this.myFileCounter = 0;
415  this.myFile.Flush();
416  this.myFile.Close();
417  }
418  }
419 
420  private void FileOpen()
421  {
422  if (this.myFileCounter <= 0)
423  {
424  this.myFileCounter = 1;
425  this.myFile = new StreamWriter(this.myPathAndFile, true);
426  }
427  else
428  {
429  this.myFileCounter++;
430  }
431  }
432 
433  private void WriteBlockClose()
434  {
435  this.myFile.Write(this.BlanksBefore);
436  this.myFile.WriteLine("</blockquote>");
437  }
438 
439  private void WriteBlockOpen(string fpsWert, string fpsHTMLClass)
440  {
441  this.myFile.Write(this.BlanksBefore);
442  this.myFile.WriteLine("<blockquote class=\"" + fpsHTMLClass + "\" id=\"IDOpen" + this.ID.ToString() + "\" style=\"display:block;\">");
443 
444  this.myFile.Write(this.BlanksBefore);
445  this.myFile.WriteLine("\t<a onclick=\"(document.getElementById('IDOpen" + this.ID.ToString() + "')).style.display='none';(document.getElementById('IDClose" + this.ID.ToString() + "')).style.display='block';\"> + " + fpsWert + "...</a>");
446 
447  this.myFile.Write(this.BlanksBefore);
448  this.myFile.WriteLine("</blockquote>");
449 
450  this.myFile.Write(this.BlanksBefore);
451  this.myFile.WriteLine("<blockquote class=\"" + fpsHTMLClass + "\" id=\"IDClose" + this.ID.ToString() + "\" style=\"display:none;\">");
452 
453  this.myFile.Write(this.BlanksBefore);
454  this.myFile.WriteLine("<a onclick=\"(document.getElementById('IDOpen" + this.ID.ToString() + "')).style.display='block';(document.getElementById('IDClose" + this.ID.ToString() + "')).style.display='none';\"> - " + fpsWert + "</a><br/>");
455 
456  this.ID = this.ID + 1;
457  }
458 
459  private void WriteHTMLFooter()
460  {
461  this.FileOpen();
462 
463  this.myFile.WriteLine("</body>");
464  this.myFile.WriteLine("</html>");
465 
466  this.FileClose();
467  }
468 
469  private void WriteHTMLHeader()
470  {
471  this.FileOpen();
472 
473  this.myFile.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
474  this.myFile.WriteLine("<html xmlns=\"http://www.w3.org/1999/xhtml\" >");
475 
476  this.myFile.WriteLine("<head>");
477  this.myFile.WriteLine("\t<title>TestPage Titel</title>");
478  this.myFile.WriteLine("\t<link href=\"Log2HTMLFile.css\" type=\"text/css\" rel=\"stylesheet\"></link>");
479  this.myFile.WriteLine("</head>");
480  this.myFile.WriteLine("<body>");
481 
482  this.FileClose();
483  }
484 
485  #endregion Methods
486  }
487 }
Klasse enthält OKW-Hilfsfunktionen.
Definition: OKW_Helper.cs:63
void LogKeyWordStart(string fps_KeyWordName, params string[] fpsParameter)
void LogWarning(string fps_Message)
LogWarning Function: Logs a warning to the results file.
void ResCloseList()
Closes the outline level.
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(string fps_Return)
void LogFunctionStart(string fps_FunctionName, params string[] fpsParameter)
void ResOpenList(string fps_Name)
void LogFunctionEnd(bool fpb_Return)
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: Log2HTMLFile.cs:88
void LogVerify(string fps_Actual, string fps_Expected)
void LogFunctionEnd(List< string > fpls_Return)
static string Boolean2String(bool fpbTrueOrFalse)
Konvertiert bool true/false nach string "true"/"false".
Definition: OKW_Helper.cs:108
Definition: Core.cs:40