/// <summary> /// 调用服务端实现的Api /// </summary> /// <param name="api">Api行为的api</param> /// <param name="parameters">参数列表</param> /// <exception cref="SocketException"></exception> /// <exception cref="SerializerException"></exception> public void InvokeApi(string api, params object[] parameters) { var packet = new FastPacket(api, this.packetIdProvider.GetId(), true); packet.SetBodyParameters(this.Serializer, parameters); this.Send(packet.ToByteRange()); }
/// <summary> /// 调用远程端的Api /// 并返回结果数据任务 /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <param name="session">会话对象</param> /// <param name="taskSetActionTable">任务行为表</param> /// <param name="serializer">序列化工具</param> /// <param name="packet">封包</param> /// <param name="timeout">超时时间</param> /// <exception cref="SocketException"></exception> /// <returns></returns> public static Task <T> InvokeApi <T>(ISession session, TaskSetActionTable taskSetActionTable, ISerializer serializer, FastPacket packet, TimeSpan timeout) { var task = taskSetActionTable.Create <T>(packet.Id, timeout); session.SendAsync(packet.ToByteRange()); return(task); }
/// <summary> /// 调用远程端实现的Api /// </summary> /// <param name="api">数据包Api名</param> /// <param name="parameters">参数列表</param> /// <exception cref="SocketException"></exception> /// <exception cref="SerializerException"></exception> /// <exception cref="ProtocolException"></exception> public void InvokeApi(string api, params object[] parameters) { var id = this.Server.PacketIdProvider.NewId(); var packet = new FastPacket(api, id, false); packet.SetBodyParameters(this.Server.Serializer, parameters); this.Send(packet.ToByteRange()); }
/// <summary> /// 调用远程端的Api /// 并返回结果数据任务 /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <param name="session">会话对象</param> /// <param name="taskSetActionTable">任务行为表</param> /// <param name="serializer">序列化工具</param> /// <param name="packet">封包</param> /// <exception cref="SocketException"></exception> public static Task <T> InvokeApi <T>(ISession session, TaskSetActionTable taskSetActionTable, ISerializer serializer, FastPacket packet) { var taskSource = new TaskCompletionSource <T>(); var taskSetAction = new TaskSetAction <T>(serializer, taskSource); taskSetActionTable.Add(packet.Id, taskSetAction); session.Send(packet.ToByteRange()); return(taskSource.Task); }
/// <summary> /// 调用远程端的Api /// 并返回结果数据任务 /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <param name="session">会话对象</param> /// <param name="taskSetActionTable">任务行为表</param> /// <param name="serializer">序列化工具</param> /// <param name="api">api</param> /// <param name="id">标识符</param> /// <param name="fromClient">是否为客户端封包</param> /// <param name="parameters">参数</param> /// <exception cref="SocketException"></exception> /// <exception cref="SerializerException"></exception> /// <returns></returns> public static Task <T> InvokeApi <T>(ISession session, TaskSetActionTable taskSetActionTable, ISerializer serializer, string api, long id, bool fromClient, params object[] parameters) { var taskSource = new TaskCompletionSource <T>(); var packet = new FastPacket(api, id, fromClient); packet.SetBodyParameters(serializer, parameters); // 登记TaskSetAction var setAction = FastTcpCommon.NewSetAction <T>(taskSource, serializer); var taskSetAction = new TaskSetAction(setAction); taskSetActionTable.Add(packet.Id, taskSetAction); session.Send(packet.ToByteRange()); return(taskSource.Task); }