OpenKeyWord  Build Tag: jenkins-DoxyGen_EN-107, Build ID: 2015-03-08_20-51-06
 All Classes Namespaces Functions Variables Properties Pages
OKW.OKW_Ini Class Reference

OKW.OKW_Ini is the related class to the configuration file OKW_Ini.xml.
More...

Collaboration diagram for OKW.OKW_Ini:

Public Member Functions

 OKW_Ini ()
 This class is a Singelton. More...
 
void Init ()
 Initializes the class OKW.OKW_Ini. More...
 
void Read ()
 Reads the properties of the class OKW_Ini from a file, given in OKW.OKW_Ini.Xml_Ini_xml. An XML file is written. For this purpose the class OKW_Ini is serialized with System.Xml.XmlSerializer. More...
 
void Save ()
 Writes the property of the class OKW_Ini in a file, given in OKW.OKW_Ini.Xml_Ini_xml. An XML file is written. For this purpose the class OKW_Ini with the class System.Xml.XmlSerializer is serialized. More...
 

Static Public Member Functions

static void Reset ()
 Deleting and resetting of the class. More...
 

Public Attributes

OKW_CustomSettings OKW_CustomSettings = new OKW_CustomSettings()
 This field has in store the section OKW_CustomSettings of OKW_Ini.xml. More...
 
OKW_Enviroment OKW_Enviroment = new OKW_Enviroment()
 This field has in store the section OKW_Enviroment of OKW_Ini.xml. More...
 
string Xml_Ini_xml = string.Empty
 Variable has in store the path- and filename of OKW_Ini.xml. More...
 

Properties

static OKW_Ini Instance [get]
 Singelton-Pattern: instance returns the actual valid and only instance of the class. More...
 

Private Attributes

Logger Log = Logger.Instance
 

Static Private Attributes

static OKW_Ini _Instance
 Singelton-Pattern: Field contains the only valid instance of this class. More...
 

Detailed Description

OKW.OKW_Ini is the related class to the configuration file OKW_Ini.xml.

The class OKW_Ini is holding in store all configuration parameters and is providing this properties.

The properties are divided in two sections:

Name Description
OKW.OKW_Ini.OKW_Enviroment Environmental characteristics, such as paths.
Detailed description in the referenced class.
OKW.OKW_Ini.OKW_CustomSettings General settings such as time-outs
Detailed description in the referenced class.

The class is created as singleton.
The use of this class is not done with the constructor, but exclusively with the property OKW.OKW_Ini.Instance.

Usage of the class OKW.OKW_Ini

Integration of package

The package OKW contains the class OKW_Ini. The class can be affected with

1 use OKW;

Getting the instance of the singleton

An instance of the class is taken as follows:

1 OKW_Ini myOKW_Ini = OKW_Ini.Instance;

### Referencing the value of a property ###

1 string MeinWert myOKW_Ini.CustomSettings.TimeOutExists;

Hint for OKW Developers

Extension of Properties

The following should be shown by way of example, as a new property NewProperty of OKW_Ini can be added.

The new property NewProperty is initialized with _"Default Value"_ . For NewProperty will be defined as follows:

1 private string __NewProperty = "Default Value";
2 
3 [XmlElement("NewProperty")]
4 public string NewProperty {
5  get{ return __NewProperty; }
6  set{ __NewProperty = value; }
7 }

Note: The private variable __NewProperty is necessary, because the property NewProperty is initialized first with a Default-Value. Since OKW_Ini will automatically create a complete OKW_Ini.xml file, it is not possible to set the property via attribute definition to a default value, since System.Xml.Serialization, only properties serializing, which differ from the default value.

Automatical Serializing

The new property NewProperty inserted this wax is automatically serialized/ deserialized with the other properties in the OKW_Ini.xml .

Author
Zoltán Hrabovszki
Date
2014-10-25/jn

Constructor & Destructor Documentation

