using global::System.IO; using global::Newtonsoft.Json; using global::Pilz.GeneralEventArgs; namespace Pilz.Configuration { public class SimpleConfiguration { [JsonIgnore] public readonly ConfigurationManagerList Managers = new ConfigurationManagerList(); public SimpleConfiguration() { Managers.GettingParentManager += Managers_GettingParentManager; } private void Managers_GettingParentManager(object sender, GetValueEventArgs e) { if (ReferenceEquals(sender, Managers)) { e.Value = this; } } /// /// Writes this instance to a string and return it. /// /// The content of the configuration instance as string. public string WriteToString() { return ConfigurationSerializer.WriteToString(this); } /// /// Write this instance to a given stream. /// /// The stream where the content should be written to. public void WriteToStream(Stream stream) { ConfigurationSerializer.WriteToStream(this, stream); } /// /// Writes this instance to the given filePath as text file. /// /// The file path where the content should be written to. The file will be created or overwritten. public void WriteToFile(string filePath) { ConfigurationSerializer.WriteToFile(this, filePath); } /// /// Reads a configuratin from the given string and returns an instance of it. /// /// The type of the configuration class to instance. /// The content of the configuration as string. /// public static T ReadFromString(string content) where T : SimpleConfiguration { return ConfigurationSerializer.ReadFromString(content); } /// /// Read a configuration from the given string and put them to this instance. /// /// The content of the configuration as string. public void ReadFromString(string content) { ConfigurationSerializer.ReadFromString(this, content); } /// /// Reads a configuratin from the given string and returns an instance of it. /// /// The type of the configuration class to instance. /// The stream with the content of the configuration. /// public static T ReadFromStream(Stream stream) where T : SimpleConfiguration { return ConfigurationSerializer.ReadFromStream(stream); } /// /// Read a configuration from the given string and put them to this instance. /// /// The stream with the content of the configuration. public void ReadFromStream(Stream stream) { ConfigurationSerializer.ReadFromStream(this, stream); } /// /// Reads a configuratin from the given string and returns an instance of it. /// /// The type of the configuration class to instance. /// The path to the file with the content of the configuration. /// public static T ReadFromFile(string filePath) where T : SimpleConfiguration { return ConfigurationSerializer.ReadFromFile(filePath); } /// /// Read a configuration from the given string and put them to this instance. /// /// The path to the file with the content of the configuration. public void ReadFromFile(string filePath) { ConfigurationSerializer.ReadFromFile(this, filePath); } } }