internal static Settings GetInstance() { if (instance == null) { if (!File.Exists(SettingsXmlPath)) { (instance = new Settings()).setDefaultValues(); } else { using (TextReader textReader = new StreamReader(SettingsXmlPath)) { Settings s = null; try { XmlSerializer serializer = new XmlSerializer(typeof(Settings)); s = serializer.Deserialize(textReader) as Settings; } catch (Exception ex) { if (QueryOptimizer.GetLoger() != null) { QueryOptimizer.GetLoger().Log("QueryOptimizer", string.Format("Unable to read file with setting\n{0}", ex), MessageLevel.Error); } } textReader.Close(); instance = s ?? new Settings(); } } } return(instance); }
private void setDefaultValues() { this.maxTimeSearchingBestQueryPlan = 500000; if (QueryOptimizer.GetLoger() != null) { QueryOptimizer.GetLoger().Log("QueryOptimizer", "Assigned default values", MessageLevel.Info); } this.SettingsValueChanged(); }
private void SettingsValueChanged() { try { using (TextWriter textWriter = new StreamWriter(SettingsXmlPath)) { XmlSerializer serializer = new XmlSerializer(typeof(Settings)); serializer.Serialize(textWriter, instance); textWriter.Close(); } } catch (Exception ex) { if (QueryOptimizer.GetLoger() != null) { QueryOptimizer.GetLoger().Log("QueryOptimizer", string.Format("Unable to save file with setting\n{0}", ex), MessageLevel.Error); } } }