/// <summary> /// Draws a given history event at the given position. /// </summary> /// <param name="historyEvent">The history event to draw.</param> /// <param name="x">The position at which to draw the event.</param> /// <param name="next">The next chronological HistoryViewItem.</param> /// <param name="currentEvent">The current event in the machine's history.</param> private void Draw(HistoryEvent historyEvent, int x, HistoryViewItem next, HistoryEvent currentEvent) { if (historyEvent == null) { return; } // Calculate the "centre" of the cell at position x. double cx = x + 0.5; double cy = 0.5; // If the history event isn't "ours", then draw it as a "passthrough" line. bool passthrough = (HistoryEvent != historyEvent); if (historyEvent.Parent != null) { // Draw a line from our parent. DrawLine(cx, 1, cx, cy, Brushes.DarkBlue); } BookmarkHistoryEvent bookmarkHistoryEvent = historyEvent as BookmarkHistoryEvent; if (bookmarkHistoryEvent != null && bookmarkHistoryEvent.Bookmark != null && !passthrough) { // User bookmarks are drawn as a red dot, system bookmarks as dark red. DrawDot(cx, bookmarkHistoryEvent.Bookmark.System ? Brushes.DarkRed : Brushes.Crimson, historyEvent != currentEvent); } if (passthrough) { // A "passthrough" event is drawn as a straight line. int childNextX = next.EventIndex(historyEvent); if (childNextX != -1) { DrawLine(cx, cy, childNextX + 0.5, 0, Brushes.DarkBlue); } } else if (next != null && historyEvent.Children.Count >= 1) { // For history events with children, draw a line from the centre of the cell to each child for (int c = 0; c < historyEvent.Children.Count; c++) { int childNextX = next.EventAncestorIndex(historyEvent.Children[c]); if (childNextX != -1) { DrawLine(cx, cy, childNextX + 0.5, 0, Brushes.DarkBlue); } } } else { // History events with no children are drawn as a terminating dot. DrawDot(cx, (bookmarkHistoryEvent != null) ? (bookmarkHistoryEvent.Bookmark.System ? Brushes.DarkRed : Brushes.Crimson) : Brushes.DarkBlue, historyEvent != currentEvent); } }
public void Close() { lock (_runningStateLock) { if (IsOpen) { Stop(); try { // Create a system bookmark so the machine can resume from where it left off the next time it's loaded, but don't // create one if we already have a system bookmark at the current event, or we're at the root event. BookmarkHistoryEvent currentBookmarkEvent = _history.CurrentEvent as BookmarkHistoryEvent; if (currentBookmarkEvent == null || (currentBookmarkEvent.Ticks != Ticks) || (currentBookmarkEvent.Bookmark == null && currentBookmarkEvent != _history.RootEvent) || (currentBookmarkEvent.Bookmark != null && !currentBookmarkEvent.Bookmark.System)) { AddBookmark(true); } } finally { } } SetCore(null); if (File != null) { File.Dispose(); File = null; } _history = new History(); Status = null; Display?.EnableGreyscale(true); } }
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; } }
internal BookmarkHistoryNode(int id, UInt64 ticks, Bookmark bookmark, HistoryNode parent, DateTime createDate) : base(id, ticks, null, bookmark, parent, createDate) { Bookmark = bookmark; HistoryEvent = new BookmarkHistoryEvent(this); }