public static Response Parse(XmlElement response) { if (response == null) { return null; } if (response.HasAttribute("Type")) { string type = response.GetAttribute("Type"); if (type != Const.REPONSE) { throw new Exception("method type error!"); } } else { throw new Exception("method format error!"); } Response result = null; if (response.HasAttribute("Name")) { string name = response.GetAttribute("Name"); result = new Response(name); } else { throw new Exception("method format error!"); } if (response.HasAttribute("Sequence")) { string sequence = response.GetAttribute("Sequence"); result.Sequence = (sequence.ToLower() == "true" ? true : false); } else { throw new Exception("method format error!"); } XmlNode parameterRoot = response.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(); }
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; }
static void OnMessage(object sender, Message msg) { if (msg.Body == null) { return; } if (msg.FirstChild == null) { return; } XmlDocument doc = new XmlDocument(); doc.LoadXml(msg.FirstChild.InnerXml); XmlElement root = doc.DocumentElement; string name = root.Name; if (name == Const.METHOD) { if (!root.HasAttribute("Type")) { return; } string type = root.GetAttribute("Type"); if (type != Const.REPONSE) { return; } response = Response.Parse(root); if (response == null) { return; } if (response.Name != method) { return; } autoEvent.Set(); } else if (name == Const.INFORM) { } else { } }