using System.IO; using System.Windows.Forms; using System.Xml; namespace SCMA { public class utils : MTC.baseUtils { /// /// folder archiviazione dati configurazione (DATA\CONF) /// public static string resxDir { get { return string.Format(@"{0}\{1}", Application.StartupPath, CRS("resxPath")); } } /// /// folder archiviazione dati configurazione (DATA\CONF) /// public static string confDir { get { return string.Format(@"{0}\{1}", Application.StartupPath, CRS("dataConfPath")); } } /// /// folder archiviazione dati storici giornalieri (DATA\DAT) /// public static string dataDatDir { get { return string.Format(@"{0}\{1}", Application.StartupPath, CRS("dataDatPath")); } } /// /// folder archiviazione dati (DATA) /// public static string dataDir { get { return string.Format(@"{0}\{1}", Application.StartupPath, CRS("dataPath")); } } /// /// File x regole di replacement USER DEFINED /// public static string nameRepRoleFile { get { return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("NameRepRolesList")); } } /// /// File x regole di replacement generato ad hoc x SOUR / OPC-UA /// public static string nameRepRoleFileSOUR { get { return nameRepRoleFile.Replace(".map", ".SOUR.map"); } } /// /// File StatusList /// public static string StatusListFile { get { return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("StatusListFilePath")); } } /// /// File StatusList generato ad hoc x SOUR / OPC-UA /// /// public static string StatusListFileSOUR { get { return StatusListFile.Replace(".map", ".SOUR.map"); } } /// /// File CounterList /// public static string CounterListFile { get { return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("CounterListFilePath")); } } /// /// File CounterList generato ad hoc x SOUR / OPC-UA /// /// public static string CounterListFileSOUR { get { return CounterListFile.Replace(".map", ".SOUR.map"); } } /// /// File AnalogList /// public static string AnalogListFile { get { return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("AnalogDataFilePath")); } } /// /// File AnalogList generato ad hoc x SOUR / OPC-UA /// /// public static string AnalogListFileSOUR { get { return AnalogListFile.Replace(".map", ".SOUR.map"); } } /// /// File AnalogList /// public static string StringListFile { get { return string.Format(@"{0}\{1}", utils.confDir, utils.CRS("StringDataFilePath")); } } /// /// File AnalogList generato ad hoc x SOUR / OPC-UA /// /// public static string StringListFileSOUR { get { return StringListFile.Replace(".map", ".SOUR.map"); } } /// /// Metodo di sanitizzazione XML /// - elimina commenti /// - formatta /// /// /// 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; } } }