コード例 #1
0
ファイル: Document.cs プロジェクト: Win10Mindapp/Mindmap
        public void BeginTransaction(string transactionName, DateTimeOffset?timestamp = null)
        {
            if (transaction == null)
            {
                var date = timestamp ?? DateTimeOffset.Now;

                transaction = new CompositeUndoRedoAction(transactionName, date);
            }
        }
コード例 #2
0
        public void Constructor_ValidParameters_PasseToProperties()
        {
            var name = "MyName";
            var date = DateTimeOffset.UtcNow.AddDays(13);

            CompositeUndoRedoAction composite = new CompositeUndoRedoAction(name, date);

            Assert.Equal(name, composite.Name);
            Assert.Equal(date, composite.Date);
            Assert.Equal(0, composite.Actions.Count);
        }
コード例 #3
0
ファイル: Document.cs プロジェクト: Win10Mindapp/Mindmap
        public void CommitTransaction()
        {
            if (transaction != null)
            {
                foreach (var command in transaction.Actions.OfType <IUndoRedoCommand>())
                {
                    command.Execute();
                }

                undoRedoManager.RegisterExecutedAction(transaction);

                transaction = null;
            }
        }
コード例 #4
0
ファイル: JsonHistory.cs プロジェクト: Win10Mindapp/Mindmap
        private static JsonHistoryStep CreateJsonStep(CompositeUndoRedoAction transaction)
        {
            var jsonStep = new JsonHistoryStep {
                Name = transaction.Name, Date = transaction.Date
            };

            foreach (var command in transaction.Actions.OfType <IUndoRedoCommand>())
            {
                var jsonCommand = new JsonHistoryStepCommand {
                    CommandType = CommandFactory.ToTypeName(command)
                };

                command.Save(jsonCommand.Properties);

                jsonStep.Commands.Add(jsonCommand);
            }

            return(jsonStep);
        }
コード例 #5
0
        public void ManyActions_UndoRedo_ActionsInvoked()
        {
            MockupAction action1 = new MockupAction();
            MockupAction action2 = new MockupAction();

            CompositeUndoRedoAction composite = new CompositeUndoRedoAction("MyName", DateTimeOffset.Now);

            composite.Add(action1);
            composite.Add(action2);

            Assert.Equal(2, composite.Actions.Count);

            composite.Undo();

            Assert.True(action1.IsUndoInvoked);
            Assert.True(action2.IsUndoInvoked);

            composite.Redo();

            Assert.True(action1.IsRedoInvoked);
            Assert.True(action2.IsRedoInvoked);
        }
コード例 #6
0
        public void AddAction_ActionIsNull_ThrowsException()
        {
            CompositeUndoRedoAction composite = new CompositeUndoRedoAction("MyName", DateTimeOffset.Now);

            Assert.Throws <ArgumentNullException>(() => composite.Add(null));
        }