示例#1
0
        public override bool MatchEntity(MetaFunctions CFunc, WSDynamicEntity entity, WSTableSource src, string key = null, string matchOperation = null)
        {
            bool _match = true;//insure that the empty array gives true

            try
            {
                foreach (WSJson jItem in Value)
                {
                    _match = false;//insure that the NOT empty array gives false on failure
                    if (jItem is WSJValue && !string.IsNullOrEmpty(key))
                    {
                        _match = ((WSJValue)jItem).MatchEntity(CFunc, entity, src, key, WSFieldFilter.GLOBAL_OPERATIONS.Equal.NAME);
                    }
                    else if (jItem is WSJObject)
                    {
                        _match = ((WSJObject)jItem).MatchEntity(CFunc, entity, src, key);
                    }
                    else if (jItem is WSJArray)
                    {
                        _match = ((WSJArray)jItem).MatchEntity(CFunc, entity, src, key);
                    }
                    if (_match)
                    {
                        break;
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(_match);
        }
示例#2
0
 internal WSJObject getBaseJson(byte UserRole)
 {
     if (Source != null && !Source.IsBase)
     {
         WSJArray    jFields = new WSJArray();
         WSJProperty jProp   = new WSJProperty(Name.ToLower(), jFields);
         WSJObject   json    = new WSJObject(new List <WSJProperty> {
             jProp
         });
         try
         {
             if (Fields != null && Fields.Any())
             {
                 IEnumerable <WSMemberSchema> acessibleSchemaes = Fields
                                                                  .Where(x => x is WSPrimitiveFieldSchema && UserRole >= ((WSPrimitiveFieldSchema)x).param.READ_ACCESS_MODE.ACCESS_LEVEL);
                 if (acessibleSchemaes != null && acessibleSchemaes.Any())
                 {
                     IEnumerable <WSJson> _fields = acessibleSchemaes.Select(f => new WSJValue(((WSPrimitiveFieldSchema)f).param.DISPLAY_NAME.ToLower()));
                     jFields.Value = _fields != null && _fields.Any(x => x != null) ? _fields.Where(x => x != null).ToList() : new List <WSJson>();
                 }
             }
         }
         catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); Func.RegError(GetType(), e, ref status); }
         return(json);
     }
     return(null);
 }
示例#3
0
 private List <dynamic> readEntity(MetaFunctions CFunc, WSJProperty jProp, WSDynamicEntity _entity, bool multydimentional = false)
 {
     try
     {
         if (_entity != null)
         {
             WSTableSource src   = (WSTableSource)_entity.getSource(CFunc);
             WSTableParam  param = src.DBParams.FirstOrDefault(p => p.Match(jProp.Key));
             PropertyInfo  pInfo = src.ReturnType.GetProperties().FirstOrDefault(p => p.Name.Equals(param.WSColumnRef.NAME));
             dynamic       val   = pInfo.GetValue(_entity, null);
             Type          pType = pInfo.PropertyType.GetEntityType();
             if (pInfo.PropertyType.IsCollectionOf <WSDynamicEntity>())
             {
                 IEnumerable <WSDynamicEntity> entities = (IEnumerable <WSDynamicEntity>)val;
                 List <dynamic> subItems = new List <dynamic>();
                 foreach (WSDynamicEntity iEntity in entities)
                 {
                     subItems.AddRange(read(CFunc, jProp.Value, iEntity, multydimentional));
                 }
                 return(subItems);
             }
             else
             {
                 return(read(CFunc, jProp.Value, val, multydimentional));
             }
         }
     }
     catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status, $"readEntity():284"); }
     return(null);
 }
示例#4
0
        public WSStatus WriteJson(JsonWriter writer, JsonSerializer serializer, List <Type> printedTypes, WSRequest Request, MetaFunctions CFunc, WSDataContext DBContext)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                if (entity == null)
                {
                    status.CODE = WSStatus.ERROR.CODE;
                    status.AddNote("WSEntity not known", WSConstants.ACCESS_LEVEL.READ);
                }
                else
                {
                    List <Type> postPrintedTypes = printedTypes.Select(x => x).ToList();
                    postPrintedTypes.Add(entity.GetType());

                    if (entity != null)
                    {
                        status.childs.Add(entity.WriteJson(writer, serializer, schema, outFields, postPrintedTypes, Request, CFunc, DBContext));
                    }
                }
            }
            catch (Exception e) {
                CFunc.RegError(GetType(), e, ref status);
                status.CODE = WSStatus.ERROR.CODE;
                status.AddNote("Error(line" + e.LineNumber() + "- " + e.Message + ")");
            }
            return(status);
        }
