示例#1
0
        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));
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
 internal static void Send(System.Net.Sockets.NetworkStream ns, PayLoad pl)
 {
     byte[] b = pl.GetPackage();
     ns.Write(b, 0, b.Length);
     ns.Flush();
 }
示例#4
0
        private void SendMessage(TcpClient tcpClient, PayLoad PL)
        {
            NetworkStream clientStream = tcpClient.GetStream();

            GingerSocket.Send(clientStream, PL);
        }
示例#5
0
        private PayLoad ProcessMessage(PayLoad PL)
        {
            PayLoad PLRC = OnMessage(GingerSocket.eProtocolMessageType.PayLoad, PL);

            return(PLRC);
        }