BinaryReader sendMsg(StreamOp op, Action <BinaryWriter> mkbody = null) { byte[] body; using (var ms = new MemoryStream()) using (var write = new BinaryWriter(ms)) { write.Write(id); write.Write((byte)op); mkbody?.Invoke(write); body = ms.ToArray(); } ServerResponseType resp = ServerResponseType.REQ_SUCCESS; BinaryReader ret = null; Task.WaitAll(man.SendMessage(ServerMessageType.STREAM_OP, body, (aresp, aret) => { resp = aresp; ret = aret == null ? null : new BinaryReader(new MemoryStream(aret.ReadBytes((int)aret.BaseStream.Length))); })); switch (resp) // TODO: Improve error handling { case ServerResponseType.REQ_SUCCESS: break; case ServerResponseType.REQ_ERROR: throw new Exception(ret.ReadString()); default: throw new Exception(); } return(ret); }
public static ServerResponseCommand OK(ServerResponseType responseType, string message = "It's all OK!") { return(new ServerResponseCommand { statusCode = StatusCode.OK, responseType = responseType, Message = message }); }
public static ServerResponseCommand Error(ServerResponseType responseType, string message = "An error occured") { return(new ServerResponseCommand { statusCode = StatusCode.Error, responseType = responseType, Message = message }); }
public override void ParseFromString(string textToParse) { try { base.ParseFromString(textToParse); // get text to parse string responseTypeText = textToParse.Substring((int)Protocol.Instance.HeaderLength, (int)Protocol.Instance.ResponseTypeLength); _responseType = _serverResponseMapper[responseTypeText]; } catch (System.Exception e) { throw e; } }
public ServerResponse(ServerResponseType Type, object Data) { this.Type = Type; this.Data = Data; }
public ServerResponse(ServerResponseType type, object data) { Type = type; Data = data; }
/// <summary> /// Used to return a response from server to client /// </summary> /// <param name="message">The message</param> /// <param name="responseType">The type of the response</param> public ServerResponse(string message, ServerResponseType responseType) { this.ResponseType = responseType; this.Message = message; }