示例#5
0
 private void parseBaseParam(WSTableParam param, IEnumerable <WSTableSource> sources = null)
 {
     try
     {
         if (param == null)
         {
         }
         else
         {
             bool isValidFields = (Fields == null || !Fields.Any(x => x is WSFieldSchema && ((WSFieldSchema)x).param.Match(param.NAME, sources)));
             if (!isValidFields)
             {
             }
             else
             {
                 if (param.DataType.IsSimple() || param.DataType.IsSimpleCollection())
                 {
                     Fields.Add(new WSPrimitiveFieldSchema(Func, param, new WSJProperty(param.DISPLAY_NAME.ToLower(), new WSJArray()), this));
                 }
                 else
                 {
                     Fields.Add(new WSEntityFieldSchema(Func, param, new WSJProperty(param.DISPLAY_NAME.ToLower(), new WSJArray()), this));
                 }
             }
         }
     }
     catch (Exception e) { Failed = true; WSStatus status = WSStatus.NONE.clone(); Func.RegError(GetType(), e, ref status); }
 }
        public override WSFilter GetCustomFilter(Expression parent, int level)
        {
            try
            {
                if (parent != null && IsFiltrable && EntitySchema != null)
                {
                    level++;
                    Expression member = Expression.Property(parent, Param.WSColumnRef.NAME);
                    if (member != null)
                    {
                        ParameterExpression id = Expression.Parameter(EntitySchema.Source.ReturnType, level.ToHex());

                        WSFilter subFilter = EntitySchema.GetCustomFilter(id, level);

                        if (subFilter != null && subFilter.IsValid)
                        {
                            dynamic subExpr = subFilter.GetType().GetMethod("ToLambda").MakeGenericMethod(new Type[] { EntitySchema.Source.ReturnType }).Invoke(subFilter, new object[] { id });

                            return(new WSEntityListFFilter(Param, member, WSEntityListFFilter.OPERATIONS.Any)
                            {
                                Value = (subExpr == null) ? true : subExpr
                            });
                        }
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); Func.RegError(GetType(), e, ref status); }
            return(null);
        }
示例#7
0
 public override bool Match(WSJson json, out WSStatus status)
 {
     status = WSStatus.NONE_Copy();
     try
     {
         if (json == null)
         {
             status = WSStatus.ERROR_Copy(); return(false);
         }
         else if (!(json is WSJArray))
         {
             status = WSStatus.ERROR_Copy(); return(false);
         }
         else
         {
             WSJProperty jProp1 = (WSJProperty)json;
             if (!Key.Equals(jProp1.Key))
             {
                 status = WSStatus.ERROR_Copy();
                 status.AddNote($"Keys not match:[{Key}<->{jProp1.Key}]");
             }
             else
             {
                 status = Value.Match(jProp1.Value, out status) ? WSStatus.SUCCESS_Copy() : status;
             }
         }
     }
     catch (Exception) { }
     return(status.CODE == WSStatus.SUCCESS.CODE);
 }
示例#8
0
        private WSStatus WriteJMembers(IEnumerable <MemberInfo> members, JsonWriter writer, JsonSerializer serializer, WSEntitySchema eSchema, WSSource xSource, WSParamList outFields, List <Type> printedTypes, WSRequest Request, MetaFunctions CFunc, WSDataContext DBContext)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                Type    eType = GetType();
                object  obj   = null;
                WSParam param = null;
                if (this is WSDynamicEntity)
                {
                    foreach (WSSchema fieldSchema in eSchema.Fields /*.Items*/)
                    {
                        if (fieldSchema is WSFieldSchema)
                        {
                            param = ((WSFieldSchema)fieldSchema).param;
                        }
                        else if (fieldSchema is WSEntityBaseSchema)
                        {
                            param = GetParam(xSource, fieldSchema.Name);
                        }
                        //else if (childSchema is WSEntitySchema) { param = GetParam(childSchema.Name); }
                        //else if (childSchema is WSEntityListSchema) { param = GetParam(((WSEntityListSchema)childSchema).EntitySchema.Name); }

                        MemberInfo member = param == null ? null : members.FirstOrDefault(p => param.Match(p.Name, null, null, false));
                        obj = member == null ? null : member is PropertyInfo ? ((PropertyInfo)member).GetValue(this, null) : member is FieldInfo ? ((FieldInfo)member).GetValue(this) : null;

                        if (param != null)
                        {
                            status.childs.Add(WriteJProperty(obj, param, writer, serializer, fieldSchema, xSource, outFields, printedTypes, Request, CFunc, DBContext));
                        }
                    }
                }
                else if (this is WSStaticEntity)
                {
                    foreach (MemberInfo member in members)
                    {
                        param = GetParam(xSource, member.Name, member.ReflectedType);
                        obj   = member is PropertyInfo ? ((PropertyInfo)member).GetValue(this, null) : member is FieldInfo ? ((FieldInfo)member).GetValue(this) : null;

                        if (param != null)
                        {
                            status.childs.Add(WriteJProperty(obj, param, writer, serializer, null, xSource, outFields, printedTypes, Request, CFunc, DBContext));
                        }
                    }
                }

                status.AddNote("done", WSConstants.ACCESS_LEVEL.READ);
            }
            catch (Exception e)
            {
                status.CODE = WSStatus.ERROR.CODE;
                status.AddNote("Error(line" + e.LineNumber() + "- " + e.Message + ")");
                CFunc.RegError(GetType(), e, ref status);
            }
            return(status);
        }