OKW.OKW_Ini.OKW_Ini ( )

This class is a Singelton.

As typical for a Singelton-Pattern an instance is not created with the constructor, but called with the property OKW_Ini.Instance.

Important: Do not use this constructor to create an instance of the class.

Note: The constructor should be 'private' with a singleton. This constructor must be 'public' because of the serializing!

Note
Further Information to the topic Singeleton at http://csharpindepth.com/Articles/General/Singleton.aspx
Author
Zoltán Hrabovszki
Date
2014-10-25/jnic
291  {
292  }

Here is the caller graph for this function:

Member Function Documentation

void OKW.OKW_Ini.Init ( )

Initializes the class OKW.OKW_Ini.

The initialization of the class OKW.OKW_Ini is scheduled as follows:

OKW_Ini_en.png
  • clear all class variables of OKW_Ini.
  • read environment variable OKW_Xml
    • if the environment variable is existing...
      • and file exists, then read the file.
      • and with this values create a file at the given place.
    • if the environment variable is missing or not set,
      • then all properties are set on "Default-Value".
      • No file will be written, because the target file is missing!
      • Warning is given that the environment variable is missing.
Exceptions
OKWEnviromentVarNotSetExceptionIf the environment variable OKW_Xml is not set.
OKWFileDoesNotExistsExceptionis triggered, if the file, given as OKW_Ini.Xml_Ini_xml, is not existing. Before a template file was created.
Author
Zoltán Hrabovszki
Date
2014-10-25/jnic
452  {
453  this.Log.LogFunctionStart(this.GetType().FullName + ".Init");
454 
455  // Klassen Variablen erst löschen...
456  this.Xml_Ini_xml = string.Empty;
457 
458  // ... und dann alles Initialisieren!
459  try
460  {
461  // 1. Lese OKWINI-Ümgebungsvariable
462  this.Xml_Ini_xml = Environment.GetEnvironmentVariable("OKW_Xml");
463 
464  this.Log.LogPrint("OKW_Xml=" + this.Xml_Ini_xml);
465 
466  if (string.IsNullOrEmpty(this.Xml_Ini_xml))
467  {
468  // OKW_Xml ist nicht gesetzt -> Ausnahme auslösen
469  throw new OKWEnviromentVarNotSetException("Enviroment variable 'OKW_Xml' not set!");
470  }
471  else
472  {
473  this.Log.LogPrint("Enviroment Var: OKW_Xml = >>" + this.Xml_Ini_xml + "<<");
474  }
475 
476  // Existiert die Datei?
477  bool bXML_Ini_xml_Exists = System.IO.File.Exists(this.Xml_Ini_xml);
478 
479  if (bXML_Ini_xml_Exists)
480  {
481  // Datei Existiert -> Lesen der Daten
482  this.Read();
483  }
484  else
485  {
486  // Datei Fehlt: Default Werte schreiben.
487  this.Save();
488  this.Log.LogWarning("File: >>" + this.Xml_Ini_xml + "<< does not exists!.");
489  this.Log.LogPrint("OKW now creates a template XML_Ini.xml for you! See: "+ this.Xml_Ini_xml);
490 
491  throw new OKWFileDoesNotExistsException("File does not exists: >>" + this.Xml_Ini_xml + "<<");
492  }
493  }
494  finally
495  {
496  this.Log.LogFunctionEnd();
497  }
498 
499  return;
500  }
string Xml_Ini_xml
Variable has in store the path- and filename of OKW_Ini.xml.
Definition: OKW_Ini.cs:233
void OKW.OKW_Ini.Read ( )

Reads the properties of the class OKW_Ini from a file, given in OKW.OKW_Ini.Xml_Ini_xml. An XML file is written. For this purpose the class OKW_Ini is serialized with System.Xml.XmlSerializer.

