Exemplo n.º 1
0
        public NodeWrapper LoadNode(Guid id)
        {
            NodeWrapper4Mongo wrapper = _proxy.Node.FindOneAs <NodeWrapper4Mongo>(Query <NodeWrapper4Mongo> .EQ(e => e.NodeId, id));

            if (wrapper != null)
            {
                var       unitWrapper = _unitRepository.LoadUnit(wrapper.UnitId);
                Converter converter   = new Converter(_options.JsonSingleChildAsCollection);
                wrapper.Node = converter.SerializableObjectToNode(wrapper.Data, unitWrapper.Unit);
            }
            return(wrapper);
        }
Exemplo n.º 2
0
        public void SaveNode(NodeWrapper wrapper)
        {
            NodeWrapper4Mongo wrapper4Mongo = new NodeWrapper4Mongo(wrapper);
            var reload = LoadNode(wrapper.NodeId);

            if (reload != null)
            {
                if (reload.Version != wrapper.Version)
                {
                    throw new ConcurrencyException(wrapper.NodeId.ToString());
                }
                wrapper4Mongo.Id      = (reload as NodeWrapper4Mongo).Id;
                wrapper4Mongo.Version = wrapper4Mongo.Version + 1;
            }
            Converter converter = new Converter(_options.JsonSingleChildAsCollection);

            wrapper4Mongo.Data = converter.NodeToSerializableObject(wrapper.Node);
            wrapper4Mongo.Node = null;
            _proxy.Node.Save(wrapper4Mongo);
        }