Esempio 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 (ServerSchemaStats.GetLoger() != null)
                            {
                                ServerSchemaStats.GetLoger().Log("ServerStats", string.Format("Unable to read file with setting\n{0}", ex), MessageLevel.Error);
                            }
                        }

                        textReader.Close();
                        instance = s ?? new Settings();
                    }
                }
            }
            return(instance);
        }
Esempio n. 2
0
        private void setDefaultValues()
        {
            this.serverStatisticDataStorageDirectory = String.Format("{0}\\plugins\\Data\\",
                                                                     Path.GetDirectoryName(SettingsXmlPath));

            if (ServerSchemaStats.GetLoger() != null)
            {
                ServerSchemaStats.GetLoger().Log("ServerStats", "Assigned default values", MessageLevel.Info);
            }

            this.SettingsValueChanged();
        }
Esempio 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 (ServerSchemaStats.GetLoger() != null)
         {
             ServerSchemaStats.GetLoger().Log("ServerStats", string.Format("Unable to save file with setting\n{0}", ex), MessageLevel.Error);
         }
     }
 }