public override void onRemove(BlockSymbol blockSymbol, Client client) { //this.SyncedWithBlockSymbol(blockSymbol); APlay.Common.Logging.Logger.LogDesigned(2, "Sheet.onRemove called", "AplayTest.Server.Sheet"); var toBeDeleted = BlockSymbols.First(t => t.Id == blockSymbol.Id); var index = BlockSymbols.IndexOf(toBeDeleted); _undoService.StartTransaction(client.Id, "Removing Block [" + toBeDeleted.Id + "]"); var undoableBlockSymbol = blockSymbol.CreateUndoable(); blockSymbol.PrepareForRemove(client.Id); _undoService.AddRemove(Id, undoableBlockSymbol, index, "Removing Block [" + toBeDeleted.Id + "]", client.Id); BlockSymbols.RemoveAt(index); var connections = blockSymbol.onGetAttachedConnections().ToList(); var connectionsindexList = new List <int>(); foreach (var connection in connections) { index = Connections.IndexOf(connection); if (index >= 0) { connectionsindexList.Add(index); } } connectionsindexList.Sort(); for (int i = connectionsindexList.Count - 1; i >= 0; i--) { var connection = connections[connectionsindexList[i]]; connection.PrepareForRemove(client.Id); var undoableConnection = connection.CreateUndoble(); _undoService.AddRemove(Id, undoableConnection, connectionsindexList[i], "Removing connection [" + undoableConnection.Id + "]", client.Id); Connections.Remove(connection); } _undoService.EndTransaction(client.Id); }
private void UndoServiceOnActiveStateChanged(object sender, ActiveStateChangedEventArgs e) { foreach (var change in e.ChangeSet.Where(c => c.OwnerId == Id)) { APlay.Common.Logging.Logger.LogDesigned(2, "ActiveStateChanged received and updated state. OwnerId: " + change.OwnerId, "AplayTest.Server.Sheet"); if (change.ChangeReason == ChangeReason.InsertAt) { if (change.Undoable is BlockSymbolUndoable) { BlockSymbols.Insert(change.IndexAt, _blockSymbolFactory.Create((BlockSymbolUndoable)change.Undoable, e.ChangeSet)); } else if (change.Undoable is ConnectionUndoable) { Connections.Insert(change.IndexAt, _connectionFactory.Create((ConnectionUndoable)change.Undoable, e.ChangeSet)); } } else if (change.ChangeReason == ChangeReason.RemoveAt) { if (change.Undoable is BlockSymbolUndoable) { BlockSymbols.RemoveAt(change.IndexAt); _blockSymbolFactory.Remove(change.Undoable.Id); } else if (change.Undoable is ConnectionUndoable) { Connections.RemoveAt(change.IndexAt); _connectionFactory.Remove(change.Undoable.Id); } } var storedObject = change.Undoable as SheetUndoable; if (storedObject != null) { if (change.ChangeReason == ChangeReason.Update) { Name = storedObject.Name; } } Dump(); } }