EddiSpeechResponder.Personality.ToFile C# (CSharp) Method

ToFile() public method

Write personality to a file. If the file name is not supplied the the default path of Constants.Data_DIR\personalities\eddi.json is used
public ToFile ( string filename = null ) : void
filename string
return void
        public void ToFile(string filename = null)
        {
            if (filename == null)
            {
                filename = dataPath;
            }
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\personalities\eddi.json";
            }

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

Usage Example

コード例 #1
0
        /// <summary>
        /// Create a copy of this file, altering the datapath appropriately
        /// </summary>
        public Personality Copy(string name, string description)
        {
            // Tidy the name up to avoid bad characters
            string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
            Regex  r           = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));

            name = r.Replace(name, "");

            // Save a copy of this personality
            string iname    = name.ToLowerInvariant();
            string copyPath = Constants.DATA_DIR + @"\personalities\" + iname + ".json";

            // Ensure it doesn't exist
            if (!File.Exists(copyPath))
            {
                ToFile(copyPath);
            }
            // Load the personality back in
            Personality newPersonality = FromFile(copyPath);

            // Change its name and description and save it back out again
            newPersonality.Name        = name;
            newPersonality.Description = description;
            newPersonality.ToFile();
            // And finally return it
            return(newPersonality);
        }
All Usage Examples Of EddiSpeechResponder.Personality::ToFile