Ejemplo n.º 1
0
 private Protobuf.ReplicationMessage GetNextMessage()
 {
     if (nextMessage == null)
     {
         nextMessage = new Protobuf.ReplicationMessage();
     }
     return(nextMessage);
 }
Ejemplo n.º 2
0
        void IReplicationStreamWriter.WriteTo(Stream stream)
        {
            WriteUpdates(GetNextMessage());

            if (nextMessage != null)
            {
                nextMessage.WriteTo(stream);
                nextMessage = null;
            }
        }
Ejemplo n.º 3
0
        private void WriteRemove(Protobuf.ReplicationMessage message, Replica replica)
        {
            var removeMessage = new Protobuf.RemoveMessage()
            {
                ReplicaId = replica.Id
            };

            message.Actions.Add(new Protobuf.ReplicationMessage.Types.ActionMessage()
            {
                Remove = removeMessage
            });
        }
Ejemplo n.º 4
0
        private void WriteRemoteCall(Protobuf.ReplicationMessage message, FunctionId functionId, IMessage argument)
        {
            var remoteCallMessage = new Protobuf.RemoteCallMessage()
            {
                FunctionId = functionId,
                TypeId     = system.GetTypeId(argument.GetType()),
                Argument   = argument.ToByteString()
            };

            message.Actions.Add(new Protobuf.ReplicationMessage.Types.ActionMessage()
            {
                RemoteCall = remoteCallMessage
            });
        }
Ejemplo n.º 5
0
        private void WriteAdd(Protobuf.ReplicationMessage message, Replica replica)
        {
            var addMessage = new Protobuf.AddMessage()
            {
                TypeId    = system.GetTypeId(replica.Value.GetType()),
                ReplicaId = replica.Id.Value,
                Replica   = replica.Value.ToByteString()
            };

            message.Actions.Add(new Protobuf.ReplicationMessage.Types.ActionMessage()
            {
                Add = addMessage
            });
        }
Ejemplo n.º 6
0
        private void WriteUpdate(Protobuf.ReplicationMessage message, Replica replica)
        {
            var value = replica.Value.ToByteString();

            if (options.AllowDifferentOnly && replica.DifferentOnly)
            {
                if (lastValues.TryGetValue(replica.Id, out ByteString lastState) && value.Equals(lastState))
                {
                    // Identical to last state, skip it
                    return;
                }
                lastValues[replica.Id] = value;
            }

            var updateMessage = new Protobuf.UpdateMessage();

            updateMessage.ReplicaId = replica.Id;
            updateMessage.Replica   = value;
            message.Updates.Add(updateMessage);
        }
Ejemplo n.º 7
0
        private void WriteUpdates(Protobuf.ReplicationMessage message)
        {
            IEnumerable <Replica> replicas = updated;

            if (options.AllowAlwaysUpdate)
            {
                replicas = replicas.Concat(system.Replicas.Where(r => (!options.MasterOnly || r.Master) && r.AlwaysUpdate));
            }

            if (options.Culling != null)
            {
                replicas = replicas.Where(d => options.Culling(d));
            }

            foreach (var replica in replicas)
            {
                WriteUpdate(message, replica);
            }

            updated.Clear();
        }