Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void setDefaultValues()
        {
            this.maxTimeSearchingBestQueryPlan = 500000;
            if (QueryOptimizer.GetLoger() != null)
            {
                QueryOptimizer.GetLoger().Log("QueryOptimizer", "Assigned default values", MessageLevel.Info);
            }

            this.SettingsValueChanged();
        }
Exemplo n.º 3
0
 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);
         }
     }
 }