public static List<string> GetTreeData(string name, int number, string description) { Request request = new Request("GetTreeData"); request.AddParameter(new Parameter("name", name)); request.AddParameter(new Parameter("number", number)); request.AddParameter(new Parameter("description", description)); RPCWrapper.SendMethodRequest(request); Response response = RPCWrapper.ReceiveMethodResponse(); Parameter p = null; foreach (Parameter item in response.Parameters) { if (item.Direction == Direction.Return) { p = item; break; } } List<string> result = p.Value as List<string>; return result; }
public static Request Parse(XmlElement request) { if (request == null) { return null; } if (request.HasAttribute("Type")) { string type = request.GetAttribute("Type"); if (type != Const.REQUEST) { throw new Exception("method type error!"); } } else { throw new Exception("method format error!"); } Request result = null; if (request.HasAttribute("Name")) { string name = request.GetAttribute("Name"); result = new Request(name); } else { throw new Exception("method format error!"); } if (request.HasAttribute("Sequence")) { string sequence = request.GetAttribute("Sequence"); result.Sequence = (sequence.ToLower() == "true" ? true : false); } else { throw new Exception("method format error!"); } XmlNode parameterRoot = request.SelectSingleNode("Parameter"); if (parameterRoot != null) { XmlNodeList parameters = parameterRoot.ChildNodes; foreach (XmlNode parameter in parameters) { Parameter p = Parameter.Parse(parameter as XmlElement); result.AddParameter(p); } } return result; }
public static void SendMethodRequest(Request request) { Message msg = new Message(); msg.Type = MessageType.chat; msg.To = server; msg.Body = request.ToString(); RPCWrapper.con.Send(msg); method = request.Name; response = null; autoEvent.Reset(); }
private static Response HandleRequest(Request request) { Response response = null; switch (request.Name) { case "GetTreeData": response = MethodWrapper.GetTreeData(request); break; default: break; } return response; }
public static Response GetTreeData(Request request) { string name = request.FindParameter("name").Value as string; int number = (int)request.FindParameter("number").Value; string description = request.FindParameter("description").Value as string; Response response = new Response("GetTreeData"); List<string> result = new List<string>(); for(int i = 0 ; i < number; i ++) { result.Add(i.ToString().PadLeft(20, '0')); } ListDAO data = new ListDAO(BasicType.String.ToString(), result); response.AddParameter(new Parameter(Direction.Return, "return", data)); return response; }