using System.Net; using XFEExtension.NetCore.CyberComm; using XFEExtension.NetCore.ServerInteractive.Models.ServerModels; using XFEExtension.NetCore.XFETransform.JsonConverter; namespace XFEExtension.NetCore.ServerInteractive.Interfaces.CoreService; /// /// XFE服务器核心标准服务基类接口 /// public interface IXFEStandardServerCoreServiceBase : IXFEServerCoreServiceBase { /// /// 当前请求的路由路径 /// string Route { get; set; } /// /// 客户端IP地址 /// string ClientIP { get; set; } /// /// 是否是标准错误(如果是标准错误,服务器将自动处理并返回给客户端;如果不是,服务器将输出报错及堆栈信息) /// bool IsStandardError { get; set; } /// /// 错误抛出是否已经处理完成(如果为true,表示错误已经被处理,不需要ErrorProcessor再次处理) /// bool Handled { get; set; } /// /// 当前请求的 json 节点 /// QueryableJsonNode? Json { get; set; } /// /// 当前请求的返回参数 /// ServerCoreReturnArgs ReturnArgs { get; set; } /// /// 当前请求的事件参数 /// CyberCommRequestEventArgs Args { get; set; } /// /// 当前请求对象。 /// [Obsolete("Use Args.Request instead. This compatibility shim will be removed in a future release.")] HttpListenerRequest? Request => Args?.Request; /// /// Sends a reply message asynchronously using the current context. /// /// The message text to send as a reply. Cannot be null or empty. /// A task that represents the asynchronous send operation. Task Send(string message); /// /// Sends a binary message using the specified buffer asynchronously. /// /// The byte array containing the data to be sent as the binary message. Cannot be null. /// A task that represents the asynchronous send operation. Task Send(byte[] buffer); /// /// Sends the contents of the specified stream as a binary message asynchronously. /// /// The stream containing the data to send. The stream must be readable and positioned at the beginning of the data /// to be sent. /// A task that represents the asynchronous send operation. Task Send(Stream stream); /// /// Sends an object as JSON asynchronously. /// /// The object to serialize to JSON and send. Task Send(object data); /// /// 关闭并返回 OK /// void OK(); /// /// 返回信息并关闭 /// /// 要返回的信息 Task Close(string message); /// /// 结束与客户端的通讯 /// /// Task Close(byte[] buffer); /// /// 结束与客户端的通讯 /// /// Task Close(Stream stream); /// /// 返回错误信息并关闭 /// /// 要返回的错误信息 /// HTTP 状态码 Task CloseWithError(string message, HttpStatusCode code = HttpStatusCode.BadRequest); /// /// 以异常结束与客户端的通讯 /// /// /// /// ServerCoreReturnArgs Error(string message, HttpStatusCode code = HttpStatusCode.BadRequest, bool handled = false); /// /// Sends the specified object serialized as JSON and closes the connection. /// /// The object to serialize to JSON and send. Task Close(object data); }