Bloom.Book.UserPrefs.Save C# (CSharp) Method

Save() private method

private Save ( ) : void
return void
        private void Save()
        {
            // We're checking this because the deserialization routine calls the property setters which triggers a save. We don't
            // want to save while loading.
            if(_loading)
                return;
            var prefs = JsonConvert.SerializeObject(this);

            Debug.Assert(!string.IsNullOrWhiteSpace(prefs));

            try
            {
                if(!string.IsNullOrWhiteSpace(prefs))
                {
                    var temp = new TempFileForSafeWriting(_filePath);
                    RobustFile.WriteAllText(temp.TempFilePath, prefs);
                    temp.WriteWasSuccessful();
                }
            }
            catch(Exception error)
            {
                //For https://silbloom.myjetbrains.com/youtrack/issue/BL-3222  we did a real fix for 3.6.
                //But this will cover us for future errors here, which are not worth stopping the user from doing work.
                NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All, "Problem saving book preferences", "book.userprefs could not be saved to " + _filePath, error);
            }
        }