OpenKeyWord  Version: 426, Datum:
OKW_Ini.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
43 {
44  using System;
45  using System.IO;
46  using System.Linq;
47  using System.Xml.Serialization;
48 
49  using OKW.Log;
50  using System.Reflection;
51 
188  public class OKW_Ini
189  {
190  #region Fields
191 
205 
220 
233  private static OKW_Ini _Instance;
234 
235  Logger Log = Logger.Instance;
236 
237  #endregion Fields
238 
239  #region Constructors
240 
276  public OKW_Ini()
277  {
278  }
279 
280  #endregion Constructors
281 
282  #region Properties
283 
306  public static OKW_Ini Instance {
307  get {
308  Logger.Instance.LogFunctionStartDebug("OKW_Ini.Instance");
309  if (_Instance == null) {
310  _Instance = new OKW_Ini();
311  _Instance.Init();
312  }
313 
314  Logger.Instance.LogFunctionEndDebug();
315  return _Instance;
316  }
317  }
318 
319  #endregion Properties
320 
321  #region Methods
322 
338  public static void Reset()
339  {
340  _Instance = null;
341  }
342 
412  public void Init()
413  {
414  Log.LogFunctionStart(this.GetType().FullName + ".Init");
415 
416  // Klassen Variablen erst löschen...
417  this.OKW_Enviroment.File_OKW_Ini_xml = string.Empty;
418  this.OKW_Enviroment.Folder_XML = string.Empty;
419 
420  // ... und dann alles Initialisieren!
421  try {
422  // 1. Lese OKWINI-Ümgebungsvariable
423  this.OKW_Enviroment.Folder_XML = System.Environment.GetEnvironmentVariable("OKW_Xml");
424 
425  // Ist die Umgebungsvariable gesetzt?
426  if (string.IsNullOrEmpty(this.OKW_Enviroment.Folder_XML))
427  {
428  // OKW_Xml ist nicht gesetzt -> OKW_Ini_xml auf Assambly Verzeichnis setzen...
429  this.OKW_Enviroment.Folder_XML = Path.Combine(MyDirectory(), "XML");
430  }
431 
432  // Existiert die Datei?
433  bool bXML_Folder_Exists = System.IO.Directory.Exists(this.OKW_Enviroment.Folder_XML);
434 
435  if (bXML_Folder_Exists)
436  {
437  this.OKW_Enviroment.Folder_LogMessages = Path.Combine(this.OKW_Enviroment.Folder_XML, "LogMessages");
438  this.OKW_Enviroment.File_OKW_Ini_xml = Path.Combine(this.OKW_Enviroment.Folder_XML, "OKW_Ini.xml");
439  // Datei Existiert -> Lesen der Daten
440 
441  // Existiert die Datei?
442  bool bFile_OKW_Ini_xml_Exists = System.IO.File.Exists(this.OKW_Enviroment.File_OKW_Ini_xml);
443 
444  if (bFile_OKW_Ini_xml_Exists)
445  {
446  Log.LogPrint("Folder_XML: >>" + this.OKW_Enviroment.Folder_XML + "<<");
447 
448  }
449  else
450  {
451  this.Save();
452  }
453  this.LogAll();
454 
455  } else {
456  // Verzeichniss fehlt: Abbruch!
457  throw new OKWFileDoesNotExistsException("Directory not found: >>" + this.OKW_Enviroment.Folder_XML + "<<");
458  }
459  } finally
460  {
461  this.Log.LogFunctionEnd();
462  }
463 
464  return;
465  }
466 
482  public void Read()
483  {
484  this.Log.LogFunctionStartDebug(this.GetType().FullName + "Read()");
485 
486  try {
487  XmlSerializer serializer = new XmlSerializer(typeof(OKW_Ini));
488  StreamReader fs = new StreamReader(this.OKW_Enviroment.File_OKW_Ini_xml);
489  _Instance = (OKW_Ini)serializer.Deserialize(fs);
490  fs.Close();
491  }
492  finally
493  {
494  this.Log.LogFunctionEndDebug();
495  }
496 
497  return;
498  }
499 
500  public void LogAll()
501  {
502 
503  this.Log.ResOpenList("Enviroment...");
504 
505  try {
506 
507  Log.LogPrint("----------------------------------------------------------------" );
508  Log.LogPrint(" Assambly Path: " + this.MyDirectory() );
509  Log.LogPrint("----------------------------------------------------------------");
510  Log.LogPrint(" OKW_Ini.xml Path: " + this.OKW_Enviroment.File_OKW_Ini_xml);
511  Log.LogPrint(" OKW_Const.xml Path: " + this.OKW_Enviroment.File_OKW_Const_xml);
512  Log.LogPrint(" OKW_Docu.xml Path: " + this.OKW_Enviroment.File_OKW_Docu_xml);
513  Log.LogPrint(" OKW_Keymap.xml Path: " + this.OKW_Enviroment.File_OKW_Keymaps_xml);
514  Log.LogPrint("OKW_Memorize.xml Path: " + this.OKW_Enviroment.File_OKW_Memorize_xml);
515  Log.LogPrint("----------------------------------------------------------------");
516  Log.LogPrint("OKW_ImplementationMatrix.xml Path: " + this.OKW_Enviroment.File_OKW_ImplementationMatrix_xml);
517  Log.LogPrint("----------------------------------------------------------------");
518  Log.LogPrint( " XML Verzechnis: " + this.OKW_Enviroment.Folder_XML );
519  Log.LogPrint( " LogMessanges: " + this.OKW_Enviroment.Folder_LogMessages );
520  Log.LogPrint( "----------------------------------------------------------------" );
521  Log.LogPrint( " Language: " + this.OKW_CustomSettings.Language );
522  Log.LogPrint( " PathSep: " + this.OKW_CustomSettings.PathSep );
523  Log.LogPrint( " TimeOutExists: " + this.OKW_CustomSettings.TimeOutExists );
524  Log.LogPrint( "TimeOutNotExists: " + this.OKW_CustomSettings.TimeOutNotExists );
525  Log.LogPrint( "----------------------------------------------------------------" );
526  }
527  finally {
528  this.Log.ResCloseList();
529  }
530 
531  return;
532  }
533 
549  public void Save()
550  {
551  Log.LogFunctionStartDebug(this.GetType().FullName + ".Save()");
552 
553  try {
554  XmlSerializer serializer = new XmlSerializer(typeof(OKW_Ini));
555  StreamWriter fs = new StreamWriter(this.OKW_Enviroment.File_OKW_Ini_xml, false);
556  serializer.Serialize(fs, _Instance);
557  fs.Close();
558  } finally {
559  Log.LogFunctionEndDebug();
560  }
561 
562  return;
563  }
564 
565 
578  public string MyDirectory()
579  {
580  string lvsReturn = string.Empty;
581 
582  Log.LogFunctionStartDebug(this.GetType().FullName + ".MyDirectory()");
583 
584  try {
585  string codeBase = Assembly.GetExecutingAssembly().CodeBase;
586  System.UriBuilder uri = new System.UriBuilder(codeBase);
587  string path = Uri.UnescapeDataString(uri.Path);
588  lvsReturn = Path.GetDirectoryName(path);
589  } finally {
590  Log.LogFunctionEndDebug(lvsReturn);
591  }
592  return lvsReturn;
593 
594  }
595 
596  #endregion Methods
597  }
598 }
string File_OKW_ImplementationMatrix_xml
Property get/set von __File_OKW_ImplementationMatrix_xml.
void LogPrint(string fps_Message)
LogPrint Function: Prints the values of expressions to the results file.
Definition: Logger.cs:302
void ResOpenList(string fps_Name)
Creates a new hierarchical level in the results file. Use ResOpenList to start a new hierarchical lev...
Definition: Logger.cs:426
string Folder_LogMessages
Property get/set von __Folder_LogMessages.
OKW_Ini()
Diese Klasse ist ein Singelton.
Definition: OKW_Ini.cs:276
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 File_OKW_Ini_xml
Property get/set von __File_OKW_Ini_xml.
string MyDirectory()
Ermittelt den Pfad zu assambly OKW.dll.
Definition: OKW_Ini.cs:578
string File_OKW_Const_xml
Property get/set von __File_OKW_Const_xml.
int TimeOutNotExists
Öffentliches Property "TimeOutNotExists".
OKW_Enviroment OKW_Enviroment
Dieses Feld hält den Abschnitt OKW_Enviroment der OKW_Ini.xml vor.
Definition: OKW_Ini.cs:219
void Init()
Initialsiert die Klasse OKW.OKW_Ini.
Definition: OKW_Ini.cs:412
string File_OKW_Keymaps_xml
Property get/set von __File_OKW_Keymaps_xml.
void Read()
Liest die Eigenschaften der Klasse OKW_Ini aus einer Datei, gegeben in OKW.OKW_Ini.Xml_Ini_xml, ein. Es wird eine XML Datei geschrieben. Hierzu wird die Klasse OKW_Ini mit System.Xml.XmlSerializer serialisiert.
Definition: OKW_Ini.cs:482
string File_OKW_Docu_xml
Property get/set von __File_OKW_Const_xml.
Property-Klasse von OKW.OKW_Ini. Stellt Umgebungseigenschaften von OKW zur Verfügung.
string Language
Öffentliches Property "Language".
string PathSep
Öffentliches Property "PathSep".
string Folder_XML
Property get/set von __Folder_XML.
static void Reset()
Löschen und zurücksetzten der Klasse.
Definition: OKW_Ini.cs:338
void Save()
Schreibt die Eigenschaften der Klasse OKW_Ini in eine Datei, gegeben in OKW.OKW_Ini.Xml_Ini_xml. Es wird eine XML Datei geschrieben. Hierzu wird die Klasse OKW_Ini mit der Klasse System.Xml.XmlSerializer serialisiert.
Definition: OKW_Ini.cs:549
OKW.OKW_Ini ist die Klasse zur Konfigurationsdatei OKW_Ini.xml.
Definition: OKW_Ini.cs:188
int TimeOutExists
Öffentliches Property "TimeOutExists".
static OKW_Ini _Instance
Singelton-Pattern: Feld enthält die einzige gültige Instanz dieser Klasse.
Definition: OKW_Ini.cs:233
Property-Klasse die Umgebungseigenschaften von OKW zur Verfügung stellt.
OKW_CustomSettings OKW_CustomSettings
Dieses Feld hält den Abschnitt OKW_CustomSettings der OKW_Ini.xml vor.
Definition: OKW_Ini.cs:204
void ResCloseList()
Closes a hierarchical level in the results file that was opened with ResOpenList. Use ResOpenList to ...
Definition: Logger.cs:392
Definition: Core.cs:40
string File_OKW_Memorize_xml
Property get/set von __File_OKW_Memorize_xml.