public static void DoHandle(Client client, byte[] data, Server server) { BaseResponseData responseData = null; try { LoginData loginData = Utils.ToObjectFromBytes <LoginData>(data); client.Nickname = loginData.Nickname; responseData = new BaseResponseData(RequestTypes.Login, RequestResult.Ok); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); Console.WriteLine(string.Format("Client login with Nickname {0}", loginData.Nickname)); } catch (Exception e) { responseData = new BaseResponseData(RequestTypes.Login, RequestResult.Error); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); Console.WriteLine("Error {0} - {1}", e.Message, e.StackTrace); } }
public static void DoHandle(Client client, byte[] data, Server server) { BaseResponseData responseData = null; try { SendMessageData sendMessageData = Utils.ToObjectFromBytes <SendMessageData>(data); Console.WriteLine("Message from client: " + sendMessageData.Message); int roomIDSendMessage = client.CurrentRoomID; ChatMessageData chatMessageData = new ChatMessageData(client.Nickname, sendMessageData.Message); server.SendEventData(server.GetRoomByID(roomIDSendMessage).Clients, (byte)EventTypes.ChatMessage, chatMessageData); responseData = new BaseResponseData(RequestTypes.SendMessage, RequestResult.Ok); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); } catch (Exception e) { responseData = new BaseResponseData(RequestTypes.SendMessage, RequestResult.Ok); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); Console.WriteLine("Error {0} - {1}", e.Message, e.StackTrace); } }
public static void DoHandle(Client client, byte[] data, Server server) { BaseResponseData responseData = null; try { EnterInRoomData enterInRoomData = Utils.ToObjectFromBytes <EnterInRoomData>(data); Room room = server.GetRoomByName(enterInRoomData.Name); if (room == null) { responseData = new BaseResponseData(RequestTypes.EnterInRoom, RequestResult.UnknowRoom); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); return; } server.RemoveClientFromRoom(client, client.CurrentRoomID); AddClientInRoom(client, room.ID, server); Console.WriteLine("Client entered in room"); } catch (Exception e) { responseData = new BaseResponseData(RequestTypes.EnterInRoom, RequestResult.Ok); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); Console.WriteLine("Error {0} - {1}", e.Message, e.StackTrace); } }
public static void DoHandle(Client client, byte[] data, Server server) { BaseResponseData responseData = null; try { CreateRoomData createRoomData = Utils.ToObjectFromBytes <CreateRoomData>(data); if (!CreateRoom(createRoomData.Name, client, server)) { responseData = new BaseResponseData(RequestTypes.CreateRoom, RequestResult.RoomExist); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); return; } responseData = new BaseResponseData(RequestTypes.CreateRoom, RequestResult.Ok); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); Request_EnterInRoomHandler.AddClientInRoom(client, server.GetRoomByName(createRoomData.Name).ID, server); } catch (Exception e) { responseData = new BaseResponseData(RequestTypes.CreateRoom, RequestResult.Error); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); Console.WriteLine("Error {0} - {1}", e.Message, e.StackTrace); } }
/// <summary> /// 返回参数无效的对映信息 /// </summary> /// <param name="controller"></param> /// <param name="jsonRequestBehavior"></param> /// <returns></returns> public static JsonResult JsonParameterInvalidResponse(this Controller controller, JsonRequestBehavior jsonRequestBehavior = JsonRequestBehavior.DenyGet) { var responseData = new BaseResponseData { ErrorCode = ErrorCodeDefine.ParameterRequired, ErrorMessage = Msg.ParamerRequired }; var modelStates = controller.ModelState.Values; if (modelStates != null && modelStates.Any()) { StringBuilder sb = new StringBuilder(); foreach (var item in modelStates) { if (item.Errors != null && item.Errors.Count > 0) { foreach (var errorItem in item.Errors) { sb.AppendFormat("{0},", errorItem.ErrorMessage); } sb = sb.Remove(sb.Length - 1, 1); } sb.AppendLine(); } responseData.ErrorMessage = string.Format("{0}:", Msg.ParamerRequired, sb.ToString()); } JsonResult jsonResult = new JsonResult { Data = responseData, JsonRequestBehavior = jsonRequestBehavior }; return(jsonResult); }
public void DoHandle(byte[] data) { BaseResponseData baseResponseData = Utils.ToObjectFromBytes <BaseResponseData>(data); ListRoomsPanel listRoomsPanel = HGL_WindowManager.I.GetWindow("ListRoomsPanel").GetComponent <ListRoomsPanel>(); listRoomsPanel.Init(Utils.ToObjectFromBytes <List <Room> >((byte[])baseResponseData.GetValue("Rooms"))); HGL_WindowManager.I.OpenWindow(null, null, "ListRoomsPanel", false, true); Debug.Log(string.Format("Response, request type: {0}, result: {1}", baseResponseData.Request, baseResponseData.Result)); }
public void DoHandle(byte[] data) { BaseResponseData baseResponseData = Utils.ToObjectFromBytes <BaseResponseData>(data); string nickname = Convert.ToString(baseResponseData.GetValue("Nickname")); if (!nickname.Equals(SuperChat.I.Client.Nickname)) { GUIManager.I.DrawMessage(new Message(MessageLevel.Info, string.Format("{0} was entered in room", nickname))); } Debug.Log(string.Format("Response, request type: {0}, result: {1}", baseResponseData.Request, baseResponseData.Result)); }
/// <summary> /// 服务器出错返回对映的错误消息 /// </summary> /// <param name="controller"></param> /// <param name="errorMessage">错误信息</param> /// <param name="jsonRequestBehavior"></param> /// <returns></returns> public static JsonResult JsonServerErrorResponse(this Controller controller, string errorMessage = null, JsonRequestBehavior jsonRequestBehavior = JsonRequestBehavior.DenyGet) { var responseData = new BaseResponseData { ErrorCode = ErrorCodeDefine.ServerError, ErrorMessage = errorMessage }; JsonResult jsonResult = new JsonResult { Data = responseData, JsonRequestBehavior = jsonRequestBehavior }; return(jsonResult); }
/// <summary> /// 添加回复信息记录 /// </summary> /// <param name="data">回复实体</param> /// <param name="requestid">回复的请求id</param> /// <param name="responsexml">回复json串</param> /// <returns></returns> public int AddResponseMsgLog(BaseResponseData data, int requestid, string responsexml) { using (var wxdb = new WXDBEntity()) { WX_ResponseMsgLog log = new WX_ResponseMsgLog(); log.ToUserName = data.ToUserName; log.FromUserName = data.FromUserName; log.CreateTime = data.CreateTime; log.MsgType = data.MsgType; log.RequestId = requestid; log.ResponseXML = responsexml; log.CreateDate = DateTime.Now; wxdb.WX_ResponseMsgLog.Add(log); wxdb.SaveChanges(); return(log.Id); } }
public async Task <BaseResponseData> StartJob(JobEntity job) { var result = new BaseResponseData(); if (job.Status != (int)JobStatus.Stop) { result.Message = "任务在停止状态下才能启动"; return(result); } if (job.EndTime.HasValue && job.EndTime < DateTime.Now) { result.Message = "任务结束时间不能小于当前时间"; return(result); } var service = await _loadBalancerFactory.Get().Lease("worker"); if (service == null) { result.Message = "没有可用的worker"; return(result); } var status = await _schedulerRemoting.StartJob(job, service); //更新状态 if (status) { job.Status = (int)JobStatus.Running; job.NodeHost = service.Address; job.NodePort = service.Port; var updatedProperties = new Expression <Func <JobEntity, object> >[] { p => p.Status, p => p.NodeHost, p => p.NodePort }; status = _jobStore.UpdateEntity(job, updatedProperties); result.Success = status; result.Message = result.Success ? "启动成功" : "更新任务状态失败"; return(result); } result.Message = "启动失败"; return(result); }
public static void DoHandle(Client client, byte[] data, Server server) { BaseResponseData responseData = null; try { GetListRoomsData getListRoomsData = Utils.ToObjectFromBytes <GetListRoomsData>(data); responseData = new BaseResponseData(RequestTypes.GetListRooms, RequestResult.Ok); responseData.AddValue("Rooms", Utils.ToByteArray(server.Rooms)); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); } catch (Exception e) { responseData = new BaseResponseData(RequestTypes.GetListRooms, RequestResult.Error); server.SendResponseData(new List <Client>() { client }, (byte)responseData.Request, responseData); Console.WriteLine("Error {0} - {1}", e.Message, e.StackTrace); } }
/// <summary> /// 获取返回给客户端的实体类型 /// </summary> /// <returns></returns> public BaseResponseData GetResponseModel() { switch (msgtype) { case MsgType.text: TextRequestMsg _request = request as TextRequestMsg; if (_request != null) { response = GetLaughResponse(_request); } msgtype = (MsgType)Enum.Parse(typeof(MsgType), response.MsgType); return(response); case MsgType.Event: EventBaseRequestMsg _eventrequest = request as EventBaseRequestMsg; if (_eventrequest != null) { response = GetEventResponst(_eventrequest); } return(response); } return(null); }
/// <summary> /// 获取返回给客户端的xml消息 /// </summary> /// <param name="data">客户请求消息实体</param> /// <param name="msgtype">请求消息类型</param> /// <returns></returns> public string GetResponseXML(BaseResponseData responseModel) { switch (msgtype) { case MsgType.text: TextResponseMsg txtresponse = responseModel as TextResponseMsg; return(txtresponse.ToResponseXml <TextResponseMsg>()); case MsgType.news: Image_TextResponseMsg imgtxtresponse = responseModel as Image_TextResponseMsg; return(imgtxtresponse.ToResponseXml <Image_TextResponseMsg>()); case MsgType.Event: var rq = request as EventBaseRequestMsg; if (rq.Event.Contains("subscribe")) { TextResponseMsg eventresponse = responseModel as TextResponseMsg; return(eventresponse.ToResponseXml <TextResponseMsg>()); } return(null); } return(""); }
public void DoHandle(byte[] data) { BaseResponseData baseResponseData = Utils.ToObjectFromBytes <BaseResponseData>(data); Debug.Log(string.Format("Response, request type: {0}, result: {1}", baseResponseData.Request, baseResponseData.Result)); }
/// <summary> /// 添加回复信息记录 /// </summary> /// <param name="data">回复实体</param> /// <param name="requestid">回复的请求id</param> /// <param name="json">回复json串</param> /// <returns></returns> public int AddResponseMsgLog(BaseResponseData data, int requestid, string responsexml) { //data.CreateTime = WXCommon.formtToDate(data.CreateTime); data.CreateTime = DateTime.Now.ToString(); return(_repository.AddResponseMsgLog(data, requestid, responsexml)); }
public override BaseResponseData <T> ReadJson(JsonReader reader, Type objectType, BaseResponseData <T> existingValue, bool hasExistingValue, JsonSerializer serializer) { if (!hasExistingValue) { existingValue = (BaseResponseData <T>)Activator.CreateInstance(objectType); } var thisObject = JObject.Load(reader); if (thisObject.Count == 2) { //should be able to assume one is "Meta Data" and the other is the data array foreach (var prop in thisObject) { if (prop.Key == "Meta Data") { existingValue.Metadata = prop.Value.ToObject <SparseMetadata>(serializer); } else { existingValue.Data = prop.Value.ToObject <Dictionary <DateTime, T> >(serializer); } } return(existingValue); } if (thisObject.Count == 1 && thisObject.Properties().First().Name == "Information") { throw new AlphaVantageException("Error from AlphaVantage: " + thisObject.Properties().First().Value); } //TODO would I require error handling at this level?? throw new Exception("Expected only 2 top-level properties on a response deserializing to BaseResponseData, but found not 2"); }
public override void WriteJson(JsonWriter writer, BaseResponseData <T> value, JsonSerializer serializer) { throw new NotImplementedException(); }
public static async Task SendMessage(WSResponseMsgID msgId, BaseResponseData result, int roleCount = 1) { var data = await InitHelpers.GetPse().SerializeAsync(result); await SendMessage(msgId, roleCount, data); }