Ejemplo n.º 1
0
 /// <summary>
 /// Save a state
 /// </summary>
 /// <param name="state">The state to save it into</param>
 internal static void SaveState(int state)
 {
     CurrentMode = Mode.Saving;
     UndoAction  = new UndoActionType(state, LastActionType.backup);
     CanUndo     = true;
     ExposeData(PathHandler.GenBackupStateFile(state));
 }
Ejemplo n.º 2
0
 public MergeData(VoteLineBlock fromVote, List <VoteLineBlock> toVotes, UndoActionType actionType)
 {
     FromVote = fromVote;
     ToVote   = fromVote;
     ToVotes.AddRange(toVotes);
     UndoActionType = actionType;
 }
Ejemplo n.º 3
0
        // Join
        public UndoAction(UndoActionType actionType, VoteType voteType, Dictionary <string, string> postIDs,
                          List <string> joinedVoters, IEnumerable <KeyValuePair <string, HashSet <string> > > priorVotes)
        {
            if (actionType != UndoActionType.Join)
            {
                throw new InvalidOperationException("Invalid use of constructor for Join undo.");
            }
            if (joinedVoters == null)
            {
                throw new ArgumentNullException(nameof(joinedVoters));
            }
            if (priorVotes == null)
            {
                throw new ArgumentNullException(nameof(priorVotes));
            }

            ActionType = actionType;
            VoteType   = voteType;
            PostIDs    = new Dictionary <string, string>(postIDs, postIDs.Comparer);

            JoinedVoters = new List <string>(joinedVoters);

            PriorVotes = new List <KeyValuePair <string, HashSet <string> > >();
            foreach (var prior in priorVotes)
            {
                PriorVotes.Add(new KeyValuePair <string, HashSet <string> >(prior.Key, new HashSet <string>(prior.Value)));
            }
        }
Ejemplo n.º 4
0
        // Merge
        public UndoAction(UndoActionType actionType, VoteType voteType, Dictionary <string, string> postIDs,
                          string vote1, HashSet <string> voters1,
                          string vote2, HashSet <string> voters2)
        {
            if (actionType != UndoActionType.Merge)
            {
                throw new InvalidOperationException("Invalid use of constructor for Merge undo.");
            }
            if (vote1 == null)
            {
                throw new ArgumentNullException(nameof(vote1));
            }
            if (voters1 == null)
            {
                throw new ArgumentNullException(nameof(voters1));
            }
            if (vote2 == null)
            {
                throw new ArgumentNullException(nameof(vote2));
            }
            if (voters2 == null)
            {
                throw new ArgumentNullException(nameof(voters2));
            }

            ActionType = actionType;
            VoteType   = voteType;
            PostIDs    = new Dictionary <string, string>(postIDs, postIDs.Comparer);

            Vote1   = vote1;
            Voters1 = new HashSet <string>(voters1 ?? Enumerable.Empty <string>());

            Vote2   = vote2;
            Voters2 = new HashSet <string>(voters2 ?? Enumerable.Empty <string>());
        }
Ejemplo n.º 5
0
        // Merge rank votes
        public UndoAction(UndoActionType actionType, VoteType voteType, Dictionary <string, string> postIDs,
                          Dictionary <KeyValuePair <string, HashSet <string> >, string> mergedVotes)
        {
            if (actionType != UndoActionType.Merge)
            {
                throw new InvalidOperationException("Invalid use of constructor for Merge undo.");
            }
            if (voteType != VoteType.Rank)
            {
                throw new InvalidOperationException("Invalid use of constructor for non-rank merge.");
            }
            if (postIDs == null)
            {
                throw new ArgumentNullException(nameof(postIDs));
            }
            if (mergedVotes == null)
            {
                throw new ArgumentNullException(nameof(mergedVotes));
            }

            ActionType = actionType;
            VoteType   = voteType;
            PostIDs    = new Dictionary <string, string>(postIDs, postIDs.Comparer);

            MergedVotes = new Dictionary <KeyValuePair <string, HashSet <string> >, string>();
            foreach (var mergedVote in mergedVotes)
            {
                // original vote, revised vote key
                MergedVotes.Add(new KeyValuePair <string, HashSet <string> >(mergedVote.Key.Key, new HashSet <string>(mergedVote.Key.Value)), mergedVote.Value);
            }
        }
Ejemplo n.º 6
0
        // Partition Children votes
        public UndoAction(UndoActionType actionType, VoteType voteType, Dictionary <string, string> postIDs,
                          HashSet <string> addedVotes, string deletedVote, HashSet <string> voters)
        {
            if (actionType != UndoActionType.PartitionChildren)
            {
                throw new InvalidOperationException("Invalid use of constructor for Partition undo.");
            }
            if (addedVotes == null)
            {
                throw new ArgumentNullException(nameof(addedVotes));
            }
            if (voters == null)
            {
                throw new ArgumentNullException(nameof(voters));
            }
            if (string.IsNullOrEmpty(deletedVote))
            {
                throw new ArgumentNullException(nameof(deletedVote));
            }


            ActionType = actionType;
            VoteType   = voteType;
            PostIDs    = new Dictionary <string, string>(postIDs, postIDs.Comparer);

            Vote1   = deletedVote;
            Voters1 = new HashSet <string>(voters ?? Enumerable.Empty <string>());
            Voters2 = new HashSet <string>(addedVotes ?? Enumerable.Empty <string>());
        }
