191 lines
5.5 KiB
C#
191 lines
5.5 KiB
C#
using System.IO;
|
|
using System.Windows.Forms;
|
|
using System.Xml;
|
|
|
|
namespace SCMA
|
|
{
|
|
public class utils : MTC.baseUtils
|
|
{
|
|
/// <summary>
|
|
/// folder archiviazione dati configurazione (DATA\CONF)
|
|
/// </summary>
|
|
public static string resxDir
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", Application.StartupPath, CRS("resxPath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// folder archiviazione dati configurazione (DATA\CONF)
|
|
/// </summary>
|
|
public static string confDir
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", Application.StartupPath, CRS("dataConfPath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// folder archiviazione dati storici giornalieri (DATA\DAT)
|
|
/// </summary>
|
|
public static string dataDatDir
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", Application.StartupPath, CRS("dataDatPath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// folder archiviazione dati (DATA)
|
|
/// </summary>
|
|
public static string dataDir
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", Application.StartupPath, CRS("dataPath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File x regole di replacement USER DEFINED
|
|
/// </summary>
|
|
public static string nameRepRoleFile
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("NameRepRolesList"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File x regole di replacement generato ad hoc x SOUR / OPC-UA
|
|
/// </summary>
|
|
public static string nameRepRoleFileSOUR
|
|
{
|
|
get
|
|
{
|
|
return nameRepRoleFile.Replace(".map", ".SOUR.map");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File StatusList
|
|
/// </summary>
|
|
public static string StatusListFile
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("StatusListFilePath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File StatusList generato ad hoc x SOUR / OPC-UA
|
|
///
|
|
/// </summary>
|
|
public static string StatusListFileSOUR
|
|
{
|
|
get
|
|
{
|
|
return StatusListFile.Replace(".map", ".SOUR.map");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File CounterList
|
|
/// </summary>
|
|
public static string CounterListFile
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("CounterListFilePath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File CounterList generato ad hoc x SOUR / OPC-UA
|
|
///
|
|
/// </summary>
|
|
public static string CounterListFileSOUR
|
|
{
|
|
get
|
|
{
|
|
return CounterListFile.Replace(".map", ".SOUR.map");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File AnalogList
|
|
/// </summary>
|
|
public static string AnalogListFile
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("AnalogDataFilePath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File AnalogList generato ad hoc x SOUR / OPC-UA
|
|
///
|
|
/// </summary>
|
|
public static string AnalogListFileSOUR
|
|
{
|
|
get
|
|
{
|
|
return AnalogListFile.Replace(".map", ".SOUR.map");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// File AnalogList
|
|
/// </summary>
|
|
public static string StringListFile
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("StringDataFilePath"));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// File AnalogList generato ad hoc x SOUR / OPC-UA
|
|
///
|
|
/// </summary>
|
|
public static string StringListFileSOUR
|
|
{
|
|
get
|
|
{
|
|
return StringListFile.Replace(".map", ".SOUR.map");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Metodo di sanitizzazione XML
|
|
/// - elimina commenti
|
|
/// - formatta
|
|
/// </summary>
|
|
/// <param name="xmlOrig"></param>
|
|
/// <returns></returns>
|
|
public static string xmlSanitize(string xmlOrig)
|
|
{
|
|
string sXml = xmlOrig;
|
|
bool xmlSanitize = utils.CRB("xmlSanitize");
|
|
// se richeisto faccio sanitize xml (pulizia commenti...)
|
|
if (xmlSanitize)
|
|
{
|
|
// primo step: converto stringa in dox XML
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
xmlDoc.PreserveWhitespace = false;
|
|
xmlDoc.LoadXml(sXml);
|
|
// ora lo parso come lista eliminando i commenti
|
|
XmlNodeList list = xmlDoc.SelectNodes("//comment()");
|
|
foreach (XmlNode node in list)
|
|
{
|
|
node.ParentNode.RemoveChild(node);
|
|
}
|
|
// fix formattazione "riscrivendo" indentazione...
|
|
StringWriter string_writer = new StringWriter();
|
|
XmlTextWriter xml_text_writer = new XmlTextWriter(string_writer);
|
|
xml_text_writer.Formatting = Formatting.Indented;
|
|
xmlDoc.WriteTo(xml_text_writer);
|
|
sXml = string_writer.ToString();
|
|
}
|
|
// restituisco
|
|
return sXml;
|
|
}
|
|
}
|
|
}
|