private void ProcessMessage(OTMessage message) { if (message.Content.Count == 0) { return; } if (MessageArrived != null) { MessageArrived(this, message); } foreach (var op in message.Content) { var operationContext = Documents[op.DocumentName]; var cachedOps = operationContext.Log.Where(item => item.ServerMessages > op.ServerMessages && !item.OwnerId.Equals(op.OwnerId)); Operation transformed = null; foreach (var cachedOp in cachedOps) { transformed = transformer.Transform(cachedOp, op); } Execute(op, operationContext); operationContext.ServerMessages++; } Broadcast(message); SendAck(message); }
private void SendAck(OTMessage msg) { var to = Clients.Where(c => c.Key == msg.Content.FirstOrDefault().OwnerId).FirstOrDefault(); to.Value.ClientMessages += msg.Content.Count; var ack = new OTAck(to.Value.ClientMessages, this.serverMessages); Task.Factory.StartNew(() => to.Value.Client.SendAck(ack)); }
private void Broadcast(OTMessage msg) { var to = Clients.Where(c => c.Key != msg.Content.FirstOrDefault().OwnerId).ToList(); foreach (var entry in to) { Task.Factory.StartNew(() => entry.Value.Client.Forward(msg)); if (MessageSent != null) { MessageSent(this, msg); } } }
public void Send(OTMessage message) { Task.Factory.StartNew(() => ProcessMessage(message)); //ProcessMessage(message); }