/// <summary> /// Ctor <see cref="HandsHistoryMemento"/>. /// </summary> public HandsHistoryMemento(IReadOnlyList <Hand> hands, HandsHistoryMemento previous = null, HandsHistoryMemento next = null) { Hands = hands; Previous = previous; Next = next; }
/// <inheritdoc /> public bool SaveHands(IReadOnlyList <Hand> hands) { _hands = hands ?? throw new ArgumentNullException(nameof(hands)); // New hands -> new memento snapshot! _memento = new HandsHistoryMemento(_hands); UpdateUsers(); return(true); }
/// <inheritdoc /> /// <remarks> /// Memento use only on removed/restore hands. /// </remarks> public bool RemoveHand(string id) { CheckHands(); var hand = _hands.FirstOrDefault(x => x.Id == id); if (hand == null) { _notificationManager.ShowErrorMessage($"Can not find in collection hand by id {id}"); return(false); } _hands = _hands.Where(x => x.Id != id).ToList(); _memento = _memento.AddNext(new HandsHistoryMemento(_hands, _memento)); UpdateUsers(); return(true); }
/// <inheritdoc /> public void Redo() { if (_memento == null) { _notificationManager.ShowErrorMessage("Please, change path where are hands"); return; } if (_memento.Next != null) { _hands = _memento.Next.Hands; _memento = _memento.Next; UpdateUsers(); } else { _notificationManager.ShowMessage("Can not do 'redo'"); } }
/// <inheritdoc /> public void SaveHandsHistoryPath(string path) { if (path.IsEmpty()) { throw new ArgumentNullException(nameof(path)); } var files = DirectoryUtils.DirectoryDirSearch(path, new List <string>(), true); if (files.IsEmpty()) { throw new EmptyFolderException(path); } _hands = _parser.ParseHandsByFilePath(files); CheckHands(); UpdateUsers(); // New files -> new memento snapshot! _memento = new HandsHistoryMemento(_hands); }
/// <summary> /// Add next memento. /// </summary> public HandsHistoryMemento AddNext(HandsHistoryMemento memento) { Next = memento; return(memento); }