示例#1
0
        // Create an Object based on the Payload and set the obj value for properoties which have requested attr
        public void CreateObjectFromPayLoad(PayLoad PL, Attribute attr)
        {
            string       cls = PL.GetValueString();
            ObjectHandle OH  = Activator.CreateInstance("GingerCore", cls);

            mObj = OH.Unwrap();

            UpdateObjectFromPayLoad(PL, attr);
        }
示例#2
0
        public void HandleClientComm(object client)
        {
            TcpClient tcpClient = (TcpClient)client;

            // TODO: need to decide when to go out of the loop !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            while (true)
            {
                try
                {
                    PayLoad PL = GingerSocket.ReadPayLoad(tcpClient);
                    if (PL.Name == "GingerSocket")
                    {
                        // This is Client/Server Protocol talks
                        string txt = PL.GetValueString();
                        if (txt == "Disconnect")
                        {
                            tcpClient.Close();
                            break;
                        }
                    }
                    else
                    {
                        PayLoad PLRC = ProcessMessage(PL);
                        if (PLRC != null)  // if async then it will be null? or we must return something, for async we should return start processing - or key id of req to pair later
                        {
                            SendMessage(tcpClient, PLRC);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //TODO: handle
                    // Client cut the connection or some err
                    //a socket error has occurred
                    // or any other server err
                    PayLoad PLErr = PayLoad.Error("Error - " + ex.Message);
                    SendMessage(tcpClient, PLErr);
                }
            }
            tcpClient.Close();
        }
示例#3
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);
                }
            }
        }