Example #1
0
 internal bool Load(IEnumerable <WSTableSource> role_sources)
 {
     if (!Fields.Any())
     {
         return(false);
     }
     else
     {
         foreach (WSEntityFieldSchema schema in Fields.OfType <WSEntityFieldSchema>())
         {
             Type eType = schema.param.DataType.GetEntityType();
             schema.SOURCE = role_sources.FirstOrDefault(x => x.ReturnType == eType);
         }
         List <string> illegalFields = Fields.OfType <WSEntityFieldSchema>().Where(x => x.SOURCE == null).Select(x => x.param.WSColumnRef.NAME).ToList();
         if (illegalFields != null && illegalFields.Any())
         {
             foreach (string field in illegalFields)
             {
                 WSMemberSchema schema = Fields.FirstOrDefault(f => ((WSFieldSchema)f).param.WSColumnRef.NAME.Equals(field));
                 if (schema != null)
                 {
                     Fields.Remove(schema);
                 }
             }
         }
         return(Fields.Any());
     }
 }
Example #2
0
        private bool saveFieldSchema(WSMemberSchema field, bool replace, ref WSFieldFilters filters)
        {
            if (field != null)
            {
                Func <WSMemberSchema, bool> func = x => x is WSFieldSchema && ((WSFieldSchema)x).param.Match(field.Name);
                if (!filters.Any(func))
                {
                    filters.Add(field);
                }
                else
                {
                    if (replace)
                    {
                        /*  TODO@ANDVO : 2016-03-08 : combine redundant field's options somehow,... (when field used more than once in schema)
                         *   fx.: 'userid:{less:10}&schema={user:[*,{userid:{more:1}}]}'
                         *   note: ofcourse we can combine them like: 'schema={user:[*,{userid:{less:10,more:1}}]}',
                         *   but what if there will be need for option's separation as : AND <-> OR?
                         */

                        filters[filters.IndexOf(filters.FirstOrDefault(func))] = field;
                    }
                }
                return(true);
            }
            return(false);
        }
Example #3
0
        private List <WSMemberSchema> readFieldSchema(WSJProperty json, out bool replace)// json => WSJValue || WSJProperty || WSJObject
        {
            replace = true;
            List <WSMemberSchema> fSchema = new List <WSMemberSchema>();

            try
            {
                if (json != null && Source != null)
                {
                    if (!string.IsNullOrEmpty(json.Key))
                    {
                        WSTableParam param = (WSTableParam)Source.GetXParam(json.Key);
                        if (param != null && param.isValid)
                        {
                            replace = true;
                            if (param.DataType.IsSimple() || param.DataType.IsSimpleCollection())
                            {
                                fSchema.Add(new WSPrimitiveFieldSchema(Func, param, json, this));
                            }
                            else if (json.IsValid)
                            {
                                WSTableSource source = (WSTableSource)Func.GetSourceByType(param.DataType.GetEntityType());
                                if (source != null)
                                {
                                    if (param.Match(json.Key))
                                    {
                                        if (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)))
                                        {
                                            fSchema.Add(new WSEntitySchema(source, json, Func, this));
                                        }
                                        else if (param.DataType.IsCollectionOf <WSEntity>())
                                        {
                                            fSchema.Add(new WSEntityListSchema(param, json, Func, this));
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            #region SET '*' [ALL PRIMITIVE FIELDS] Filter
                            if (WSConstants.ALIACES.ALL_PRIMITIVE_FIELDS.Match(json.Key))
                            {
                                replace = false;

                                IEnumerable <WSTableParam> DBPrimitiveParams =
                                    Source.DBPrimitiveParams.Any() ?
                                    Source.DBPrimitiveParams.Where(x => Func.IsAccessible(x.READ_ACCESS_MODE.ACCESS_LEVEL)) :
                                    new List <WSTableParam>();
                                IEnumerable <WSJValue> all_primitive_params =
                                    DBPrimitiveParams.Any() ?
                                    DBPrimitiveParams.Select(x => new WSJValue(x.DISPLAY_NAME)) :
                                    new List <WSJValue>();

                                foreach (WSJValue _item in all_primitive_params)
                                {
                                    WSMemberSchema schema = Source.BaseSchema.Fields.FirstOrDefault(x => x.Name.Equals(_item.Value));
                                    if (schema != null)
                                    {
                                        fSchema.Add(schema);
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); Func.RegError(GetType(), e, ref status); }
            return(fSchema);
        }