Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Used to asynchronously compute difference between two
- /// differenceable objects. When the corresponding computation is
- /// complete, the 'DifferenceSnapshotComputed' event is raised.
- /// </summary>
- public class DifferenceSnapshot
- {
- public event EventHandler<EventArgs> DifferenceSnapshotComputed;
- /// <summary>
- /// Is equal to 'null' if the difference is not yet computed.
- /// Guaranteed to be non-null when the 'DifferenceSnapshotComputed' event
- /// was raised and becomes immutable after that.
- /// </summary>
- public IImmutableDifferenceBuffer DifferenceBuffer;
- public DifferenceSnapshot(IDifferenceable left, IDifferenceable right)
- {
- // ...
- }
- }
- public class DifferenceViewer
- {
- private readonly DifferenceSnapshot differenceSnapshot;
- /// <summary>
- /// Called when the difference snapshot finished it's evaluation.
- /// </summary>
- private readonly EventHandler<EventArgs>
- performPostponedDifferenceSnapshotProjection;
- public DifferenceViewer(DifferenceSnapshot differenceSnapshot)
- {
- this.differenceSnapshot = differenceSnapshot;
- if (differenceSnapshot.DifferenceBuffer == null)
- {
- performPostponedDifferenceSnapshotProjection =
- (sender, args) =>
- {
- // This postponed projection is only done once when
- // the corresponding difference snapshot finished it's
- // computation.
- differenceSnapshot.DifferenceSnapshotComputed -=
- performPostponedDifferenceSnapshotProjection;
- ProjectDifferenceSnapshotToView();
- };
- differenceSnapshot.DifferenceSnapshotComputed +=
- performPostponedDifferenceSnapshotProjection;
- }
- else
- {
- ProjectDifferenceSnapshotToView();
- }
- }
- private void ProjectDifferenceSnapshotToView()
- {
- if (differenceSnapshot.DifferenceBuffer == null)
- throw new InvalidOperationException(
- "Difference snapshot is not yet computed.");
- // Perform some actions which result in displaying the
- // corresponding snapshot in the user view.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement