OpenKeyWord  Version: 426, Datum:
OKW_Const.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.Collections.Generic;
46  using System.IO;
47  using System.Xml.XPath;
48 
49  using OKW.Log;
50 
128  public class OKW_Const
129  {
130  #region Fields
131 
132  private static readonly OKW_Const instance = new OKW_Const();
133 
148 
162 
163  private XPathDocument MyXPathDocument;
164  private XPathNavigator MyXPathNavigator;
165 
180  string OKW_Const_xml = string.Empty;
181 
182  #endregion Fields
183 
184  #region Constructors
185 
265  private OKW_Const()
266  {
267 
269  this.OKW_Const_xml = System.IO.Path.Combine(OKW_Ini.Instance.OKW_Enviroment.Folder_XML, @"OKW_Const.xml");
270  System.Console.WriteLine( "OKW_Const.xml: >>" + this.OKW_Const_xml + "<<");
271 
272  this.LM_OKW_Const_xml = new LogMessenger(this.GetType().Name);
273 
274  if (!System.IO.File.Exists(this.OKW_Const_xml))
275  {
276  string lvsMessage = this.LM_OKW_Const_xml.GetMessage("OKW_Const", "FileNotFoundException", this.OKW_Const_xml);
277  throw new FileNotFoundException(lvsMessage);
278  }
279  else
280  {
281  MyXPathDocument = new XPathDocument(this.OKW_Const_xml);
282  MyXPathNavigator = this.MyXPathDocument.CreateNavigator();
283  }
284  }
285 
286  #endregion Constructors
287 
288  #region Properties
289 
308  public static OKW_Const Instance
309  {
310  get
311  {
312  return instance;
313  }
314  }
315 
316  #endregion Properties
317 
318  #region Methods
319 
336  public string Boolean2YesNo(bool fpbTrueOrFalse)
337  {
338  string lvs_Return = string.Empty;
339  string lvsInternalname = string.Empty;
340 
341  try
342  {
343  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".Boolean2YesNo", "fpbTrueOrFalse", fpbTrueOrFalse.ToString());
344 
345  if (fpbTrueOrFalse)
346  {
347  // If TRUE -> YES
348  lvs_Return = this.GetConst4Internalname("YES");
349  }
350  else
351  {
352  // Else FALSE -> NO
353  lvs_Return = this.GetConst4Internalname("NO");
354  }
355  }
356  finally
357  {
358  Logger.Instance.LogFunctionEndDebug(lvs_Return);
359  }
360 
361  return lvs_Return;
362  }
363 
394  public string ConcatHSEP(List<string> fpLs_ListString2Concat)
395  {
396  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".ConcatHSEP", "fpLs_ListString2Concat", fpLs_ListString2Concat.ToString());
397 
398  string lvs_Return = string.Empty;
399 
400  try
401  {
402  lvs_Return = OKW_Helper.ListStringConcat(fpLs_ListString2Concat, this.GetOKWConst4Internalname("HSEP"));
403  }
404  finally
405  {
406  Logger.Instance.LogFunctionEndDebug(lvs_Return);
407  }
408 
409  return lvs_Return;
410  }
411 
440  public string ConcatSEP(List<string> fpLs_ListString2Concat)
441  {
442  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".ConcatSEP", "fpLs_ListString2Concat", fpLs_ListString2Concat.ToString());
443 
444  string lvs_Return = string.Empty;
445 
446  try
447  {
448  lvs_Return = OKW_Helper.ListStringConcat(fpLs_ListString2Concat, this.GetOKWConst4Internalname("SEP"));
449  }
450  finally
451  {
452  Logger.Instance.LogFunctionEndDebug(lvs_Return);
453  }
454 
455  return lvs_Return;
456  }
457 
486  public string ConcatVSEP(List<string> fpLs_ListString2Concat)
487  {
488  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".ConcatVSEP", "fpLs_ListString2Concat", fpLs_ListString2Concat.ToString());
489 
490  string lvs_Return = string.Empty;
491 
492  try
493  {
494  lvs_Return = OKW_Helper.ListStringConcat(fpLs_ListString2Concat, this.GetOKWConst4Internalname("VSEP"));
495  }
496  finally
497  {
498  Logger.Instance.LogFunctionEndDebug(lvs_Return);
499  }
500 
501  return lvs_Return;
502  }
503 
551  public string GetConst4Internalname(string fpsInternalname)
552  {
553  Log.Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".ReadConst", "fpsInternalname", fpsInternalname);
554 
555  string lvs_temp = string.Empty;
556 
557  string myXPath = "//okwconst[@internalname='" + fpsInternalname + "']/name/" + CL.Language;
558 
559  Log.Logger.Instance.LogPrintDebug("myXPath: " + myXPath);
560 
561  try
562  {
563  XPathNodeIterator iter = this.MyXPathNavigator.Select(myXPath);
564 
565  if (iter.Count > 0)
566  {
567  while (iter.MoveNext())
568  {
569  lvs_temp = iter.Current.Value;
570  }
571  }
572  else
573  {
574  string lvsMessage = this.LM_OKW_Const_xml.GetMessage("GetConst4Internalname",
575  "ExceptionConst4Internalname",
576  fpsInternalname,
577  CL.Language,
578  this.LM_OKW_Const_xml.XMLFile);
579  throw new OKWConst4InternalnameNotFoundException(lvsMessage);
580  }
581  }
582  finally
583  {
584  if (lvs_temp == string.Empty)
585  {
586  Log.Logger.Instance.LogFunctionEndDebug();
587  }
588  else
589  {
590  Log.Logger.Instance.LogFunctionEndDebug(lvs_temp);
591  }
592  }
593 
594  return lvs_temp;
595  }
596 
597 
654  public string GetOKWConst4Internalname(string fpsInternalname)
655  {
656  string lvsReturn = string.Empty;
657 
658  Logger.Instance.LogFunctionStartDebug( this.GetType().FullName + ".GetOKWConst4Internalname", "fpsInternalname", fpsInternalname);
659 
660  try
661  {
662  lvsReturn =
663  this.GetConst4Internalname("LEFTBRACE") +
664  this.GetConst4Internalname(fpsInternalname) +
665  this.GetConst4Internalname("RIGHTBRACE");
666  }
667  finally
668  {
669  Logger.Instance.LogFunctionEndDebug(lvsReturn);
670  }
671 
672  return lvsReturn;
673  }
674 
675 
722  public List<string> SplitHSEP(string fpsString2Split)
723  {
724  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".SplitHSEP", "fpsString2Split", fpsString2Split);
725  List<string> lvls_2Plit = new List<string>();
726 
727  try
728  {
729  lvls_2Plit = OKW_Helper.StrSplit(fpsString2Split, this.GetOKWConst4Internalname("HSEP"));
730  }
731  finally
732  {
733  Logger.Instance.LogFunctionEndDebug(lvls_2Plit.ToString());
734  }
735 
736  return lvls_2Plit;
737  }
738 
739 
786  public List<string> SplitSEP(string fpsString2Split)
787  {
788  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".SplitSEP", "fpsString2Split", fpsString2Split);
789 
790  List<string> lvls_2Plit = null;
791 
792  try
793  {
794  lvls_2Plit = OKW_Helper.StrSplit(fpsString2Split, this.GetOKWConst4Internalname("SEP"));
795  }
796  finally
797  {
798  Logger.Instance.LogFunctionEndDebug(lvls_2Plit.ToString());
799  }
800 
801  return lvls_2Plit;
802  }
803 
850  public List<string> SplitVSEP(string fps_String2Split)
851  {
852  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".SplitHSEP", "fps_String2Split", fps_String2Split);
853  List<string> lvls_2Plit = new List<string>();
854 
855  try
856  {
857  lvls_2Plit = OKW_Helper.StrSplit(fps_String2Split, this.GetOKWConst4Internalname("VSEP"));
858  }
859  finally
860  {
861  Logger.Instance.LogFunctionEndDebug(lvls_2Plit.ToString());
862  }
863 
864  return lvls_2Plit;
865  }
866 
867 
900  public bool YesNo2Boolean(string fpsYesOrNo)
901  {
902  Logger.Instance.LogFunctionStartDebug(this.GetType().FullName + ".YesNo2Boolean", "fpsYesOrNo", fpsYesOrNo);
903  bool lvb_Return = false;
904 
905  string lvs_Yes = string.Empty;
906  string lvs_No = string.Empty;
907 
908  try
909  {
910  lvs_Yes = this.GetConst4Internalname("YES");
911  lvs_No = this.GetConst4Internalname("NO");
912 
913  if (lvs_Yes.ToUpper() == fpsYesOrNo.ToUpper())
914  {
915  lvb_Return = true;
916  }
917  else if (lvs_No.ToUpper() == fpsYesOrNo.ToUpper())
918  {
919  lvb_Return = false;
920  }
921  else
922  {
923  Logger.Instance.LogFunctionEndDebug();
924 
925  string lvsMessage = this.LM_OKW_Const_xml.GetMessage("YesNo2Boolean", "ValueNotAllowed", fpsYesOrNo, lvs_Yes + "'/'" + lvs_No);
926  throw new OKWNotAllowedValueException(lvsMessage);
927  }
928  }
929  finally
930  {
931  Logger.Instance.LogFunctionEndDebug(lvb_Return);
932  }
933 
934  return lvb_Return;
935  }
936 
937  #endregion Methods
938  }
939 }
string GetMessage(string MethodName, string TextKey)
Holt die Log-Meldung für MethodeNmae/Textkey ohne weitere Parameter.
Klasse enthält OKW-Hilfsfunktionen.
Definition: OKW_Helper.cs:63
OKW.OKWConst4InternalnameNotFoundException wird ausgelöst, wenn zu einer Konstanten, gegeben mit dem internen Namen, keine Übersetzung gefunden wird.
List< string > SplitHSEP(string fpsString2Split)
Methode trennt einen String und wandelt diesen in eine Liststring um. Der Schnitt wird an der Konstan...
Definition: OKW_Const.cs:722
static OKW_Ini Instance
Singelton-Pattern: Instanz gibt die aktuelle, gültige und einzige Innstanz der Klasse zurück...
Definition: OKW_Ini.cs:306
List< string > SplitVSEP(string fps_String2Split)
Methode trennt einen String und wandelt diesen in einen Liststring um. Der Schnitt wird an der Konsta...
Definition: OKW_Const.cs:850
http://de.wikipedia.org/wiki/ISO-3166-1-Kodierliste
Definition: OKWLanguage.cs:50
string File_OKW_Const_xml
Property get/set von __File_OKW_Const_xml.
static T Instance
Holt die einzige Instanz dieser Klasse.
bool YesNo2Boolean(string fpsYesOrNo)
Konvertiert sprachabhängig Ja/Nein zu einem boolean Wert (Wahr/Falsch).
Definition: OKW_Const.cs:900
static OKW_Const Instance
Holt die einzige Instanz dieser Klasse. Die Instanz dieser Klasse.
Definition: OKW_Const.cs:309
OKW_Enviroment OKW_Enviroment
Dieses Feld hält den Abschnitt OKW_Enviroment der OKW_Ini.xml vor.
Definition: OKW_Ini.cs:219
string OKW_Const_xml
Enthält den vollständigen Pfad und den Dateinamen zu der Datei OKW_Const.xml.
Definition: OKW_Const.cs:180
string GetConst4Internalname(string fpsInternalname)
Methode ermittelt für Internalname und der aktuell eingestellten Sprache den Wert für Const...
Definition: OKW_Const.cs:551
string Boolean2YesNo(bool fpbTrueOrFalse)
Konvertiert WAHR/FALSCH (true/false) sprachabhängig nach "Ja"/"Nein" (Yes/No)
Definition: OKW_Const.cs:336
OKW_Const verwaltet die sprachabhängigen OKW-Konstanten.
Definition: OKW_Const.cs:128
string Folder_XML
Property get/set von __Folder_XML.
OKWLanguage CL
Aktuelle Spracheinstellung (Current Language) wird in der Klasse OKWLanguage verwaltet. http://de.wikipedia.org/wiki/ISO-3166-1-Kodierliste.
Definition: OKW_Const.cs:147
OKW_Const()
Privater Konstruktor ohne Parameter im Entwurfsmuster Singelton initialisiert die Klasse OKW_Const...
Definition: OKW_Const.cs:265
string GetOKWConst4Internalname(string fpsInternalname)
Methode ermittelt für Internalname und der aktuell eingestellten Sprache den Wert für OKWConst...
Definition: OKW_Const.cs:654
LogMessenger liest Log-Meldungen sprachspezifisch für die im Konstruktor gegeben Klasse aus der Zugeh...
Definition: LogMessenger.cs:90
LogMessenger LM_OKW_Const_xml
Referenz auf OKW.Log.LogMessenger.
Definition: OKW_Const.cs:161
OKW.OKW_Ini ist die Klasse zur Konfigurationsdatei OKW_Ini.xml.
Definition: OKW_Ini.cs:188
static List< string > ParseMe(List< string > fpLsString2Parse)
Parst einen _List< string>, ersetzt die Parser-Schlüsslewörter durch Werte.
Definition: Parser.cs:31
static string ListStringConcat(List< string > fps_ListString2Concat, string fps_Separator)
Wandelt List in einen string um und trennt die Werte durch das vorgegebene Trennzeichen vonei...
Definition: OKW_Helper.cs:449
string ConcatSEP(List< string > fpLs_ListString2Concat)
Methode verbindet die einzelne Strings eines.
Definition: OKW_Const.cs:440
string ConcatVSEP(List< string > fpLs_ListString2Concat)
Methode verbindet die einzelnen Strings eines.
Definition: OKW_Const.cs:486
string Language
Gets or sets a string property.
Definition: OKWLanguage.cs:77
static List< string > StrSplit(string fpsString2Split, string fpsSeparator)
Splittet einen string am angegebenen Separator auf. Der Separator kann aus mehr als einem Zeichen bes...
Definition: OKW_Helper.cs:737
string ConcatHSEP(List< string > fpLs_ListString2Concat)
Methode verbindet die einzelne Strings eines.
Definition: OKW_Const.cs:394
Definition: Core.cs:40
List< string > SplitSEP(string fpsString2Split)
Methode trennt einen String und wandelt diesen in einen Liststring um. Der Schnitt wird an der Konsta...
Definition: OKW_Const.cs:786