示例#9
0
 public override bool Match(WSJson json, out WSStatus status)
 {
     status = json != null && json is WSJValue && Value.Equals(((WSJValue)json).Value) ? WSStatus.SUCCESS_Copy() : WSStatus.ERROR_Copy();
     if (status.CODE != WSStatus.SUCCESS.CODE)
     {
         status.AddNote($"Values not match:[{{current:{Value}}}<->{{original:{((WSJValue)json).Value}}}]");
         return(false);
     }
     return(true);
 }
示例#10
0
 public WSEntitySchema(WSTableSource _Source, WSJProperty _Json, MetaFunctions _Func, WSEntitySchema _Parent = null, bool _IsValidSchema = true) : base(_Func, _Parent)
 {
     try
     {
         IsValidSchema = _IsValidSchema;
         Source        = _Source;
         setUp(_Json);
     }
     catch (Exception e) { Failed = true; WSStatus status = WSStatus.NONE.clone(); Func.RegError(GetType(), e, ref status); }
 }
示例#11
0
 public override WSFilter GetOptionFilter(MetaFunctions CFunc, Expression parent, int level, string state = null, bool?negate = null)
 {
     try
     {
         WSCombineFilter filter = new WSCombineFilter(WSCombineFilter.SQLMode.OrElse, negate);
         filter.SaveRange(Value.Select(x => x.GetOptionFilter(CFunc, parent, level, state, null)).ToList());
         return(filter.Any() ? (filter.Count == 1 && !filter.Negate) ? filter.FirstOrDefault() : filter : null);
     }
     catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
     return(null);
 }
示例#12
0
 public override WSFilter GetFieldFilter(MetaFunctions CFunc, WSTableParam param, Expression parent, int level, string state = null, bool?negate = null)
 {
     try
     {
         WSCombineFilter filter = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso);
         filter.SaveRange(Value.Select(x => x.GetFieldFilter(CFunc, param, parent, level, state, negate)).ToList()); /*DONT FORVARD 'negate' parameter to avoid complicatency*/
         return(filter.Any() ? (filter.Count == 1 && !filter.Negate) ? filter.FirstOrDefault() : filter : null);
     }
     catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
     return(null);
 }
示例#13
0
 public static void Add(this List <WSStatus> list, string text)
 {
     try
     {
         if (list != null)
         {
             WSStatus status = WSStatus.NONE_Copy(); status.AddNote(text); list.Add(status);
         }
     }
     catch (Exception) { }
 }
示例#14
0
        public override string ToString()
        {
            string text = base.ToString();

            try { text = string.Format("[Count:{0}]", Count); }
            catch (Exception e) {
                text = e.Message;
                WSStatus status = WSStatus.NONE.clone();
                Func.RegError(GetType(), e, ref status);
            }
            return(text);
        }
