EddiSpeechResponder.SpeechResponderConfiguration.ToFile C# (CSharp) Метод

ToFile() публичный Метод

Write configuration to a file. If the filename is not supplied then the path used when reading in the configuration will be used, or the default path of Constants.Data_DIR\speechresponder.json will be used
public ToFile ( string filename = null ) : void
filename string
Результат void
        public void ToFile(string filename = null)
        {
            if (filename == null)
            {
                filename = dataPath;
            }
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\speechresponder.json";
            }

            string json = JsonConvert.SerializeObject(this, Formatting.Indented);
            File.WriteAllText(filename, json);
        }
    }

Usage Example

Пример #1
0
        /// <summary>
        /// Change the personality for the speech responder
        /// </summary>
        /// <returns>true if the speech responder is now using the new personality, otherwise false</returns>
        public bool SetPersonality(string newPersonality)
        {
            SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();

            if (newPersonality == configuration.Personality)
            {
                // Already set to this personality
                return(true);
            }

            // Ensure that this personality exists
            Personality personality = Personality.FromName(newPersonality);

            if (personality != null)
            {
                // Yes it does; use it
                configuration.Personality = newPersonality;
                configuration.ToFile();
                scriptResolver = new ScriptResolver(personality.Scripts);
                Logging.Debug("Changed personality to " + newPersonality);
                return(true);
            }
            else
            {
                // No it does not; ignore it
                return(false);
            }
        }
All Usage Examples Of EddiSpeechResponder.SpeechResponderConfiguration::ToFile
SpeechResponderConfiguration