示例#1
0
        public List <Measurements> readFromTXT(SettingsFromXML settingsFromXML, MqttCfgSettingsOrganiser mqttCfgSettings)
        {
            // Retrieve the info from the config.xml
            string[] rows;

            if (settingsFromXML.inputFormat == "singleLine")
            {
                string content = File.ReadAllText(mqttCfgSettings.InputPathDirectory + "\\" + mqttCfgSettings.InputFile);
                rows = content.Split(settingsFromXML.splitVariables);
            }
            else // separatedRows
            {
                rows = File.ReadAllLines(mqttCfgSettings.InputPathDirectory + "\\" + mqttCfgSettings.InputFile);
            }
            foreach (var row in rows)
            {
                string[] tokens = row.Split(settingsFromXML.splitKeyValue);
                if (tokens[0].ToUpper() == settingsFromXML.firstValue)
                {
                    measurements = new Measurements();
                }

                Measurements.StoreMeasurements(tokens[0], tokens[1], measurements);

                if (tokens[0].ToUpper() == settingsFromXML.lastValue)
                {
                    measurementsList.Add(measurements);
                }
            }
            return(measurementsList);
        }
示例#2
0
        // USING FILE AND PATH FETCHED FROM CONFIG.XML
        public List <Measurements> readFromXML(SettingsFromXML settingsFromXML, MqttCfgSettingsOrganiser mqttCfgSettings)
        {
            string key_dict = "";

            XmlTextReader reader = new XmlTextReader(mqttCfgSettings.InputPathDirectory + "\\" + mqttCfgSettings.InputFile);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:             // The node is an element.
                    key_dict = reader.Name;
                    break;

                case XmlNodeType.Text:                //Display the text in each element.
                {
                    if (key_dict.ToUpper() == settingsFromXML.firstValue)
                    {
                        measurements = new Measurements();
                    }

                    Measurements.StoreMeasurements(key_dict, reader.Value, measurements);

                    if (key_dict.ToUpper() == settingsFromXML.lastValue)
                    {
                        measurementsList.Add(measurements);
                    }
                    break;
                }

                case XmlNodeType.EndElement:          //Display the end of the element.
                    break;
                }
            }
            return(measurementsList);
        }