示例#15
0
 internal override bool applyInternal(WSRequest Request, MetaFunctions CFunc)
 {
     try
     {
         foreach (WSJProperty prop in Value)
         {
             prop.apply(Request, CFunc);
         }
         return(true);
     } catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
     return(false);
 }
示例#16
0
        public override bool Match(WSJson json, out WSStatus status)
        {
            status = WSStatus.NONE_Copy();
            try
            {
                if (json == null)
                {
                    status = WSStatus.ERROR_Copy(); return(false);
                }
                else if (!(json is WSJObject))
                {
                    status = WSStatus.ERROR_Copy(); return(false);
                }
                else
                {
                    WSJObject            jObj  = (WSJObject)json;
                    IEnumerable <string> keys  = Value.Select(v1 => v1.Key);
                    IEnumerable <string> keys1 = jObj.Value.Select(v1 => v1.Key);
                    if (keys1.Any(p1 => !keys.Any(p => p1.Equals(p))))
                    {
                        status = WSStatus.ERROR_Copy();
                        status.AddNote($"An original service generates response with additional properties:[{keys1.Where(p1 => !keys.Any(p => p1.Equals(p))).Aggregate((a,b)=>a+","+b)}] which is not exists in current object.");
                    }
                    else if (keys.Count() != keys1.Count())
                    {
                        status = WSStatus.ERROR_Copy();
                        status.AddNote($"The current service generates response with additional properties:[{keys.Where(p1 => !keys1.Any(p => p1.Equals(p))).Aggregate((a, b) => a + "," + b)}] which is not exists in original object.");
                    }
                    else
                    {
                        foreach (WSJProperty jProp1 in jObj.Value)
                        {
                            WSJProperty jProp = Value.FirstOrDefault(x => x.Key.Equals(jProp1.Key));

                            WSStatus pStatus = jProp.Match(jProp1, out pStatus) ? WSStatus.SUCCESS_Copy() : pStatus;

                            status = pStatus;

                            if (pStatus.CODE != WSStatus.SUCCESS.CODE)
                            {
                                return(false);
                            }
                        }
                        return(!status.childs.Any(x => x.CODE != WSStatus.SUCCESS.CODE));
                    }
                }
            }
            catch (Exception) { }
            return(status.CODE == WSStatus.SUCCESS.CODE);
        }
示例#17
0
        public List <dynamic> read(MetaFunctions CFunc, WSJson json, WSDynamicEntity _entity = null, bool multydimentional = false)
        {
            List <dynamic> result = new List <dynamic>();

            try
            {
                _entity = _entity == null ? this : _entity;
                if (json is WSJValue)
                {
                    dynamic val = readPrimitive(CFunc, (WSJValue)json, _entity); if (val != null)
                    {
                        result.Add(val);
                    }
                }
                else if (json is WSJArray)
                {
                    foreach (WSJson item in ((WSJArray)json).Value)
                    {
                        List <dynamic> val = read(CFunc, item, _entity, multydimentional);
                        if (multydimentional)
                        {
                            result.Add(val);
                        }
                        else
                        {
                            result.AddRange(val);
                        }
                    }
                }
                else if (json is WSJObject)
                {
                    List <dynamic> val = readEntity(CFunc, ((WSJObject)json).Value[0], _entity, multydimentional);
                    if (val != null && val.Any())
                    {
                        if (multydimentional)
                        {
                            result.Add(val);
                        }
                        else
                        {
                            result.AddRange(val);
                        }
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status, $"read():357"); }
            return(result);
        }
示例#18
0
 private dynamic readPrimitive(MetaFunctions CFunc, WSJValue jVal, WSDynamicEntity _entity)
 {
     try
     {
         if (_entity != null)
         {
             Type          eType = _entity.GetType();
             WSTableSource src   = ((WSTableSource)CFunc.GetSourceByType(eType));
             WSTableParam  param = src.DBParams.FirstOrDefault(p => p.Match(jVal.Value));
             PropertyInfo  pInfo = eType.GetProperties().FirstOrDefault(p => p.Name.Equals(param.WSColumnRef.NAME));
             return(pInfo.GetValue(_entity, null));
         }
     }
     catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status, $"readPrimitive():373"); }
     return(null);
 }