Ejemplo n.º 7
0
 public UndoAction(UndoActionType action, Card card, string index, string contents, AttachmentFile file)
 {
     this.Action = action;
     this.Data1  = card;
     this.Data2  = index;
     this.Data3  = contents;
     this.Data4  = file;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Load a state
 /// </summary>
 /// <param name="state">The state to load from</param>
 internal static void LoadState(int state)
 {
     //TODO: check if no mods were loaded
     CurrentMode = Mode.Loading;
     UndoAction  = new UndoActionType(state, LastActionType.restore);
     CanUndo     = true;
     ExposeData(PathHandler.GenBackupStateFile(state));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds a merge record.
        /// </summary>
        /// <param name="fromRecord">The original vote string.</param>
        /// <param name="toRecord">The revised vote string.</param>
        /// <param name="partitionMode">The partition mode.</param>
        public void AddMergeRecord(VoteLineBlock fromRecord, List <VoteLineBlock> toRecords,
                                   UndoActionType actionType, PartitionMode partitionMode)
        {
            var merges = GetMergesFor(partitionMode);

            MergeData data = new MergeData(fromRecord, toRecords, actionType);

            merges.Add(data);
        }
Ejemplo n.º 10
0
 private void addUndoAction(UndoActionType type)
 {
     if (CurrentDrawObject == null)
     {
         return;
     }
     _undos.Push(new UndoAction()
     {
         UndoActionType = type,
         DrawObject     = CurrentDrawObject.GetSerializable()
     });
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Removes the most recently added merge record of the given partition mode.
        /// </summary>
        /// <param name="partitionMode">The partition mode.</param>
        public void RemoveLastMergeRecord(PartitionMode partitionMode, UndoActionType actionType)
        {
            var merges = GetMergesFor(partitionMode);

            if (merges.Count > 0)
            {
                int index = merges.FindLastIndex(a => a.UndoActionType == actionType);

                if (index >= 0)
                {
                    merges.RemoveAt(index);
                }
            }
        }
Ejemplo n.º 12
0
        public UndoAction(UndoActionType actionType, VoteStorage currentState,
                          VoteLineBlock?storageVote = null)
        {
            ActionType = actionType;

            // Clone the current vote repository.
            storage = new VoteStorage(currentState);

            // Utilize a cloned storage vote if we need to track a changed VoteLineBlock
            // that had internal properties changed.  Otherwise those will be propogated
            // to our storage collection.
            if (storageVote != null)
            {
                var storedVote = storageVote.Clone();
                storage.TryGetValue(storageVote, out var storedVoteSupporters);
                storage.Remove(storageVote);
                storage.Add(storedVote, storedVoteSupporters);
            }
        }
Ejemplo n.º 13
0
        // Delete votes
        public UndoAction(UndoActionType actionType, VoteType voteType, Dictionary <string, string> postIDs,
                          Dictionary <string, HashSet <string> > deletedVotes)
        {
            if (actionType != UndoActionType.Delete)
            {
                throw new InvalidOperationException("Invalid use of constructor for Delete undo.");
            }
            if (deletedVotes == null)
            {
                throw new ArgumentNullException(nameof(deletedVotes));
            }

            ActionType = actionType;
            VoteType   = voteType;
            PostIDs    = new Dictionary <string, string>(postIDs, postIDs.Comparer);

            DeletedVotes = new Dictionary <string, HashSet <string> >();
            foreach (var deletedVote in deletedVotes)
            {
                DeletedVotes.Add(deletedVote.Key, new HashSet <string>(deletedVote.Value));
            }
        }
Ejemplo n.º 14
0
 public UndoAction(UndoActionType action, Card card, string text)
 {
     this.Action = action;
     this.Data1  = card;
     this.Data2  = text;
 }
Ejemplo n.º 15
0
 public UndoAction(UndoActionType action, Card card)
 {
     this.Action = action;
     this.Data1  = card;
 }
Ejemplo n.º 16
0
 public MergeData(VoteLineBlock fromVote, VoteLineBlock toVote, UndoActionType actionType)
 {
     FromVote       = fromVote;
     ToVote         = toVote;
     UndoActionType = actionType;
 }
Ejemplo n.º 17
0
 public UndoAction(UndoActionType action, int index, Card card)
 {
     this.Action = action;
     this.Data1  = index;
     this.Data2  = card;
 }
Ejemplo n.º 18
0
 public UndoAction(UndoActionType action, Card card, AttachmentFile file)
 {
     this.Action = action;
     this.Data1  = card;
     this.Data2  = file;
 }