コード例 #1
0
        public IResponse <T> Deserialize <T>(DataPacket item) where T : class, new()
        {
            Message <T> data = null;

            if (item != null)
            {
                data = new Message <T>(item.Items);
                switch (item.ModelAction)
                {
                case ModelActionOption.None:
                    break;

                case ModelActionOption.Post:
                case ModelActionOption.Put:
                case ModelActionOption.Get:
                    if (item.Buffer != null)
                    {
                        data.Content = new List <T>();
                        data.Content.Add(GenericSerializer.ByteArrayToGenericItem <T>(item.Buffer));
                    }
                    break;

                case ModelActionOption.Delete:
                    break;

                case ModelActionOption.GetAll:
                    if (item.Buffer != null)
                    {
                        data.Content = GenericSerializer.ByteArrayToGenericItem <List <T> >(item.Buffer);
                    }
                    break;

                case ModelActionOption.GetAllProjections:
                    if (item.Buffer != null)
                    {
                        //TODO  FIX THIS
                        //data.Display = GenericSerializer.ByteArrayToGenericItem<List<Projection>>(item.Buffer);
                    }
                    break;

                case ModelActionOption.ExecuteAction:
                    break;

                case ModelActionOption.ExecuteCommand:
                    if (item.Tables != null)
                    {
                        data.Data = item.Tables;
                    }
                    break;

                case ModelActionOption.ExecuteMany:
                    break;

                default:
                    break;
                }
            }
            else
            {
                data = new Message <T>(new List <TypedItem>());
            }
            if (item != null && !item.IsOkay)
            {
                data.SetError(500, item.ErrorMessage);
            }

            return(data as IResponse <T>);
        }