示例#19
0
 public WSResponse(WSClientMeta _meta)
 {
     meta = _meta;
     if (meta.Request != null && meta.Request.Security != null)
     {
         if (meta.Request.Security.IsLogged && meta.Request.Security.AuthToken.User.role != iostatus.CODE)
         {
             iostatus = WSStatus.NONE.clone(meta.Request.Security.AuthToken.User.role);
         }
         init();
     }
     else
     {
         iostatus = WSStatus.NONE.clone(WSConstants.ACCESS_LEVEL.READ);
     }
 }
示例#20
0
        private bool Match(ClientFunctions CFunc, WSDynamicEntity refEntity)
        {
            try
            {
                if (refEntity == null)
                {
                    return(false);
                }
                else if (refEntity.GetType() != GetType())
                {
                    return(false);
                }
                else
                {
                    Type          orgType = GetType();
                    WSTableSource orgSrc  = (WSTableSource)getSource(CFunc);
                    IEnumerable <WSTableParam> orgParams = orgSrc.DBParams.Where(p => p.DataType.IsSimple());

                    Type          refType = refEntity.GetType();
                    WSTableSource refSrc  = ((WSTableSource)CFunc.GetSourceByType(refType));
                    IEnumerable <WSTableParam> refParams = refSrc.DBParams.Where(p => p.DataType.IsSimple());

                    IEnumerable <WSTableParam> orgExceptParams = orgParams.Where(p1 => !refParams.Any(p2 => p2.Match(p1)));
                    IEnumerable <WSTableParam> refExceptParams = refParams.Where(p1 => !orgParams.Any(p2 => p2.Match(p1)));

                    if (orgExceptParams.Any() || refExceptParams.Any())
                    {
                        return(false);
                    }
                    else
                    {
                        foreach (WSTableParam param in orgParams)
                        {
                            object orgInfo = orgType.GetProperties().FirstOrDefault(p => p.Name.Equals(param.WSColumnRef.NAME)).GetValue(this, null);
                            object refInfo = refType.GetProperties().FirstOrDefault(p => p.Name.Equals(param.WSColumnRef.NAME)).GetValue(refEntity, null);
                            if (!(orgInfo == null && refInfo == null) && !orgInfo.ToString().Equals(refInfo.ToString()))
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status, $"Match():321"); }
            return(false);
        }
示例#21
0
 public override Expression SortTable <T>(MetaFunctions CFunc, WSDataContext dc, List <PropertyInfo> parents, Expression expression, ref WSStatus iostatus)
 {
     try
     {
         foreach (WSJson json in Value)
         {
             List <PropertyInfo> subParents = new List <PropertyInfo>();
             if (parents != null && parents.Any())
             {
                 subParents.AddRange(parents);
             }
             expression = json.SortTable <T>(CFunc, dc, subParents, expression, ref iostatus);
         }
     }
     catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
     return(expression);
 }
示例#22
0
        public override bool MatchEntity(MetaFunctions CFunc, WSDynamicEntity entity, WSTableSource src, string key = null, string matchOperation = null)
        {
            bool isMatch = true;

            try
            {
                foreach (WSJProperty jProp in Value)
                {
                    if (!jProp.MatchEntity(CFunc, entity, src, key))
                    {
                        isMatch = false;
                    }
                }
            }
            catch (Exception e) { isMatch = false; WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(isMatch);
        }
示例#23
0
        public override bool Match(WSRequest Request, WSDataContext DBContext, MetaFunctions CFunc, WSSchema schema)
        {
            bool ok = false;

            try
            {
                WSEntitySchema eSchema = null;
                if (schema is WSEntitySchema)
                {
                    eSchema = (WSEntitySchema)schema;
                }
                else if (schema is WSEntityListSchema)
                {
                    eSchema = ((WSEntityListSchema)schema).EntitySchema;
                }

                if (eSchema != null)
                {
                    bool baseFilterMatch = true;
                    if (eSchema.Source.BaseFilter != null && eSchema.Source.BaseFilter.IsValid && eSchema.Source.BaseFilter.apply(Request, CFunc))
                    {
                        baseFilterMatch = eSchema.Source.BaseFilter.MatchEntity(CFunc, this, ((WSTableSource)CFunc.GetSourceByType(GetType())));
                    }

                    bool dynamicFilterMatch = true;
                    if (eSchema.Fields != null || eSchema.Fields != null)
                    {
                        dynamicFilterMatch = MatchFields(Request, CFunc, eSchema) && MatchFilters(Request, CFunc, eSchema);
                    }

                    ok = baseFilterMatch && dynamicFilterMatch;
                }
            }
            catch (Exception e) {
                if (Request != null)
                {
                    CFunc.RegError(GetType(), e, ref Request.status, $"Match():434");
                }
                else
                {
                    WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status, $"Match():435");
                }
            }
            return(ok);
        }
示例#24
0
 public WSEntitySchema(MetaFunctions _Func, WSTableSource _Source = null, IEnumerable <WSTableSource> sources = null) : base(_Func, null)
 {
     try {
         if (_Source != null)
         {
             Source = _Source;
             Name   = _Source.NAME.ToLower();
             if (_Source != null && _Source.UserRole >= _Source.AccessLevel)
             {
                 foreach (WSTableParam param in _Source.Params)
                 {
                     parseBaseParam(param, sources);
                 }
             }
         }
     }
     catch (Exception e) { Failed = true; WSStatus status = WSStatus.NONE.clone(); Func.RegError(GetType(), e, ref status); }
 }
示例#25
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                if (value != null)
                {
                    if (value is IList)
                    {
                        serializeWSRecords(writer, serializer, (IList)value, XParams);
                    }
                    else if (value is WSRecord)
                    {
                        ((WSRecord)value).WriteJson(writer, serializer, new List <Type>(), Request, CFunc, DBContext);
                    }
                }
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref status); }
        }
