Exemplo n.º 1
0
        private static void ClearConfiguration()
        {
            var oldConfig = _configuration;

            _configuration = new ChronicleConfiguration();
            ConfigurationChanged?.Invoke();
            oldConfig.Dispose();
        }
Exemplo n.º 2
0
        private static void ConfigureFrom(string path, bool reconfiguringFromWatch)
        {
            if (!File.Exists(path))
            {
                if (reconfiguringFromWatch)
                {
                    ClearConfiguration();
                    return;
                }
                throw new FileNotFoundException
                          ($"Could not load NChronicle Configuration from file {path}: the file could not be found.");
            }
            var xmlSerializer             = new XmlSerializer(typeof(ChronicleConfiguration));
            ChronicleConfiguration config = null;

            try {
#if NETFX
                using (var textReader = new XmlTextReader(path)) {
#else
                using (var fileStream = new FileStream(path, FileMode.Open))
                    using (var textReader = XmlReader.Create(fileStream)) {
#endif
                    config = xmlSerializer.Deserialize(textReader) as ChronicleConfiguration;
                }
            }
            catch (Exception e) {
                if (!reconfiguringFromWatch)
                {
                    throw new XmlException
                              ($"Could not serialize NChronicle Configuration from file {path}, check inner exception for more information.",
                              e);
                }
            }
            if (config == null)
            {
                throw new XmlException($"Could not serialize NChronicle Configuration from file {path}.");
            }
            _configuration.Dispose();
            _configuration = config;
            ConfigurationChanged?.Invoke();
        }
Exemplo n.º 3
0
 static NChronicle()
 {
     _configuration = new ChronicleConfiguration();
 }