Example #1
0
        public void SaveLatest()
        {
            if (_realImpl == null)
            {
                return;
            }
            RealScratchPage realImpl = GetRealImpl();

            using (var w = new LineWriter(LogFile.FullName, FileMode.Append))
                realImpl.SaveLatest(w.WriteLine);
            File.WriteAllText(TextFile.FullName, _realImpl.Text);
            _logStamp  = LogFile.LastWriteTimeUtc;
            _textStamp = TextFile.LastWriteTimeUtc;
        }
Example #2
0
        RealScratchPage LoadRealImpl()
        {
            // Load up a new real implementation from disk.
            RealScratchPage result = null;
            string          text   = null;

            // Try getting it from the log.
            try
            {
                if (LogFile.Exists)
                {
                    _logStamp = LogFile.LastWriteTimeUtc;
                    using (var reader = new LineReader(LogFile.FullName))
                        result = new RealScratchPage(reader.ReadLine);
                }
            }
            catch
            {
                result = null;
            }

            if (result == null)
            {
                result = new RealScratchPage();
            }

            // Try getting it from the text file.
            if (TextFile.Exists)
            {
                text       = File.ReadAllText(TextFile.FullName);
                _textStamp = TextFile.LastWriteTimeUtc;
            }

            // If there's a conflict, the text file wins, but keep log history; and rewrite it.
            if (text != null && result.Text != text)
            {
                result.Text = text;
                using (var w = new LineWriter(LogFile.FullName, FileMode.Create))
                    result.SaveAll(w.WriteLine);
                _logStamp = LogFile.LastWriteTimeUtc;
            }

            return(result);
        }