示例#26
0
        public WSDynamicEntity getRelatedParent <A>(ClientFunctions CFunc, ref WSStatus _statusLines, IEnumerable <Type> _refTypes = null)
        {
            WSDynamicEntity relEntity = null;

            try
            {
                WSTableSource orgSrc = (WSTableSource)getSource(CFunc);
                WSTableSource relSrc = (WSTableSource)CFunc.GetSourceByType(typeof(A));
                if (relSrc != null)
                {
                    WSTableParam refParam = orgSrc.DBParams.FirstOrDefault(x => x.DataType == relSrc.ReturnType);
                    if (refParam == null)
                    {
                        IEnumerable <Type>         refTypes = _refTypes == null ? new List <Type>() : _refTypes.Select(x => x);
                        IEnumerable <WSTableParam> eParams  = orgSrc.DBParams.Any() ? orgSrc.DBParams.Where(x => x.DataType.IsValidDynamicEntity() && !x.DataType.IsCollection() && !refTypes.Any(t => t == x.DataType)) : null;
                        if (eParams != null && eParams.Any())
                        {
                            foreach (WSTableParam eParam in eParams)
                            {
                                object          pValue  = null;
                                WSDynamicEntity pEntity = TryReadPropertyValue(eParam.WSColumnRef.NAME, out pValue, null) ? (WSDynamicEntity)pValue : null;

                                relEntity = pEntity.getRelatedParent <A>(CFunc, ref _statusLines, refTypes);

                                if (relEntity != null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        object PValue = null;
                        relEntity = TryReadPropertyValue(refParam.WSColumnRef.NAME, out PValue, null) ? (WSDynamicEntity)PValue : null;
                    }
                }
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref _statusLines, $"getRelatedParent():211"); }
            return(relEntity);
        }
示例#27
0
        public override bool MatchEntity(MetaFunctions CFunc, WSDynamicEntity entity, WSTableSource src, string key = null, string matchOperation = null)
        {
            bool isMatch = true;

            try
            {
                if (!string.IsNullOrEmpty(key) && IsValid)
                {
                    matchOperation = matchOperation == null ? WSFieldFilter.GLOBAL_OPERATIONS.Equal.NAME : matchOperation;

                    WSTableParam param = src.DBPrimitiveParams.FirstOrDefault(p => p.Match(key));

                    if (param != null)
                    {
                        isMatch = Match(entity.GetType().GetProperty(param.WSColumnRef.NAME).GetValue(entity, null), matchOperation, param.DataType);
                    }
                }
            }
            catch (Exception e) { isMatch = false;  WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(isMatch);
        }
示例#28
0
        public override Expression SortTable <TEntity>(MetaFunctions CFunc, WSDataContext dc, List <PropertyInfo> parents, Expression expression, ref WSStatus iostatus)
        {
            try
            {
                if (dc != null)
                {
                    parents = parents != null ? parents : new List <PropertyInfo>();
                    Type          srcType    = parents.Any() ? parents.LastOrDefault().PropertyType.IsCollection() ? parents.LastOrDefault().PropertyType.GetEntityType() : parents.LastOrDefault().PropertyType : typeof(TEntity);
                    ITable        initSource = srcType == null ? null : dc.GetTable(typeof(TEntity));
                    ITable        source     = srcType == null ? null : dc.GetTable(srcType);
                    WSTableSource schema     = srcType == null ? null : (WSTableSource)CFunc.GetSourceByType(srcType);
                    if (schema != null)
                    {
                        WSParam param = schema.GetXParam(Value);

                        if (param != null && param is WSTableParam)
                        {
                            WSTableParam tParam   = (WSTableParam)param;
                            PropertyInfo property = srcType.GetProperties().FirstOrDefault(p => tParam.WSColumnRef.NAME.Equals(p.Name));
                            if (property == null)
                            {
                                iostatus.AddNote(string.Format("No PropertyInfo found for : [{0}]", tParam.DISPLAY_NAME));
                            }
                            else
                            {
                                parents.Add(property);

                                if (tParam.DataType.IsSimple() && tParam.IsSortable)
                                {
                                    expression = SortPrimitiveType <TEntity>(initSource, source, param, false, parents, expression, ref iostatus);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(expression);
        }
示例#29
0
        public WSParam GetXParam(string xName, Type DefaultFieldType = null, Func <Type, WSTableSource> getTSource = null)
        {
            WSParam param = null;

            try
            {
                if (!string.IsNullOrEmpty(xName))
                {
                    xName = xName.ToLower();
                    param = Params.FirstOrDefault(p => p is WSTableParam ? ((WSTableParam)p).Match(xName, null, getTSource) : p.Match(xName, null, getTSource));
                    if (param == null)
                    {
                        if (DefaultFieldType != null)
                        {
                            param = new WSTableParam(ReturnType, 0, xName.ToLower(), new WSColumnRef(xName), DefaultFieldType, CFunc);
                        }
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(param);
        }
示例#30
0
        private string LoadJson()
        {
            try
            {
                StringBuilder sb = new StringBuilder();

                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

                sb.Append("\"DeleteFlag\":\"" + (DeleteFlag == null ? "" : DeleteFlag.NAME) + "\"");
                sb.Append(",");
                sb.Append("\"IsReadable\":" + IsReadable.ToString().ToLower() + "");
                sb.Append(",");
                sb.Append("\"IsCreatable\":" + IsCreatable.ToString().ToLower() + "");
                sb.Append(",");
                sb.Append("\"IsEditable\":" + IsEditable.ToString().ToLower() + "");
                sb.Append(",");
                sb.Append("\"IsDeletable\":" + IsDeletable.ToString().ToLower() + "");
                sb.Append(",");
                string fEntityKeys = "{" + (FirstEntityKeys.Any() ? FirstEntityKeys.Select(x => "\"" + x.Key + "\":" + js.Serialize(x.Value)).Aggregate((a, b) => a + "," + b) : "") + "}";
                sb.Append("\"FirstEntity\":" + fEntityKeys);

                string baseJson = base.Json;

                baseJson = baseJson.Replace(("\"SecurityZone\":\"" + base.SecurityZone + "\""), ("\"SecurityZone\":\"" + SecurityZone + "\""));

                sb.Append(string.IsNullOrEmpty(baseJson) ? "" : ("," + baseJson));

                sb.Append(",\"AVAILABLE_FORMATS\":[");
                if (AVAILABLE_FORMATS != null && AVAILABLE_FORMATS.Any())
                {
                    sb.Append(AVAILABLE_FORMATS.Select(x => "{" + x.Json + "}").Aggregate((a, b) => a + "," + b));
                }
                sb.Append("]");
                return(sb.ToString());
            }
            catch (Exception e) { WSStatus status = WSStatusBase.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }

            return(string.Empty);
        }