Author
Zoltán Hrabovszki
Date
2014-10-25/jnic
518  {
519  this.Log.LogFunctionStartDebug(this.GetType().FullName + "Read()");
520 
521  try
522  {
523  XmlSerializer serializer = new XmlSerializer(typeof(OKW_Ini));
524  StreamReader fs = new StreamReader(this.Xml_Ini_xml);
525  _Instance = (OKW_Ini)serializer.Deserialize(fs);
526  fs.Close();
527  }
528  finally
529  {
530  this.Log.LogFunctionEndDebug();
531  }
532 
533  return;
534  }
OKW_Ini()
This class is a Singelton.
Definition: OKW_Ini.cs:290
string Xml_Ini_xml
Variable has in store the path- and filename of OKW_Ini.xml.
Definition: OKW_Ini.cs:233
static OKW_Ini _Instance
Singelton-Pattern: Field contains the only valid instance of this class.
Definition: OKW_Ini.cs:247

Here is the call graph for this function:

static void OKW.OKW_Ini.Reset ( )
static

Deleting and resetting of the class.

Is needed primarily for the unittests.

Author
Zoltan Hrabovszki
Date
2014-10-25/jnic
356  {
357  _Instance = null;
358  }
static OKW_Ini _Instance
Singelton-Pattern: Field contains the only valid instance of this class.
Definition: OKW_Ini.cs:247
void OKW.OKW_Ini.Save ( )

Writes the property of the class OKW_Ini in a file, given in OKW.OKW_Ini.Xml_Ini_xml. An XML file is written. For this purpose the class OKW_Ini with the class System.Xml.XmlSerializer is serialized.

Author
Zoltán Hrabovszki
Date
2014-10-25/jnic
552  {
553  this.Log.LogFunctionStartDebug(this.GetType().FullName + "Save()");
554 
555  try
556  {
557  XmlSerializer serializer = new XmlSerializer(typeof(OKW_Ini));
558  StreamWriter fs = new StreamWriter(this.Xml_Ini_xml, false);
559  serializer.Serialize(fs, _Instance);
560  fs.Close();
561  }
562  finally
563  {
564  this.Log.LogFunctionEndDebug();
565  }
566 
567  return;
568  }
OKW_Ini()
This class is a Singelton.
Definition: OKW_Ini.cs:290
string Xml_Ini_xml
Variable has in store the path- and filename of OKW_Ini.xml.
Definition: OKW_Ini.cs:233
static OKW_Ini _Instance
Singelton-Pattern: Field contains the only valid instance of this class.
Definition: OKW_Ini.cs:247

Member Data Documentation

OKW_Ini OKW.OKW_Ini._Instance
staticprivate

Singelton-Pattern: Field contains the only valid instance of this class.

///

Author
Zoltán Hrabovszki
Date
2014-10-25/jnic
OKW_CustomSettings OKW.OKW_Ini.OKW_CustomSettings = new OKW_CustomSettings()

This field has in store the section OKW_CustomSettings of OKW_Ini.xml.

///

Author
Zoltán Hrabovszki
Date
2014-10-25/jn
OKW_Enviroment OKW.OKW_Ini.OKW_Enviroment = new OKW_Enviroment()

This field has in store the section OKW_Enviroment of OKW_Ini.xml.

///

Author
Zoltán Hrabovszki
Date
2014-10-25/jnic
string OKW.OKW_Ini.Xml_Ini_xml = string.Empty

Variable has in store the path- and filename of OKW_Ini.xml.

///

Author
Zoltán Hrabovszki
Date
2014_10_25/jnic

Property Documentation

OKW_Ini OKW.OKW_Ini.Instance
staticget

Singelton-Pattern: instance returns the actual valid and only instance of the class.

At the first use of this class an instance of this class is automatically created.

Important: To receive an instance of OKW.OKW_Ini use exclusively this property only!

Author
Zoltán Hrabovszki
Date
2014-10-25/jnic

The documentation for this class was generated from the following file: