public Message Parse(string message)
        {
            Message ret;
            if (String.IsNullOrWhiteSpace(message))
            {
                throw new ServerProtocolParsingError("Message empty");
            }

            var messageTrimed = message.Trim();

            var pushPrefix = "push/";
            if (messageTrimed.StartsWith(pushPrefix))
            {
                var content = message.Substring(pushPrefix.Length);
                ret = new Push(content);

            }
            else if (messageTrimed.Equals("pull"))
            {
                ret = new Pull();
            }
            else
            {
                var matc = Regex.Match(messageTrimed, "^register/([a-z-0-9]+)/(.+)$", RegexOptions.Multiline | RegexOptions.Singleline);
                if (matc.Success)
                {
                    var group = matc.Groups[1].Value;
                    var model = matc.Groups[2].Value;
                    ret = new Register(group, model);
                }
                else
                {
                    throw new ServerProtocolParsingError("Unknown action");
                }
            }

            return ret;
        }
        private void RegisterHandler(Register register)
        {
            var client = Context.WebSocket;
            _clients.Add(register.GetNodeName(), client);
            var currentModel = WSGroupServices.GetModelService().getCurrentModel().getModel();

            var kf = new DefaultKevoreeFactory();
            // we clone the marshalled instance into a proper one
            var modelToApply = (ContainerRoot)kf.createJSONLoader().loadModelFromString(currentModel.serialize()).get(0);

            // We merge received model with current one
            ContainerRoot recModel = (ContainerRoot)WSGroupServices.GetJsonModelLoader()
                        .loadModelFromString(register.GetModel()).get(0);

            TraceSequence tseq = WSGroupServices.GetModelCompare().merge(modelToApply, recModel);
            tseq.applyOn(modelToApply);

            Dictionary<string, string> context = new Dictionary<string, string>();
            context.Add("nodeName", register.GetNodeName());
            context.Add("groupName", WSGroupServices.GetContext().getInstanceName());
            if (DoesFilterMatchIncomingNodeName(register.GetNodeName(), WSGroupServices.GetFilter()))
            {
                ApplyOnConnect(context, modelToApply);
            }
            else
            {
                var push = new Push(new ContainerRootMarshalled(modelToApply).serialize());
                _clients[register.GetNodeName()].Send(push.Serialize());
            }
        }
 private void PushHandler(Push pushMessage)
 {
     ModelUtil.UpdateModelLocaly(pushMessage.GetModel());
     BroadcastToTheGroup(pushMessage);
 }