private async void SetTimeOffsets(ITimeOffsets value) // todo: consider converting setter to a public function { var oldOffsets = provider.TimeOffsets; if (oldOffsets.Equals(value)) { return; } var savedBookmarks = bookmarks.Items .Where(b => b.GetLogSource() == this) .Select(b => new { bmk = b, threadId = b.Thread.ID }) .ToArray(); await provider.SetTimeOffsets(value, CancellationToken.None); var invserseOld = oldOffsets.Inverse(); bookmarks.PurgeBookmarksForDisposedThreads(); foreach (var b in savedBookmarks) { var newBmkTime = b.bmk.Time.Adjust(invserseOld).Adjust(value); bookmarks.ToggleBookmark(new Bookmark( newBmkTime, logSourceThreads.GetThread(new StringSlice(b.threadId)), b.bmk.DisplayName, b.bmk.Position, b.bmk.LineIndex)); } owner.OnTimeOffsetChanged(this); using (var s = OpenSettings(false)) { s.Data.Root.SetAttributeValue("timeOffset", value.ToString()); } }
public BookmarkController( IBookmarks bookmarks, IModelThreads threads, IHeartBeatTimer heartbeat ) { tracer = LJTraceSource.EmptyTracer; threads.OnThreadListChanged += (s, e) => { bookmarksNeedPurgeFlag.Invalidate(); }; heartbeat.OnTimer += (sender, args) => { if (args.IsNormalUpdate && bookmarksNeedPurgeFlag.Validate()) { bookmarks.PurgeBookmarksForDisposedThreads(); } }; bookmarks.OnBookmarksChanged += (sender, e) => { if (e.Type == BookmarksChangedEventArgs.ChangeType.Added || e.Type == BookmarksChangedEventArgs.ChangeType.Removed || e.Type == BookmarksChangedEventArgs.ChangeType.RemovedAll || e.Type == BookmarksChangedEventArgs.ChangeType.Purged) { foreach (var affectedSource in e.AffectedBookmarks .Select(b => b.GetLogSource()) .Where(s => s.LogSourceStateIsOkToChangePersistentState()) .Distinct()) { try { affectedSource.StoreBookmarks(); } catch (Persistence.StorageException storageException) { tracer.Error(storageException, "Failed to store bookmarks for log {0}", affectedSource.GetSafeConnectionId()); } } } }; }