/// <summary> /// 操作数据 /// </summary> /// <param name="parameter">短路径操作参数</param> /// <returns>返回参数</returns> internal ValueData.Data Operation(ref OperationParameter.ShortPathOperationNode parameter) { if (CanWrite) { if (parameter.Buffer != null) { if (parameter.Identity.Ticks == startTicks) { byte[] packet; Cache.Value.Node node = shortPaths[parameter.Identity.Index].Get(parameter.Identity.Identity, out packet); if (packet.Length == parameter.Identity.PacketSize) { if (node.IsNode) { byte[] bufferData = parameter.Buffer.Array.Array; System.Buffer.BlockCopy(packet, 0, bufferData, parameter.Buffer.Array.Start + OperationParameter.Serializer.HeaderSize, parameter.Identity.PacketSize); fixed(byte *bufferFixed = bufferData) { OperationParameter.NodeParser parser = new OperationParameter.NodeParser(this, parameter.Buffer, bufferFixed); parser.Read += parameter.Identity.PacketSize; node.Operation(ref parser); if (parser.IsOperation) { onOperation(parameter.Buffer); } else { parameter.Buffer.FreeReference(); } return(parser.ReturnParameter); } } return(new ValueData.Data(ReturnType.NotFoundShortPathNode)); } } return(new ValueData.Data(ReturnType.NotFoundShortPath)); } return(new ValueData.Data(ReturnType.ServerDeSerializeError)); } return(new ValueData.Data(ReturnType.CanNotWrite)); }
/// <summary> /// 操作数据 /// </summary> /// <param name="parameter">短路径操作参数</param> /// <param name="onOperation"></param> internal void Operation(ref OperationParameter.ShortPathOperationNode parameter, Func <AutoCSer.Net.TcpServer.ReturnValue <ReturnParameter>, bool> onOperation) { ReturnType returnType = ReturnType.CanNotWrite; try { if (CanWrite) { if (parameter.Buffer != null) { returnType = ReturnType.NotFoundShortPath; if (parameter.Identity.Ticks == startTicks) { byte[] packet; Cache.Value.Node node = shortPaths[parameter.Identity.Index].Get(parameter.Identity.Identity, out packet); if (packet.Length == parameter.Identity.PacketSize) { if (node.IsNode) { returnType = ReturnType.Unknown; byte[] bufferData = parameter.Buffer.Array.Array; System.Buffer.BlockCopy(packet, 0, bufferData, parameter.Buffer.Array.Start + OperationParameter.Serializer.HeaderSize, parameter.Identity.PacketSize); fixed(byte *bufferFixed = bufferData) { OperationParameter.NodeParser parser = new OperationParameter.NodeParser(this, parameter.Buffer, bufferFixed); parser.Read += parameter.Identity.PacketSize; parser.OnReturn = onOperation; try { node.Operation(ref parser); } finally { if (parser.OnReturn == null) { returnType = ReturnType.Success; } } if (parser.IsOperation) { this.onOperation(parameter.Buffer); } else { parameter.Buffer.FreeReference(); } return; } } else { returnType = ReturnType.NotFoundShortPathNode; } } } } else { returnType = ReturnType.ServerDeSerializeError; } } parameter.Buffer.FreeReference(); } finally { if (returnType != ReturnType.Success) { onOperation(new ReturnParameter(returnType)); } } }