Difference between revisions of "Csharp utils dll"
From OpenKM Documentation
(→ConfigXML) |
|||
(11 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
OKMUtils DLL library has general purpose classes to help work with OpenKM. | OKMUtils DLL library has general purpose classes to help work with OpenKM. | ||
+ | |||
+ | * Download [[File:OKMUtils_2.0.zip]] | ||
+ | * [http://doxygen.openkm.com/OKMUtils Doxygen OKMUtils] ( Packages & classes & files documentation ) | ||
== Understanding the basics == | == Understanding the basics == | ||
Line 8: | Line 11: | ||
* DictionaryHelper ( load .properties resource project file into dictionary ) | * DictionaryHelper ( load .properties resource project file into dictionary ) | ||
* Logger ( manage log file into MyDocuments/OpenKM ); | * Logger ( manage log file into MyDocuments/OpenKM ); | ||
+ | * FileUtil ( file utilies ) | ||
== ConfigXML == | == ConfigXML == | ||
ConfigXML helps on manage openkm.xml file stored at MyDocuments/OpenKM to keep application configuration parameters. First time is called ConfigXML if MyDocuments/OpenKM/openkm.xml configuration file not exists create one with default values. | ConfigXML helps on manage openkm.xml file stored at MyDocuments/OpenKM to keep application configuration parameters. First time is called ConfigXML if MyDocuments/OpenKM/openkm.xml configuration file not exists create one with default values. | ||
+ | |||
+ | {{Note|We suggest to '''store language''' follow the '''format enGB''' (english, Great Britain), '''esES''' (spanish, Spain), etc... }} | ||
'''Example openkm.xml file:''' | '''Example openkm.xml file:''' | ||
Line 24: | Line 30: | ||
</source> | </source> | ||
− | '''Example | + | '''Example:''' |
<source lang="csharp"> | <source lang="csharp"> | ||
// Read actual configuration | // Read actual configuration | ||
Line 46: | Line 52: | ||
configXML.CreateConfigurationFile(); | configXML.CreateConfigurationFile(); | ||
Program.configXML.ReadConfig(); // After created configuration file is good practice read again | Program.configXML.ReadConfig(); // After created configuration file is good practice read again | ||
+ | </source> | ||
+ | |||
+ | == DictionaryHelper == | ||
+ | DictionaryHelper load source properties files into Dictionary. That is used to set translations to OKMForms objects. | ||
+ | |||
+ | {{Note|Character '''#''' indicates is a '''comment line''' and the line will be skipped.}} | ||
+ | |||
+ | '''File resource/translation-enGB.properties:''' | ||
+ | <source lang="text"> | ||
+ | # Form configuration | ||
+ | form.configuration.name=Configuration | ||
+ | form.configuration.language=Language | ||
+ | form.configuration.version=OpenKM Version | ||
+ | form.configuration.userName=User | ||
+ | form.configuration.password=Password | ||
+ | form.configuration.host=Host | ||
+ | form.configuration.error.msg=Field {0} can not be empty | ||
+ | </source> | ||
+ | |||
+ | '''Example:''' | ||
+ | <source lang="csharp"> | ||
+ | // We've assumed the namespace of the project is OKMExample | ||
+ | // and file transations-enGB.properties is stored under folder resources | ||
+ | // then the resource should be called OKMExample.resources.translations-enGB.properties | ||
+ | DictionaryHelper dictionary = new DictionaryHelper(); | ||
+ | String resource = "OKMExample.resources.translations-enGB.properties"; | ||
+ | Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource); | ||
+ | dictionary.loadDictionary(stream); | ||
+ | String nameLabel = dictionary.getTranslation(form.configuration.name); | ||
+ | </source> | ||
+ | |||
+ | == Logger == | ||
+ | Logger helps on manage log file into MyDocuments/OpenKM | ||
+ | |||
+ | '''Example:''' | ||
+ | <source lang="csharp"> | ||
+ | // Initial declaration | ||
+ | // Will be created a file called DigitalSignature.log into MyDocuments/OpenKM folder | ||
+ | Logger.Instance.changeLogName("DigitalSignature"); | ||
+ | Logger.Instance.changeLogLevel(Logger.DEBUG); | ||
+ | Logger.Instance.enableMessageBox(true); | ||
+ | // Application start | ||
+ | Logger.Instance.info("Application started"); | ||
+ | // Error will display error MessageBox | ||
+ | // enableMessageBox should only be enabled in Forms projects | ||
+ | Logger.Instance.error("Some error"); | ||
</source> | </source> | ||
[[Category: Extension Guide]] | [[Category: Extension Guide]] |
Latest revision as of 16:49, 9 May 2014
DLL have been compiled for net 2.0 that should ensure go with any upper .net version |
OKMUtils DLL library has general purpose classes to help work with OpenKM.
- Download File:OKMUtils 2.0.zip
- Doxygen OKMUtils ( Packages & classes & files documentation )
Understanding the basics
- ConfigXML ( manage openkm.xml at MyDocuments/OpenKM user folder to store configuration )
- DictionaryHelper ( load .properties resource project file into dictionary )
- Logger ( manage log file into MyDocuments/OpenKM );
- FileUtil ( file utilies )
ConfigXML
ConfigXML helps on manage openkm.xml file stored at MyDocuments/OpenKM to keep application configuration parameters. First time is called ConfigXML if MyDocuments/OpenKM/openkm.xml configuration file not exists create one with default values.
We suggest to store language follow the format enGB (english, Great Britain), esES (spanish, Spain), etc... |
Example openkm.xml file:
<?xml version="1.0"?>
<openkm>
<host>http://192.168.1.34:8180/OpenKM/</host>
<user>okmAdmin</user>
<password>1HpkvlY72ks=</password>
<version>2</version>
<idioma>enGB</idioma>
</openkm>
Example:
// Read actual configuration
ConfigXML configXML = new ConfigXML();
// Read webservice based on OpenKM version
OKMWebservice webservice = null;
if (configXML.getVersion().Equals("") || int.Parse(configXML.getVersion())== OKMWebServiceFactory.PROFESSIONAL_6_4)
{
webservice = OKMWebServiceFactory.getInstance(configXML.getHost(), configXML.getUser(), configXML.getPassword(), OKMWebServiceFactory.PROFESSIONAL_6_4);
}
else
{
webservice = OKMWebServiceFactory.getInstance(configXML.getHost(), configXML.getUser(), configXML.getPassword(), OKMWebServiceFactory.PROFESSIONAL_6_2);
}
// Here for example store new configuration
configXML.setHost("http://localhost:8080/OpenKM");
configXML.setUser("okmADmin");
configXML.setPassword("admin");
configXML.setVersion(OKMWebServiceFactory.PROFESSIONAL_6_4.toString());
configXML.setLanguage("esES");
configXML.CreateConfigurationFile();
Program.configXML.ReadConfig(); // After created configuration file is good practice read again
DictionaryHelper
DictionaryHelper load source properties files into Dictionary. That is used to set translations to OKMForms objects.
Character # indicates is a comment line and the line will be skipped. |
File resource/translation-enGB.properties:
# Form configuration
form.configuration.name=Configuration
form.configuration.language=Language
form.configuration.version=OpenKM Version
form.configuration.userName=User
form.configuration.password=Password
form.configuration.host=Host
form.configuration.error.msg=Field {0} can not be empty
Example:
// We've assumed the namespace of the project is OKMExample
// and file transations-enGB.properties is stored under folder resources
// then the resource should be called OKMExample.resources.translations-enGB.properties
DictionaryHelper dictionary = new DictionaryHelper();
String resource = "OKMExample.resources.translations-enGB.properties";
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
dictionary.loadDictionary(stream);
String nameLabel = dictionary.getTranslation(form.configuration.name);
Logger
Logger helps on manage log file into MyDocuments/OpenKM
Example:
// Initial declaration
// Will be created a file called DigitalSignature.log into MyDocuments/OpenKM folder
Logger.Instance.changeLogName("DigitalSignature");
Logger.Instance.changeLogLevel(Logger.DEBUG);
Logger.Instance.enableMessageBox(true);
// Application start
Logger.Instance.info("Application started");
// Error will display error MessageBox
// enableMessageBox should only be enabled in Forms projects
Logger.Instance.error("Some error");