Ejemplo n.º 1
0
        private HistoryState getState()
        {
            var undoDepth = _uiConfigRepository.Config.UndoDepth;

            int minSaveIndex = _settingsIndex - undoDepth;
            int saveCount    = 1 + 2 * undoDepth;

            if (minSaveIndex < 0)
            {
                minSaveIndex = 0;
            }

            if (saveCount > _settingsHistory.Count - minSaveIndex)
            {
                saveCount = _settingsHistory.Count - minSaveIndex;
            }

            var state = new HistoryState
            {
                SettingsHistory = _settingsHistory.SkipFirst(minSaveIndex).TakeFirst(saveCount),
                SettingsIndex   = _settingsIndex - minSaveIndex
            };

            return(state);
        }
Ejemplo n.º 2
0
 internal static void WriteHistory(string file, HistoryState state)
 {
     using (var writer = File.CreateText(file))
         using (var jsonWriter = new JsonTextWriter(writer)
         {
             Formatting = Formatting.Indented, Indentation = 1, IndentChar = '\t'
         })
             _serializer.Serialize(jsonWriter, state);
 }
Ejemplo n.º 3
0
 internal static void WriteHistory(FsPath filename, HistoryState state)
 {
     FileUtil.SafeCreateFile(filename, file =>
     {
         using var writer = file.CreateText();
         var textWriter   = new JsonTextWriter(writer)
         {
             Formatting  = Formatting.Indented,
             Indentation = 1,
             IndentChar  = '\t'
         };
         using var jsonWriter = textWriter;
         _serializer.Serialize(jsonWriter, state);
     });
 }
Ejemplo n.º 4
0
        private HistoryState getState()
        {
            int minSaveIndex = _settingsIndex - _maxDepth;
            int saveCount    = 1 + 2 * _maxDepth;

            if (minSaveIndex < 0)
            {
                minSaveIndex = 0;
            }

            if (saveCount > _settingsHistory.Count - minSaveIndex)
            {
                saveCount = _settingsHistory.Count - minSaveIndex;
            }

            var state = new HistoryState
            {
                SettingsHistory = _settingsHistory.SkipFirst(minSaveIndex).TakeFirst(saveCount),
                SettingsIndex   = _settingsIndex - minSaveIndex
            };

            return(state);
        }
Ejemplo n.º 5
0
        internal bool TryReadHistory(FsPath file, out HistoryState state)
        {
            state = null;
            if (!file.IsFile())
            {
                return(false);
            }
            try
            {
                using (var fileReader = file.OpenText())
                {
                    using var jsonReader = new JsonTextReader(fileReader);
                    state = _serializer.Deserialize <HistoryState>(jsonReader);
                }

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex, "Failed to read history");
                return(false);
            }
        }