82 lines
2.0 KiB
C#
82 lines
2.0 KiB
C#
///
|
|
/// Copyright (c) 2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace ResultsBrowser
|
|
{
|
|
/// <summary>
|
|
/// Class to be serialized to an XML file...
|
|
/// Public members are filters / parts of a query.
|
|
/// </summary>
|
|
[XmlRootAttribute("Query")]
|
|
public class QueryFilters
|
|
{
|
|
public string[] FilterNames;
|
|
|
|
[XmlIgnore]
|
|
public int FilterNamesCount { get { return (FilterNames != null) ? FilterNames.Length : 0; } }
|
|
|
|
public string[] FilterSettings;
|
|
|
|
[XmlIgnore]
|
|
public int FilterSettingsCount { get { return (FilterSettings != null) ? FilterSettings.Length : 0; } }
|
|
|
|
|
|
public QueryFilters()
|
|
{
|
|
}
|
|
|
|
public QueryFilters(int count)
|
|
{
|
|
if (count > 0)
|
|
{
|
|
FilterNames = new string[count];
|
|
FilterSettings = new string[count];
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load public fields of this class from the XML file.
|
|
/// </summary>
|
|
public static QueryFilters Load(string fileName)
|
|
{
|
|
try
|
|
{
|
|
using (TextReader reader = new StreamReader(fileName))
|
|
{
|
|
QueryFilters ls = (new XmlSerializer(typeof(QueryFilters))).Deserialize(reader) as QueryFilters;
|
|
// Copy the settings just in case De-serialize() completes OK
|
|
return ls;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
string msg = e.Message;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save public fields of this class to the XML file.
|
|
/// </summary>
|
|
public void Save(string fileName)
|
|
{
|
|
try
|
|
{
|
|
using (TextWriter writer = new StreamWriter(fileName))
|
|
{
|
|
(new XmlSerializer(typeof(QueryFilters))).Serialize(writer, this);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
string msg = e.Message;
|
|
}
|
|
}
|
|
}
|
|
}
|