Exemplo n.º 1
0
 protected static FactMemento CreateRoom(long domainId)
 {
     FactMemento room = new FactMemento(TypeRoom);
     room.Data = new byte[] { 1, 2, 3, 4 };
     room.AddPredecessor(RoleRoomDomain, new FactID { key = domainId }, true);
     return room;
 }
        private static FactMemento NewMove(FactID gameId, byte moveIndex)
        {
            var move = new FactMemento(MoveType);

            move.Data = new byte[] { moveIndex };
            move.AddPredecessor(MoveGame, gameId, true);
            return(move);
        }
        protected static FactMemento CreateRoom(long domainId)
        {
            FactMemento room = new FactMemento(TypeRoom);

            room.Data = new byte[] { 1, 2, 3, 4 };
            room.AddPredecessor(RoleRoomDomain, new FactID {
                key = domainId
            }, true);
            return(room);
        }
Exemplo n.º 4
0
        private IdentifiedFactMemento DeserlializeIdentifiedFactMemento(BinaryReader factReader, long factId)
        {
            short dataSize;

            byte[] data;
            short  predecessorCount;

            CorrespondenceFactType factType = GetFactType(BinaryHelper.ReadShort(factReader));

            dataSize = BinaryHelper.ReadShort(factReader);
            if (dataSize > MaxDataLength)
            {
                throw new CorrespondenceException("Maximum data length exceeded.");
            }
            data             = dataSize > 0 ? factReader.ReadBytes(dataSize) : new byte[0];
            predecessorCount = BinaryHelper.ReadShort(factReader);
            if (predecessorCount > MaxPredecessorCount)
            {
                throw new CorrespondenceException("Maximum predecessor count exceeded.");
            }

            FactMemento factMemento = new FactMemento(factType);

            factMemento.Data = data;
            for (short i = 0; i < predecessorCount; i++)
            {
                bool isPivot;
                long predecessorFactId;

                RoleMemento role = GetRole(BinaryHelper.ReadShort(factReader));
                isPivot           = BinaryHelper.ReadBoolean(factReader);
                predecessorFactId = BinaryHelper.ReadLong(factReader);

                factMemento.AddPredecessor(
                    role,
                    new FactID()
                {
                    key = predecessorFactId
                },
                    isPivot
                    );
            }

            return(new IdentifiedFactMemento(new FactID {
                key = factId
            }, factMemento));
        }
        private static FactMemento TranslateMemento(Dictionary <FactID, FactID> localIdByRemoteId, IdentifiedFactMemento identifiedFact)
        {
            FactMemento translatedMemento = new FactMemento(identifiedFact.Memento.FactType);

            translatedMemento.Data = identifiedFact.Memento.Data;
            foreach (PredecessorMemento remote in identifiedFact.Memento.Predecessors)
            {
                FactID localPredecessorId;
                if (!localIdByRemoteId.TryGetValue(remote.ID, out localPredecessorId))
                {
                    return(null);
                }

                translatedMemento.AddPredecessor(remote.Role, localPredecessorId, remote.IsPivot);
            }
            return(translatedMemento);
        }
 private static FactMemento NewMove(FactID gameId, byte moveIndex)
 {
     var move = new FactMemento(MoveType);
     move.Data = new byte[] { moveIndex };
     move.AddPredecessor(MoveGame, gameId, true);
     return move;
 }
        private static FactMemento TranslateMemento(Dictionary<FactID, FactID> localIdByRemoteId, IdentifiedFactMemento identifiedFact)
        {
            FactMemento translatedMemento = new FactMemento(identifiedFact.Memento.FactType);
            translatedMemento.Data = identifiedFact.Memento.Data;
            foreach (PredecessorMemento remote in identifiedFact.Memento.Predecessors)
            {
                FactID localPredecessorId;
                if (!localIdByRemoteId.TryGetValue(remote.ID, out localPredecessorId))
                    return null;

                translatedMemento.AddPredecessor(remote.Role, localPredecessorId, remote.IsPivot);
            }
            return translatedMemento;
        }
        private IdentifiedFactMemento DeserlializeIdentifiedFactMemento(BinaryReader factReader, long factId)
        {
            short dataSize;
            byte[] data;
            short predecessorCount;

            CorrespondenceFactType factType = GetFactType(BinaryHelper.ReadShort(factReader));
            dataSize = BinaryHelper.ReadShort(factReader);
            if (dataSize > MaxDataLength)
                throw new CorrespondenceException("Maximum data length exceeded.");
            data = dataSize > 0 ? factReader.ReadBytes(dataSize) : new byte[0];
            predecessorCount = BinaryHelper.ReadShort(factReader);
            if (predecessorCount > MaxPredecessorCount)
                throw new CorrespondenceException("Maximum predecessor count exceeded.");

            FactMemento factMemento = new FactMemento(factType);
            factMemento.Data = data;
            for (short i = 0; i < predecessorCount; i++)
            {
                bool isPivot;
                long predecessorFactId;

                RoleMemento role = GetRole(BinaryHelper.ReadShort(factReader));
                isPivot = BinaryHelper.ReadBoolean(factReader);
                predecessorFactId = BinaryHelper.ReadLong(factReader);

                factMemento.AddPredecessor(
                    role,
                    new FactID() { key = predecessorFactId },
                    isPivot
                );
            }

            return new IdentifiedFactMemento(new FactID { key = factId }, factMemento);
        }