private void _client_MessageReceived(byte[] obj) { IXPFile ixp = new IXPFile(Encoding.UTF8.GetString(obj)); if (!ixp.NetworkFunction.Equals(_request.NetworkFunction)) return; _received = true; _responseDelegate(ixp.GetInfoValue("Response")); }
private void UpdarteTime(IXPFile file) { Invoke((MethodInvoker)delegate { lblCurTime.Text = String.Format("{0:00}:{1:00}:{2:00}", int.Parse(file.GetInfoValue("hours")), int.Parse(file.GetInfoValue("minutes")), int.Parse(file.GetInfoValue("seconds"))); }); }
private void CallAlarm(IXPFile file) { int id = int.Parse(file.GetInfoValue("alarm_id")); Alarm a = _alarms.FirstOrDefault(al => al.ID == id); MessageBox.Show("ALARM: " + a.Name); }
private static void HandleMessage(ServerInstance arg1, string message) { IXPFile ixp = new IXPFile(message); FunctionInfo nfunc = _networkFunctions.FirstOrDefault(nf => nf.Name.Equals(ixp.NetworkFunction)); if (nfunc != null) Debug.Log(_debugChannel, "Function: " + ixp.NetworkFunction); else { Debug.Log(_debugChannel, "Function: Unknown"); return; } Dictionary<string, object> dicParams = new Dictionary<string, object>(); foreach (string param in nfunc.Parameters) { if (ixp.GetInfoValue(param) == null && nfunc.GetParameterType(param) != typeof(ServerInstance)) { Debug.Log(_debugChannel, "Missing parameter: " + param); return; } object paramVal = null; Type t = nfunc.GetParameterType(param); if (t == typeof(ServerInstance)) { paramVal = arg1; } else { string strVal = ixp.GetInfoValue(param); if (t == typeof(string)) { paramVal = strVal; } else if (t == typeof(int)) { int i = -1; bool s = int.TryParse(strVal, out i); if (s) paramVal = i; } else if(t == typeof(byte)) { byte b = 0; bool s = byte.TryParse(strVal, out b); if (s) paramVal = b; } else if(t == typeof(ushort)){ ushort us = 0; bool s = ushort.TryParse(strVal, out us); if (s) paramVal = us; } else if (t == typeof(bool)) { if (strVal.Equals("TRUE")) paramVal = true; else if (strVal.Equals("FALSE")) paramVal = false; } if (paramVal == null) { Debug.Log(_debugChannel, "Invalid type for param " + param + ". Expected " + t.ToString() + ". Got Value: " + strVal); return; } } dicParams.Add(param, paramVal); } if (nfunc.ReturnType == typeof(void)) nfunc.Invoke(dicParams); else if (nfunc.ReturnType == typeof(IXPFile)) { IXPFile file = (IXPFile)nfunc.Invoke(dicParams); arg1.Send(Encoding.UTF8.GetBytes(file.XML)); } else { object response = nfunc.Invoke(dicParams); IXPFile iresponse = new IXPFile(); iresponse.NetworkFunction = ixp.NetworkFunction; iresponse.PutInfo("Response", response.ToString()); arg1.Send(Encoding.UTF8.GetBytes(iresponse.XML)); } }
private static void SimpleRequest_Client_MessageReceived(byte[] obj) { IXPFile response = new IXPFile(Encoding.UTF8.GetString(obj)); if (!response.NetworkFunction.Equals(_simpleRequestRequest)) return; _simpleRequestResponse = response.GetInfoValue("Response"); }