public PayLoad SendPayLoad(PayLoad pl) { if (IsGingerSocketLogging) { GingerSocketLog GSL = new GingerSocketLog(); GSL.LogType = "Send"; GSL.SetPayLoad(pl); GingerSocketLogs.Add(GSL); } try { Stopwatch st = new Stopwatch(); st.Start(); GingerSocket.Send(mNetworkStream, pl); PayLoad plrc = GingerSocket.ReadPayLoad(mClientSocket); st.Stop(); if (IsGingerSocketLogging) { GingerSocketLog GSL = new GingerSocketLog(); GSL.SetPayLoad(plrc); GSL.LogType = "Recv"; GSL.Elapsed = st.ElapsedMilliseconds; GingerSocketLogs.Add(GSL); } return(plrc); } catch (Exception ex) { // Raise event so consumer can show a message or close nicely or retry connect OnMessage(GingerSocket.eProtocolMessageType.CommunicationError, ex.Message); return(PayLoad.Error("Error in SendPayLoad:" + ex.Message)); } }
internal void UpdateObjectFromPayLoad(PayLoad PL, Attribute attr) { List <PropertyInfo> list = GetProperties(attr); //TODO: unpack the Payload and update the obj foreach (PropertyInfo PI in list) { object v = PI.GetValue(mObj); if (PI.PropertyType.IsEnum) { string s = PL.GetValueEnum(); object o = Enum.Parse(PI.PropertyType, s); PI.SetValue(mObj, o); } else if (v is IObservableList) { List <PayLoad> lst = PL.GetListPayLoad(); foreach (PayLoad PL1 in lst) { ObjectReflectionHelper ORH1 = new ObjectReflectionHelper(); ORH1.CreateObjectFromPayLoad(PL1, attr); ((IObservableList)v).Add(ORH1.obj); } } else if (PI.PropertyType.Name == "String") { string s = PL.GetValueString(); PI.SetValue(mObj, s); } else { throw new Exception("Unknown type to handle - " + PI.PropertyType); } } }
internal static void Send(System.Net.Sockets.NetworkStream ns, PayLoad pl) { byte[] b = pl.GetPackage(); ns.Write(b, 0, b.Length); ns.Flush(); }
private void SendMessage(TcpClient tcpClient, PayLoad PL) { NetworkStream clientStream = tcpClient.GetStream(); GingerSocket.Send(clientStream, PL); }
private PayLoad ProcessMessage(PayLoad PL) { PayLoad PLRC = OnMessage(GingerSocket.eProtocolMessageType.PayLoad, PL); return(PLRC); }