示例#1
0
        private object getMemberValue(WSEntity entity, WSParam eParam, MetaFunctions CFunc)
        {
            WSTableSource            xSource  = (WSTableSource)CFunc.GetSourceByType(entity.GetType());
            IEnumerable <MemberInfo> eMembers = xSource.ReturnType.GetMembers().Where(m => m is PropertyInfo || m is FieldInfo);
            MemberInfo eField = eMembers.FirstOrDefault(m => eParam.Match(m.Name));

            return(eField is PropertyInfo ? ((PropertyInfo)eField).GetValue(entity, null) : eField is FieldInfo ? ((FieldInfo)eField).GetValue(entity) : null);
        }
示例#2
0
 public WSRecord(MetaFunctions _CFunc, WSEntity _entity, byte _role, WSSchema _schema, WSParamList _outFields = null, string _Name = null)
 {
     CFunc     = _CFunc;
     Name      = string.IsNullOrEmpty(_Name) ? GetType().Name : _Name;
     schema    = _schema;
     outFields = _outFields;
     entity    = _entity;
     role      = _role;
 }
示例#3
0
        private WSStatus WriteCollapsedValues(JsonWriter writer, JsonSerializer serializer, WSEntity entity, WSSource xSource, WSJson collapseOption, WSRequest Request, MetaFunctions CFunc)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                /*******************************************************************************
                 *
                 * //  TODO @ANDVO : 2016-02-15 : IMPORTANT!!! => Implement security check like this :
                 *
                 * WSStatus status = Validate(obj, xParam, writer, serializer, security, schema);
                 * if (status.CODE == WSStatus.SUCCESS.CODE)
                 * {
                 */

                if (entity != null && collapseOption != null && collapseOption.IsValid)
                {
                    WSTableSource childSource = (WSTableSource)CFunc.GetSourceByType(entity.GetType());

                    object  fieldValue = null;
                    WSParam field      = null;
                    if (collapseOption is WSJValue)
                    {
                        string fieldName = ((WSJValue)collapseOption).Value;
                        field      = entity.GetParam(xSource, fieldName);
                        fieldValue = getMemberValue(entity, field, CFunc);

                        WSPrimitiveFieldSchema fieldSchema = new WSPrimitiveFieldSchema(CFunc, (WSTableParam)field, new WSJProperty(fieldName, new WSJArray()), /*((WSTableSource)entity.getSource())*/ childSource.BaseSchema);
                        if (Validate(fieldValue, field, writer, serializer, childSource.BaseSchema, childSource, null, ref status, Request, CFunc))
                        {
                            object _obj = null;
                            serializer.Serialize(writer, field.TryReadPrimitiveWithDefault(fieldValue, string.Empty, out _obj) ? _obj : string.Empty);
                            writer.Flush();
                            status = WSStatus.SUCCESS_Copy();
                        }
                    }
                    else if (collapseOption is WSJObject)
                    {
                        WSJProperty collapseSrc = ((WSJObject)collapseOption).Value.FirstOrDefault();
                        field      = entity.GetParam(childSource, collapseSrc.Key);
                        fieldValue = getMemberValue(entity, field, CFunc);
                        if (Validate(fieldValue, field, writer, serializer, childSource.BaseSchema, childSource, null, ref status, Request, CFunc))
                        {
                            if (fieldValue == null)
                            {
                                serializer.Serialize(writer, "NULL");
                                writer.Flush();
                            }
                            else if (fieldValue is WSEntity)
                            {
                                WSTableSource fieldSource = (WSTableSource)CFunc.GetSourceByType(fieldValue.GetType());
                                status = WriteCollapsedValues(writer, serializer, (WSEntity)fieldValue, fieldSource, collapseSrc.Value, Request, CFunc);
                            }
                            else if (fieldValue.IsCollectionOf <WSEntity>())
                            {
                                WSTableSource fieldSource = (WSTableSource)CFunc.GetSourceByType(fieldValue.GetType().GetEntityType());
                                if (!((IEnumerable <WSEntity>)fieldValue).Any())
                                {
                                    serializer.Serialize(writer, "NULL");
                                    writer.Flush();
                                }
                                else
                                {
                                    foreach (WSEntity eItem in (IEnumerable <WSEntity>)fieldValue)
                                    {
                                        status.childs.Add(WriteCollapsedValues(writer, serializer, eItem, fieldSource, collapseSrc.Value, Request, CFunc));
                                    }
                                    status = status.IsPositive ? WSStatus.SUCCESS_Copy() : WSStatus.ERROR_Copy();
                                }
                            }
                        }
                    }
                }


                /*}
                 *
                 *******************************************************************************/
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref status); }
            return(status);
        }