OpenKeyWord  Version: 426, Datum:
ImplementationMatrix.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 
43 {
44  using System;
45  using System.Collections.Generic;
46  using System.IO;
47  using System.Xml.Serialization;
48 
49  using OKW.Log;
50 
54  public class ImplementationMatrix
55  {
56  #region Fields
57 
64 
68  public List<string> cvKeywords = new List<string>();
69 
73  public List<string> cvNamesOfGUIClasses = new List<string>();
74 
83  public string OKW_ImplementationMatrix_xml = string.Empty;
84 
85  protected static ImplementationMatrix instance = null;
86 
87  private Logger Log = Logger.Instance;
88 
89  #endregion Fields
90 
91  #region Constructors
92 
97  {
98  this.finalizeMe = true;
99  }
100 
101  #endregion Constructors
102 
103  #region Properties
104 
111  public static ImplementationMatrix Instance
112  {
113  get
114  {
115  if ( instance == null)
116  {
117  instance = new ImplementationMatrix();
118  instance.Init();
119  }
120 
121  return instance;
122  }
123  }
124 
125  #endregion Properties
126 
127  #region Methods
128 
134  public string GetImplementation(string fpsKey)
135  {
136  string lvsReturn = string.Empty;
137 
138  if (this.cvImplementationMatrix.ContainsKey(fpsKey))
139  {
140  lvsReturn = this.cvImplementationMatrix[fpsKey];
141  }
142  else
143  {
144  lvsReturn = "?";
145  }
146 
147  return lvsReturn;
148  }
149 
157  public void Init()
158  {
159  this.Log.LogFunctionStartDebug(this.GetType().FullName + ".Init");
160 
161  // Klassen Variablen erst löschen...
162  this.OKW_ImplementationMatrix_xml = string.Empty;
163 
164  // Listen und Dictionary Löschen
165  this.cvImplementationMatrix.Clear();
166  this.cvKeywords.Clear();
167  this.cvNamesOfGUIClasses.Clear();
168 
169  // ... und dann alles Initialisieren!
170  // 1. Setze Pfad und
171  this.OKW_ImplementationMatrix_xml = OKW_Ini.Instance.OKW_Enviroment.File_OKW_ImplementationMatrix_xml;
172 
173  if (!string.IsNullOrEmpty(this.OKW_ImplementationMatrix_xml))
174  {
175  this.Log.LogPrintDebug("OKW Memorize Datei = >>" + this.OKW_ImplementationMatrix_xml + "<<");
176  if (System.IO.File.Exists(this.OKW_ImplementationMatrix_xml))
177  {
178  // Lesen der Daten
179  this.Read();
180  }
181  else
182  {
183  // Deafault werte Lesen.
184  this.Log.LogWarning("Datei: >>" + this.OKW_ImplementationMatrix_xml + "<< nicht gefunden.");
185  }
186  }
187  else
188  {
189  this.Log.LogWarning("Enviroment variable 'OKWIni' not set!");
190  }
191 
192  this.Log.LogFunctionEndDebug();
193  return;
194  }
195 
203  public void Read()
204  {
205  this.Log.LogFunctionStartDebug( this.GetType().FullName + "Read()");
206 
207  try
208  {
209  XmlSerializer serializer = new XmlSerializer(typeof(ImplementationMatrix));
210  StreamReader fs = new StreamReader(this.OKW_ImplementationMatrix_xml);
211  instance = (ImplementationMatrix)serializer.Deserialize(fs);
212  fs.Close();
213  }
214  finally
215  {
216  this.Log.LogFunctionEndDebug();
217  }
218 
219  return;
220  }
221 
229  public void Save()
230  {
231  this.Log.LogFunctionStartDebug(instance.GetType().FullName + "Save()");
232 
233  try
234  {
235  XmlSerializer serializer = new XmlSerializer(typeof(ImplementationMatrix));
236  StreamWriter fs = new StreamWriter(this.OKW_ImplementationMatrix_xml, false);
237  serializer.Serialize(fs, instance);
238  fs.Close();
239  }
240  finally
241  {
242  this.Log.LogFunctionEndDebug();
243  }
244 
245  return;
246  }
247 
258  public void SetImplementation(string fpsNameOfGUIClass, string fpsKeyWord, string fpsImplemented)
259  {
260  this.AddNameOfGUIClass(fpsNameOfGUIClass);
261  this.AddKeyword(fpsKeyWord);
262 
263  string lvskey = fpsNameOfGUIClass + ";" + fpsKeyWord;
264 
265  if (fpsImplemented == "P" || fpsImplemented == "F" || fpsImplemented == "N")
266  {
267  this.AddImplementation(lvskey, fpsImplemented);
268  }
269  else{
270  throw new OKWNotAllowedValueException("Nur Werte 'Y' und 'N' sind erlaubt");
271  }
272 
273  return;
274  }
275 
276  public void WriteResultXML()
277  {
278  string lvskey;
279 
280  foreach (string lvsKeyword in this.cvKeywords)
281  {
282  foreach (string lvsClassName in this.cvNamesOfGUIClasses)
283  {
284  lvskey = lvsClassName + ";" + lvsKeyword;
285 
286  System.Console.WriteLine("<td>" + this.GetImplementation(lvskey) + "</td>");
287  }
288  }
289 
290  return;
291  }
292 
300  private void AddImplementation(string fpsKey, string fpsImplemented)
301  {
302  if (this.cvImplementationMatrix.ContainsKey(fpsKey))
303  {
304  if (fpsImplemented=="F" & this.cvImplementationMatrix[fpsKey] == "N")
305  {
306  throw new Exception("001: Fehler in Matrix: " + this.cvImplementationMatrix[fpsKey] + "-Wert kann nicht auf 'F' gesetzt werden.");
307  }
308  if (fpsImplemented=="F" & this.cvImplementationMatrix[fpsKey] == "F")
309  {
310  this.cvImplementationMatrix[fpsKey] = "F";
311  }
312  if (fpsImplemented=="F" & this.cvImplementationMatrix[fpsKey] == "P")
313  {
314  this.cvImplementationMatrix[fpsKey] = "F";
315  }
316  if (fpsImplemented=="P" & this.cvImplementationMatrix[fpsKey] == "N")
317  {
318  throw new Exception("002: Fehler in Matrix: " + this.cvImplementationMatrix[fpsKey] + "-Wert kann nicht auf 'P' gesetzt werden.");
319  }
320  if (fpsImplemented=="P" & this.cvImplementationMatrix[fpsKey] == "F")
321  {
322  this.cvImplementationMatrix[fpsKey] = "F";
323  }
324  if (fpsImplemented=="N" & this.cvImplementationMatrix[fpsKey] == "P")
325  {
326  throw new Exception("003: Fehler in Matrix: " + this.cvImplementationMatrix[fpsKey] + "-Wert kann nicht auf 'N' gesetzt werden.");
327  }
328  if (fpsImplemented=="N" & this.cvImplementationMatrix[fpsKey] == "F")
329  {
330  throw new Exception("004: Fehler in Matrix: " + this.cvImplementationMatrix[fpsKey] + "-Wert kann nicht auf 'N' gesetzt werden.");
331  }
332  if (fpsImplemented=="N" & this.cvImplementationMatrix[fpsKey] == "N")
333  {
334  this.cvImplementationMatrix[fpsKey] = "N";
335  }
336  }
337  else
338  {
339  this.cvImplementationMatrix.Add(fpsKey,fpsImplemented);
340  }
341 
342  return;
343  }
344 
345  public void SaveAs_CSV()
346  {
347  string lvsZeile;
348  System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\temp\ImplementationMatrix\ImplementationMatrix.csv");
349 
350  // Spaltenköpfe schreiben
351  lvsZeile = "GUI-Class";
352  foreach ( string Keyword in this.cvKeywords )
353  {
354  lvsZeile = lvsZeile + ";" + Keyword;
355  }
356  file.WriteLine(lvsZeile);
357 
358  // Body Schreiben
359  foreach ( string GUIKlassName in this.cvNamesOfGUIClasses )
360  {
361  lvsZeile = GUIKlassName;
362 
363  foreach ( string Keyword in this.cvKeywords )
364  {
365  lvsZeile = lvsZeile + ";" + this.GetImplementation(GUIKlassName + ";" + Keyword);
366  }
367 
368  file.WriteLine(lvsZeile);
369  }
370 
371  file.Close();
372 
373  return;
374  }
375 
376  public void SaveAs_HTML()
377  {
378  System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\temp\ImplementationMatrix\ImplementationMatrix.html");
379 //
380  file.WriteLine("<html>");
381  file.WriteLine(" <head>");
382 
383  file.WriteLine(" <style type=\"text/css\">");
384  file.WriteLine(" td.P{");
385  file.WriteLine(" text-align:center;");
386  file.WriteLine(" background-color:#00FF00;");
387  file.WriteLine(" }");
388  file.WriteLine(" td.F{");
389  file.WriteLine(" text-align:center;");
390  file.WriteLine(" background-color:#FF0000;");
391  file.WriteLine(" }");
392  file.WriteLine(" td.N{");
393  file.WriteLine(" text-align:center;");
394  file.WriteLine(" background-color:#000000;");
395  file.WriteLine(" }");
396 
397  file.WriteLine(" th.rotate {");
398  file.WriteLine(" /* Something you can count on */");
399  file.WriteLine(" height: 200px;");
400  file.WriteLine(" white-space: nowrap;");
401  file.WriteLine(" }");
402 
403  file.WriteLine(" th.rotate > div {");
404  file.WriteLine(" transform: ");
405  file.WriteLine(" /* Magic Numbers */");
406  file.WriteLine(" translate(0px, 90px)");
407  file.WriteLine(" /* 45 is really 360 - 45 */");
408  file.WriteLine(" rotate(-90deg);");
409  file.WriteLine(" width: 25px;");
410  file.WriteLine(" }");
411  file.WriteLine(" th.rotate > div > span {");
412  file.WriteLine(" padding: 5px 10px;");
413  file.WriteLine(" }");
414 
415  file.WriteLine(" </style>");
416 
417  file.WriteLine(" </head>");
418 
419  file.WriteLine(" <body>");
420 
421  file.WriteLine(" <table border=\"1\">");
422  file.WriteLine(" <tr>");
423  // Spaltenköpfe schreiben
424  file.WriteLine(" <th>GUI-Class</th>");
425  foreach ( string Keyword in this.cvKeywords )
426  {
427  file.WriteLine(" <th class=\"rotate\"><div><span>" + Keyword + "</span></div></th>");
428  }
429  file.WriteLine(" </tr>");
430 
431 
432  // Body Schreiben
433  foreach ( string GUIKlassName in this.cvNamesOfGUIClasses )
434  {
435  file.WriteLine(" <tr>");
436  file.WriteLine(" <th>" + GUIKlassName + "</th>");
437 
438  foreach ( string Keyword in this.cvKeywords )
439  {
440  string Wert = this.GetImplementation(GUIKlassName + ";" + Keyword);
441  file.WriteLine(" <td class=\""+ Wert +"\" align=\"center\">" + Wert + "</td>");
442  }
443 
444  file.WriteLine(" </tr>");
445  }
446  file.WriteLine(" </table>");
447 
448  file.WriteLine(" </body>");
449  file.WriteLine("</html>");
450  file.Close();
451 
452  return;
453  }
454 
455 
461  private void AddKeyword(string fpsKeyword)
462  {
463  if (!this.cvKeywords.Contains(fpsKeyword))
464  {
465  this.cvKeywords.Add(fpsKeyword);
466  }
467 
468  return;
469  }
470 
476  private void AddNameOfGUIClass(string fpsNameOfGUIClass)
477  {
478  if (!this.cvNamesOfGUIClasses.Contains(fpsNameOfGUIClass))
479  {
480  this.cvNamesOfGUIClasses.Add(fpsNameOfGUIClass);
481  }
482 
483  return;
484  }
485 
486  bool finalizeMe;
488  {
489  if (this.finalizeMe)
490  {
491  this.SaveAs_HTML();
492  this.Save();
493  this.finalizeMe=false;
494  }
495  }
496 
497  #endregion Methods
498  }
499 }
string File_OKW_ImplementationMatrix_xml
Property get/set von __File_OKW_ImplementationMatrix_xml.
static OKW_Ini Instance
Singelton-Pattern: Instanz gibt die aktuelle, gültige und einzige Innstanz der Klasse zurück...
Definition: OKW_Ini.cs:306
string GetImplementation(string fpsKey)
Holt die Implementierung eines Schlüsselwortes für ein Object.
OKW_Enviroment OKW_Enviroment
Dieses Feld hält den Abschnitt OKW_Enviroment der OKW_Ini.xml vor.
Definition: OKW_Ini.cs:219
ImplementationMatrix()
Privater Konstruktor als singelton.
ImplentationMatrix wird für die Dokumentaion des Implmentierungs fortschrittes verwendet.
void AddImplementation(string fpsKey, string fpsImplemented)
Fügt eine neue Implementierung der Dictionary cvImplementationMatrix hinzu. Existiert dieser (=fpsKey...
void AddNameOfGUIClass(string fpsNameOfGUIClass)
Fügt den Namen einer Klasse der List cvNamesOfGUIClasses zu, wenn dieser noch nicht in der Liste ist...
void LogPrintDebug(string fpsMessage)
Loggt eine Nachricht.
Definition: Logger.cs:332
OKW.OKW_Ini ist die Klasse zur Konfigurationsdatei OKW_Ini.xml.
Definition: OKW_Ini.cs:188
void LogWarning(string fps_Message)
LogWarning Function: Logs a warning to the results file.
Definition: Logger.cs:377
void SetImplementation(string fpsNameOfGUIClass, string fpsKeyWord, string fpsImplemented)
Setzt die Implementierung eines Schlüsselwortes für ein Object.
void AddKeyword(string fpsKeyword)
Fügt ein Schlüsselwort der List zu wen dieser noch nicht in der Liste ist. Ziel: Eindeutige List der ...
Definition: Core.cs:40