Exemplo n.º 1
0
        public override void onAdd(BlockSymbol blockSymbol, Client client)
        {
            APlay.Common.Logging.Logger.LogDesigned(2, "OnAdd(blockSymbol) Pos: " + blockSymbol.PositionX + "/" + blockSymbol.PositionY, "AplayTest.Server.Sheet");

            var undoObject = new BlockSymbolUndoable(blockSymbol);

            _undoService.AddInsert(Id, undoObject, BlockSymbols.Count, "Adding new Block", client.Id);

            BlockSymbols.Add(blockSymbol);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        private void Dump()
        {
            var dump = "Sheet:" + Name + ", Conns. #: " + Connections.Count + ", BlockSymbol #: " + BlockSymbols.Count +
                       ", Connectors #: " +
                       BlockSymbols.Count;


            foreach (var blockSymbol in BlockSymbols)
            {
                dump += "\n" + blockSymbol.Dump();
            }

            foreach (var connector in BlockSymbols.SelectMany(b => b.Connectors))
            {
                dump += "\n" + connector.Dump();
            }

            foreach (var connection in Connections)
            {
                dump += "\n" + connection.Dump();
            }

            Console.WriteLine(dump);
        }