Ejemplo n.º 1
0
        /// <summary>
        /// Rewrites the machine file according to the current in-memory representation of the timeline.
        /// </summary>
        /// <param name="diffsEnabled">Enable calculation of diffs. Setting this to true can cause compacting to take a long time.</param>
        /// <remarks>
        /// This is useful for compacting the size of the machine file, due to the fact that bookmark and timeline deletions don't actually
        /// remove anything from the machine file, but simply log the fact they happened.
        /// </remarks>
        ///
        public void Compact(IFileSystem fileSystem)
        {
            // Only allow closed machines to compact!
            if (!CanCompact())
            {
                throw new Exception("Can't compact an open machine!");
            }

            string oldFilepath = PersistantFilepath;
            string newFilepath = oldFilepath + ".tmp";

            MachineFileInfo info = null;

            using (ITextFile textFile = fileSystem.OpenTextFile(oldFilepath))
            {
                info = MachineFile.Read(textFile);
            }

            using (ITextFile textFile = fileSystem.OpenTextFile(newFilepath))
                using (MachineFile writer = new MachineFile(textFile, info.History))
                {
                    writer.WriteHistory(info.Name);
                }

            fileSystem.ReplaceFile(oldFilepath, newFilepath);
        }
Ejemplo n.º 2
0
        static public MachineFileInfo Read(ITextFile textFile)
        {
            MachineFileReader reader = new MachineFileReader();

            reader.ReadFile(textFile);

            MachineFileInfo info = new MachineFileInfo(reader.Name, reader.History, reader.NextLineId);

            return(info);
        }
Ejemplo n.º 3
0
        static public LocalMachine GetClosedMachine(IFileSystem fileSystem, string filepath)
        {
            MachineFileInfo info = null;

            using (ITextFile textFile = fileSystem.OpenTextFile(filepath))
            {
                info = MachineFile.Read(textFile);
            }

            LocalMachine machine = New(info.Name, info.History, filepath);

            if (machine.History != null)
            {
                HistoryEvent historyEvent = machine.History.CurrentEvent.MostRecent <BookmarkHistoryEvent>();;

                machine.Display.GetFromBookmark((historyEvent as BookmarkHistoryEvent)?.Bookmark);
                machine.Display.EnableGreyscale(true);
            }

            return(machine);
        }
Ejemplo n.º 4
0
        public void OpenFromFile(IFileSystem fileSystem)
        {
            if (IsOpen)
            {
                return;
            }

            ITextFile textFile = null;

            try
            {
                textFile = fileSystem.OpenTextFile(PersistantFilepath);
                MachineFileInfo info = MachineFile.Read(textFile);
                MachineFile     file = new MachineFile(textFile, info.History, info.NextLineId);

                _history = info.History;
                _name    = info.Name;

                File = file;

                BookmarkHistoryEvent historyEvent = _history.CurrentEvent.MostRecent <BookmarkHistoryEvent>();
                SetCurrentEvent(historyEvent ?? _history.RootEvent);

                // Should probably be monitoring the IsOpen property, I think...
                Display.EnableGreyscale(false);
            }
            catch (Exception ex)
            {
                // Make sure we remove our lock on the machine file...
                textFile?.Dispose();
                textFile = null;

                File = null;

                throw ex;
            }
        }