예제 #1
0
        public override string GetLine()
        {
            switch (CoreAction.Type)
            {
            case CoreRequest.Types.KeyPress:
                return(MachineFile.KeyCommand(Id, CoreAction.Ticks, CoreAction.KeyCode, CoreAction.KeyDown));

            case CoreRequest.Types.Reset:
                return(MachineFile.ResetCommand(Id, CoreAction.Ticks));

            case CoreRequest.Types.LoadDisc:
                return(MachineFile.LoadDiscCommand(Id, CoreAction.Ticks, CoreAction.Drive, CoreAction.MediaBuffer.GetBytes()));

            case CoreRequest.Types.LoadTape:
                return(MachineFile.LoadTapeCommand(Id, CoreAction.Ticks, CoreAction.MediaBuffer.GetBytes()));

            case CoreRequest.Types.CoreVersion:
                return(MachineFile.VersionCommand(Id, CoreAction.Ticks, CoreAction.Version));

            case CoreRequest.Types.RunUntil:
                return(MachineFile.RunCommand(Id, CoreAction.Ticks, CoreAction.StopTicks));

            default:
                throw new ArgumentException(String.Format("Unrecognized core action type {0}.", CoreAction.Type), "type");
            }
        }
예제 #2
0
        public bool Persist(IFileSystem fileSystem, string filepath)
        {
            using (AutoPause())
            {
                if (File != null)
                {
                    // We already are persisted!
                    throw new InvalidOperationException("This machine is already persisted!");
                }

                if (String.IsNullOrEmpty(filepath))
                {
                    throw new ArgumentException("Invalid filepath.", nameof(filepath));
                }

                ITextFile   textFile    = fileSystem.OpenTextFile(filepath);
                MachineFile machineFile = new MachineFile(textFile, _history);

                machineFile.WriteHistory(_name);

                File = machineFile;

                PersistantFilepath = filepath;

                return(true);
            }
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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;
            }
        }
예제 #6
0
 public override string GetLine()
 {
     return(MachineFile.AddBookmarkCommand(Id, Ticks, Bookmark.System, Bookmark.Version, Node.CreateDate, Bookmark.State.GetBytes(), Bookmark.Screen.GetBytes()));
 }