Exemplo n.º 1
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); }
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 internal bool Match(WSTableParam param, IEnumerable <WSTableSource> role_sources = null, Func <Type, WSTableSource> getTSource = null)
 {
     try
     {
         return(param != null && WSEntityType != null && WSEntityType == param.WSEntityType && base.Match(param.NAME, role_sources, getTSource));
     }
     catch (Exception) { }
     return(false);
 }
Exemplo n.º 4
0
 public WSFieldSchema(MetaFunctions _Func, WSTableParam _param, WSJProperty _Json, WSEntitySchema _Parent) : base(_Func, _Parent)
 {
     param = _param;
     if (_Json != null)
     {
         Name = _Json.Key;
         IOBaseOptions.Save(_Json.Value);
     }
 }
Exemplo n.º 5
0
 public bool Contains(WSTableParam param)
 {
     try
     {
         return(this.Any(x => x.Contains(param)));
     }
     catch (Exception) { }
     return(false);
 }
Exemplo n.º 6
0
 public override bool Contains(WSTableParam param)
 {
     try
     {
         return(IsValid && Field.Match(param));
     }
     catch (Exception) { }
     return(false);
 }
Exemplo n.º 7
0
 public override bool Contains(WSTableParam param)
 {
     //TODO@2016-03-04 : find out if WSTableParam 'param' is releted to this filter
     //try
     //{
     //    return IsValid && Source.ReturnType==param.WSEntityType;
     //}
     //catch (Exception) { }
     return(false);
 }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
0
        private WSJProperty getFieldJson(WSTableParam param, WSJson json)
        {
            WSJProperty fJson = null;

            if (json is WSJObject)
            {
                fJson = ((WSJObject)json).Value.FirstOrDefault(x => param.Match(x.Key));
            }
            else if (json is WSJArray)
            {
                fJson = ((WSJArray)json).Value.OfType <WSJObject>().FirstOrDefault(x => param.Match(x.Value[0].Key)).Value[0];
            }
            return(fJson);
        }
Exemplo n.º 10
0
        public override WSFilter GetCustomFilter(Expression _EntityExpression, int _level)
        {
            WSCombineFilter mainFilter = !IsFiltrable ? null : new WSCombineFilter(CombineMode);

            if (mainFilter != null && _EntityExpression != null)
            {
                Expression member = null;
                if (_EntityExpression.Type == Source.ReturnType)
                {
                    member = _EntityExpression;
                }
                else if (Parent != null)
                {
                    WSTableParam paramExt = (WSTableParam)Parent.Source.GetXParam(Name);
                    if (paramExt != null)
                    {
                        member = Expression.Property(_EntityExpression, paramExt.WSColumnRef.NAME);
                    }
                }

                if (member != null && IsFiltrable)
                {
                    if (Fields != null && Fields.Any())
                    {
                        WSCombineFilter cFields = new WSCombineFilter(Fields.CombineMode);
                        mainFilter.Save(cFields);
                        foreach (WSSchema field in Fields)
                        {
                            cFields.Save(field.GetCustomFilter(member, _level));
                        }
                    }
                    if (Filters != null && Filters.Any())
                    {
                        WSCombineFilter cFilters = new WSCombineFilter(Filters.CombineMode);
                        mainFilter.Save(cFilters);
                        foreach (WSSchema field in Filters)
                        {
                            cFilters.Save(field.GetCustomFilter(member, _level));
                        }
                    }
                }

                if (IOBaseOptions != null && !IOBaseOptions.IsEmpty)
                {
                    mainFilter.Save(IOBaseOptions.GetOptionFilter(Func, member, _level + 1));
                }
            }
            return(mainFilter != null && mainFilter.IsValid ? mainFilter.Reduce() : mainFilter);
        }
Exemplo n.º 11
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(Key);

                        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.WSColumnRef.NAME));
                            }
                            else
                            {
                                parents.Add(property);

                                if (tParam.DataType.IsSimple() && tParam.IsSortable)
                                {
                                    bool IsDesc = false;
                                    if (Value is WSJValue)
                                    {
                                        IsDesc = ((WSJValue)Value).Value.ToLower().Equals("desc");
                                    }
                                    expression = SortPrimitiveType <TEntity>(initSource, source, param, IsDesc, parents, expression, ref iostatus);
                                }
                                else if (tParam.DataType.IsSameOrSubclassOf(typeof(WSEntity)) || tParam.DataType.IsCollectionOf <WSEntity>())
                                {
                                    expression = Value.SortTable <TEntity>(CFunc, dc, parents, expression, ref iostatus);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref iostatus); }
            return(expression);
        }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
        private string LoadJson()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("\"Name\":\"" + ReturnType.Name + "\"");
            sb.Append(",\"ReturnType\":\"" + ReturnType.FullName + "\"");
            sb.Append(",\"SecurityZone\":\"" + SecurityZone + "\"");

            sb.Append("," + base.Json);

            sb.Append(",\"Params\":[");
            Func <WSParam, bool>   isAccessibleParam = x => x.READ_ACCESS_MODE.ACCESS_LEVEL <= UserRole;
            Func <WSParam, string> jFunc             = (x => "{" + (x is WSTableParam ? ((WSTableParam)x).Json : x.Json) + "}");

            if (Params != null && Params.Any(isAccessibleParam))
            {
                List <string> paramList = new List <string>();
                foreach (WSParam param in Params.Where(isAccessibleParam))
                {
                    if (param is WSTableParam)
                    {
                        WSTableParam tParam = (WSTableParam)param;
                        if (tParam.IsAssociation)
                        {
                            WSSource src = CFunc.GetSourceByType(tParam.DataType.GetEntityType());
                            if (src != null && src.AccessLevel <= UserRole)
                            {
                                paramList.Add("{" + tParam.Json + "}");
                            }
                        }
                        else
                        {
                            paramList.Add("{" + tParam.Json + "}");
                        }
                    }
                    else
                    {
                        paramList.Add("{" + param.Json + "}");
                    }
                }
                sb.Append(paramList.Aggregate((a, b) => a + "," + b));
            }
            sb.Append("]");

            return(sb.ToString());
        }
Exemplo n.º 14
0
        public bool IsRelationTo(ClientFunctions CFunc, WSDynamicEntity _RelationTEntity, ref WSStatus _statusLines, IEnumerable <Type> _refTypes = null)
        {
            bool _IsRelationTo = false;

            try
            {
                if (_RelationTEntity != null)
                {
                    WSTableSource orgSrc = (WSTableSource)getSource(CFunc);
                    WSTableSource relSrc = (WSTableSource)_RelationTEntity.getSource(CFunc);
                    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;

                                    _IsRelationTo = pEntity.IsRelationTo(CFunc, _RelationTEntity, ref _statusLines, refTypes);

                                    if (_IsRelationTo)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            object          PValue    = null;
                            WSDynamicEntity RefEntity = TryReadPropertyValue(refParam.WSColumnRef.NAME, out PValue, null) ? (WSDynamicEntity)PValue : null;

                            _IsRelationTo = RefEntity != null && _RelationTEntity.Match(CFunc, RefEntity);
                        }
                    }
                }
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref _statusLines, $"IsRelationTo():256"); }
            return(_IsRelationTo);
        }
Exemplo n.º 15
0
        internal new WSTableParam Clone()
        {
            WSTableParam param = new WSTableParam(WSEntityType, CODE, NAME, WSColumnRef, DataType, func);

            param.DISPLAY_NAME     = DISPLAY_NAME;
            param.DEFAULT_VALUE    = DEFAULT_VALUE;
            param.IsColumn         = IsColumn;
            param.IsAssociation    = IsAssociation;
            param.READ_ACCESS_MODE = READ_ACCESS_MODE != null?READ_ACCESS_MODE.Clone() : new WSAccessMode(WSConstants.ACCESS_LEVEL.READ);

            param.WRITE_ACCESS_MODE = WRITE_ACCESS_MODE != null?WRITE_ACCESS_MODE.Clone() : new WSAccessMode(WSConstants.ACCESS_LEVEL.UPDATE);

            param.SkipEmpty      = SkipEmpty;
            param.ALLOWED_VALUES = (ALLOWED_VALUES != null && ALLOWED_VALUES.Any()) ? ALLOWED_VALUES.Select(x => x.Clone()).ToList() : new List <WSValue>();
            param.ALIACES        = (ALIACES != null && ALIACES.Any()) ? ALIACES.Select(x => x).ToList() : new List <string>();
            param.DESCRIPTION    = DESCRIPTION;
            return(param);
        }
Exemplo n.º 16
0
        public void Merge(WSTableSource ext)
        {
            base.Merge(ext);

            AllowOwnerAccess = ext.AllowOwnerAccess;
            BaseFilter       = ext.BaseFilter;
            DeletableFilter  = ext.DeletableFilter;
            EditableFilter   = ext.EditableFilter;
            CreatableFilter  = ext.CreatableFilter;
            ReadableFilter   = ext.ReadableFilter;

            foreach (WSTableParam orgParam in Params.OfType <WSTableParam>())
            {
                WSTableParam extParam = ext.DBParams.FirstOrDefault(p => p.WSColumnRef.NAME.Equals(orgParam.WSColumnRef.NAME));
                if (extParam != null)
                {
                    orgParam.Merge(extParam);
                }
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        public override WSFilter GetOptionFilter(MetaFunctions CFunc, Expression parent, int level, string state = null, bool?negate = null)
        {
            WSCombineFilter filter = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso);

            try
            {
                if (Value != null)
                {
                    if (WSConstants.ALIACES.NOT.Match(Key))
                    {
                        return(Value.GetOptionFilter(CFunc, parent, level, state, true));
                    }
                    else if (WSConstants.ALIACES.ANY.Match(Key))
                    {
                        return(Value.GetOptionFilter(CFunc, parent, level, Key, true));
                    }
                    else
                    {
                        if (Value is WSJValue)
                        {
                            filter.Save(((WSJValue)Value).GetOptionFilter(CFunc, parent, level, state, negate));
                        }
                        else
                        {
                            WSTableSource PSource  = (WSTableSource)CFunc.GetSourceByType(parent.Type.GetEntityType());
                            WSTableParam  subParam = PSource == null ? null : (WSTableParam)PSource.GetXParam(Key);

                            //TODO@ANDVO:2016-11-15: implement deep filtering
                        }
                        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);
        }
Exemplo n.º 21
0
        public override WSFilter GetFieldFilter(MetaFunctions CFunc, WSTableParam param, Expression parent, int level, string state = null, bool?negate = null)
        {
            try
            {
                ///**************************************************
                //* if(filter array contains any conditional 'IOJFilter'
                //* like : "[{option_name1:value1},{option_name2:value2}]" (example:"[{max:123},{min:123}]") , - then use 'CombineMode.AndAlso'
                //* else
                //* (if all values in the filter array are simple type values)
                //* like : "{value1,value2,value3,...}" ,- use 'CombineMode.Or'
                //* ***********************************************/
                WSCombineFilter filter = new WSCombineFilter(WSCombineFilter.SQLMode.OrElse, negate);

                foreach (WSJson j in Value)
                {
                    WSFilter jFilter = j.GetFieldFilter(CFunc, param, parent, level, state, negate);
                    filter.Save(jFilter);
                }

                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);
        }
Exemplo n.º 22
0
        public override bool MatchEntity(MetaFunctions CFunc, WSDynamicEntity entity, WSTableSource src, string key = null, string matchOperation = null)
        {
            bool isMatch = true;

            try
            {
                if (!IsValid)
                {
                    isMatch = false;
                }
                else
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        key = Key;
                    }
                    else
                    {
                        matchOperation = Key;
                    }

                    if (Value is WSJValue)
                    {
                        isMatch = ((WSJValue)Value).MatchEntity(CFunc, entity, src, key, matchOperation);
                    }
                    else
                    {
                        if (src.DBAssociationParams.Any(p => p.Match(Key)))
                        {
                            WSTableParam param = src.DBAssociationParams.FirstOrDefault(p => p.Match(Key));
                            src = (WSTableSource)CFunc.GetSourceByType(param.DataType.GetEntityType());
                            object oEntity = entity.GetType().GetProperty(param.WSColumnRef.NAME).GetValue(entity, null);
                            if (oEntity.GetType().IsCollectionOf <WSDynamicEntity>())
                            {
                                foreach (WSDynamicEntity e in (IEnumerable <WSDynamicEntity>)oEntity)
                                {
                                    if (Value is WSJObject)
                                    {
                                        if (((WSJObject)Value).MatchEntity(CFunc, e, src))
                                        {
                                            isMatch = true;
                                        }
                                    }
                                    else if (Value is WSJArray)
                                    {
                                        if (((WSJArray)Value).MatchEntity(CFunc, e, src))
                                        {
                                            isMatch = true;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (Value is WSJObject)
                                {
                                    isMatch = ((WSJObject)Value).MatchEntity(CFunc, (WSDynamicEntity)oEntity, src);
                                }
                                else if (Value is WSJArray)
                                {
                                    isMatch = ((WSJArray)Value).MatchEntity(CFunc, (WSDynamicEntity)oEntity, src);
                                }
                            }
                        }
                        else
                        {
                            if (Value is WSJObject)
                            {
                                isMatch = ((WSJObject)Value).MatchEntity(CFunc, entity, src, key);
                            }
                            else if (Value is WSJArray)
                            {
                                isMatch = ((WSJArray)Value).MatchEntity(CFunc, entity, src, key);
                            }
                        }
                    }
                }
            }
            catch (Exception e) { isMatch = false; WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(isMatch);
        }
Exemplo n.º 23
0
 public WSNumericFFilter(WSTableParam _Field, Expression _member, WSOperation _Operation)
     : base(_Field, _member)
 {
     operation = _Operation != null ? _Operation : OPERATIONS.GetOperation(null);
 }
Exemplo n.º 24
0
        public override WSFilter GetFieldFilter(MetaFunctions CFunc, WSTableParam param, Expression parent, int level, string state = null, bool?negate = null)
        {
            Expression      member = Expression.Property(parent, param.WSColumnRef.NAME);
            WSCombineFilter filter = new WSCombineFilter();

            if (param != null && param.isValid)
            {
                try
                {
                    if (WSConstants.ALIACES.EXIST.Match(Value) || WSConstants.ALIACES.EMPTY.Match(Value) || WSConstants.ALIACES.IS_OWN.Match(Value))
                    {
                        state = Value;
                    }

                    #region Read WSEntity (Ready)
                    if (!string.IsNullOrEmpty(state) && (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)) || param.DataType.IsCollectionOf <WSEntity>()))
                    {
                        if (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)) && WSEntityFFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(state)))
                        {
                            filter.Save(new WSEntityFFilter(param, member, WSEntityFFilter.OPERATIONS.STATE_OPERATIONS.FirstOrDefault(x => x.Match(state)))
                            {
                                Value = null
                            });
                        }
                        else if (param.DataType.IsCollectionOf <WSEntity>() && WSEntityListFFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(state)))
                        {
                            filter.Save(new WSEntityListFFilter(param, member, WSEntityListFFilter.OPERATIONS.STATE_OPERATIONS.FirstOrDefault(x => x.Match(state)))
                            {
                                Value = null
                            });
                        }
                    }
                    #endregion

                    #region Read primitive
                    else
                    {
                        dynamic dVal = null;

                        #region Numeric (Ready)
                        if (param.DataType.IsNumeric())
                        {
                            #region SPECIAL CASES
                            #region If Exists (Ready)
                            if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSNumericFFilter(param, member, WSNumericFFilter.OPERATIONS.NotEqual)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #region If Empty (Ready)
                            else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSNumericFFilter(param, member, null)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #endregion

                            #region If Value (Ready)
                            else
                            {
                                if (param.DataType.Read(Value, out dVal))
                                {
                                    Type        dType     = dVal == null ? param.DataType : dVal.GetType();
                                    WSOperation operation = WSNumericFFilter.OPERATIONS.GetOperation(state);

                                    if (operation.Match("max") && dType.IsCollection())
                                    {
                                        dVal = ((List <dynamic>)dVal).Max(x => x);
                                    }
                                    else if (operation.Match("min") && dType.IsCollection())
                                    {
                                        dVal = ((List <dynamic>)dVal).Min(x => x);
                                    }

                                    filter.Save(new WSNumericFFilter(param, member, operation)
                                    {
                                        Value = dVal
                                    });
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #region bool (Ready)
                        else if (typeof(bool?).IsAssignableFrom(param.DataType))
                        {
                            #region SPECIAL CASES
                            #region If Exists (Ready)
                            if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSBoolFFilter(param, member, WSBoolFFilter.OPERATIONS.NotEqual)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #region If Empty (Ready)
                            else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSBoolFFilter(param, member, null)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #endregion

                            #region If Value (Ready)
                            else
                            {
                                if (param.DataType.Read(Value, out dVal))
                                {
                                    filter.Save(new WSBoolFFilter(param, member, WSBoolFFilter.OPERATIONS.GetOperation(state))
                                    {
                                        Value = dVal
                                    });
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #region string (Ready)
                        else if (typeof(string).IsAssignableFrom(param.DataType))
                        {
                            #region SPECIAL CASES
                            #region If Exists (Ready)
                            if (WSConstants.ALIACES.EXIST.Match(Value))
                            {
                                if (param.DataType.IsNullable())
                                {
                                    filter.Save(new WSStringFFilter(param, member, WSStringFFilter.OPERATIONS.NotEqual)
                                    {
                                        Value = null
                                    });
                                }
                                filter.Save(new WSStringFFilter(param, member, WSStringFFilter.OPERATIONS.NotEqual)
                                {
                                    Value = string.Empty
                                });
                            }
                            #endregion
                            #region If Empty (Ready)
                            else if (WSConstants.ALIACES.EMPTY.Match(Value))
                            {
                                WSCombineFilter cFilter = new WSCombineFilter(WSCombineFilter.SQLMode.Or);;
                                if (param.DataType.IsNullable())
                                {
                                    cFilter.Save(new WSStringFFilter(param, member, null)
                                    {
                                        Value = null
                                    });
                                }
                                cFilter.Save(new WSStringFFilter(param, member, null)
                                {
                                    Value = string.Empty
                                });
                                filter.Save(cFilter);
                            }
                            #endregion
                            #endregion

                            #region If Value (Ready)
                            else if (param.DataType.IsNullable() || !string.IsNullOrEmpty(Value))
                            {
                                if (param.DataType.Read(Value, out dVal))
                                {
                                    filter.Save(new WSStringFFilter(param, member, WSStringFFilter.OPERATIONS.GetOperation(state))
                                    {
                                        Value = dVal
                                    });
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #region Guid (Ready)
                        else if (typeof(Guid?).IsAssignableFrom(param.DataType))
                        {
                            #region SPECIAL CASES
                            #region If Exists (Ready)
                            if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSGuidFFilter(param, member, WSGuidFFilter.OPERATIONS.NotEqual)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #region If Empty (Ready)
                            else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSGuidFFilter(param, member, null)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #endregion

                            #region If Value (Ready)
                            else
                            {
                                if (param.DataType.Read(Value, out dVal, null, WSConstants.GUID_LIST_SEPARATORS))
                                {
                                    filter.Save(new WSGuidFFilter(param, member, WSGuidFFilter.OPERATIONS.GetOperation(state))
                                    {
                                        Value = dVal
                                    });
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #region DateTime (Ready)
                        else if (typeof(DateTime?).IsAssignableFrom(param.DataType))
                        {
                            #region SPECIAL CASES
                            #region If Exists (Ready)
                            if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSDateFFilter(param, member, WSDateFFilter.OPERATIONS.NotEqual)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #region If Empty (Ready)
                            else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSDateFFilter(param, member, null)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #endregion

                            #region If Value (Ready)
                            else
                            {
                                WSOperation operation =
                                    Value.IsTrue() ?
                                    WSDateFFilter.OPERATIONS.LessOrEqual :
                                    (Value.IsFalse() && !(param.DataType.IsNullable())) ?
                                    WSDateFFilter.OPERATIONS.GreaterThanOrEqual :
                                    WSDateFFilter.OPERATIONS.GetOperation(state);
                                WSDateFFilter mainFilter = null;
                                if (operation != null && operation.Match(WSDateFFilter.OPERATIONS.WeekDayEqual))
                                {
                                    mainFilter = new WSDateFFilter(param, member, operation)
                                    {
                                        Value = Value
                                    };
                                }
                                else if (param.DataType.Read(Value, out dVal, new char[] { }, WSConstants.DATE_LIST_SEPARATORS, param.WSColumnRef.NAME))
                                {
                                    Type dType = dVal == null ? param.DataType : dVal.GetType();
                                    if (dType.IsCollection() && operation != null)
                                    {
                                        dVal = operation.Match(WSDateFFilter.OPERATIONS.LessOrEqual) ? ((List <dynamic>)dVal).Max(x => x) : operation.Match(WSDateFFilter.OPERATIONS.GreaterThanOrEqual) ? ((List <dynamic>)dVal).Min(x => x) : dVal;
                                    }
                                    mainFilter = new WSDateFFilter(param, member, operation)
                                    {
                                        Value = dVal
                                    };
                                }

                                if (param.DataType.IsNullable())
                                {
                                    WSCombineFilter cf = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso);

                                    if (mainFilter.Value != null)
                                    {
                                        cf.Save(new WSDateFFilter(param, member, WSDateFFilter.OPERATIONS.NotEqual)
                                        {
                                            Value = null
                                        });
                                    }

                                    cf.Save(mainFilter);

                                    filter.Save(cf);
                                }
                                else
                                {
                                    filter.Save(mainFilter);
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #region TimeSpan (Ready)
                        else if (typeof(TimeSpan?).IsAssignableFrom(param.DataType))
                        {
                            #region SPECIAL CASES
                            #region If Exists (Ready)
                            if (WSConstants.ALIACES.EXIST.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSTimeFFilter(param, member, WSTimeFFilter.OPERATIONS.NotEqual)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #region If Empty (Ready)
                            else if (WSConstants.ALIACES.EMPTY.Match(Value) && param.DataType.IsNullable())
                            {
                                filter.Save(new WSTimeFFilter(param, member, null)
                                {
                                    Value = null
                                });
                            }
                            #endregion
                            #endregion

                            #region If Value (Ready)
                            else
                            {
                                if (param.DataType.Read(Value, out dVal, new char[] { }, WSConstants.DATE_LIST_SEPARATORS))
                                {
                                    WSOperation operation = WSTimeFFilter.OPERATIONS.GetOperation(state);

                                    Type dType = dVal == null ? param.DataType : dVal.GetType();
                                    if (dType.IsCollection() && operation != null)
                                    {
                                        dVal = operation.Match("max") ? ((List <dynamic>)dVal).Max(x => x) : operation.Match("min") ? ((List <dynamic>)dVal).Min(x => x) : dVal;
                                    }

                                    if (param.DataType.IsNullable())
                                    {
                                        WSCombineFilter cf = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso);

                                        if (Value != null)
                                        {
                                            cf.Save(new WSTimeFFilter(param, member, WSTimeFFilter.OPERATIONS.NotEqual)
                                            {
                                                Value = null
                                            });
                                        }

                                        cf.Save(new WSTimeFFilter(param, member, operation)
                                        {
                                            Value = dVal
                                        });

                                        filter.Save(cf);
                                    }
                                    else
                                    {
                                        filter.Save(new WSTimeFFilter(param, member, operation)
                                        {
                                            Value = dVal
                                        });
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion
                    }
                    #endregion
                }
                catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); if (CFunc != null)
                                      {
                                          CFunc.RegError(GetType(), e, ref status);
                                      }
                }
            }
            return(filter.Any() ? (filter.Count == 1 && !filter.Negate) ? filter.FirstOrDefault() : filter : null);
        }
Exemplo n.º 25
0
        public override WSFilter GetFieldFilter(MetaFunctions CFunc, WSTableParam param, Expression parent, int level, string state = null, bool?negate = null)
        {
            WSCombineFilter filter = new WSCombineFilter(WSCombineFilter.SQLMode.AndAlso);

            try
            {
                if (param != null && param.isValid && (param.DataType.IsNullable() || Value != null))
                {
                    if (param.DataType.IsSimple())
                    {
                        bool localNegate = WSConstants.ALIACES.NOT.Match(state);
                        negate = negate == null ? localNegate : localNegate != negate;
                        WSFilter pFilter = Value.GetFieldFilter(CFunc, param, parent, level, Key, negate);
                        filter.Save(pFilter);
                    }
                    else if (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)) || param.DataType.IsCollectionOf <WSEntity>())
                    {
                        if (WSConstants.ALIACES.NOT.Match(Key))
                        {
                            return(Value.GetFieldFilter(CFunc, param, parent, level, state, true));
                        }
                        else if (WSConstants.ALIACES.ANY.Match(Key))
                        {
                            return(Value.GetFieldFilter(CFunc, param, parent, level, Key, true));
                        }
                        else
                        {
                            WSTableSource PSource = (WSTableSource)CFunc.GetSourceByType/*<WSTableSource>*/ (param.DataType.GetEntityType());

                            WSTableParam subParam = PSource == null ? null : (WSTableParam)PSource.GetXParam(Key);
                            Expression   member   = Expression.Property(parent, param.WSColumnRef.NAME);
                            if (subParam == null && WSConstants.SPECIAL_CASES.Any(c => c.Match(Key)))
                            {
                                if (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)))
                                {
                                    return(new WSEntityFFilter(param, member, WSEntityFFilter.OPERATIONS.STATE_OPERATIONS.FirstOrDefault(x => x.Match(Key)))
                                    {
                                        Value = null
                                    });
                                }
                                else if (param.DataType.IsCollectionOf <WSEntity>())
                                {
                                    return(new WSEntityListFFilter(param, member, WSEntityListFFilter.OPERATIONS.STATE_OPERATIONS.FirstOrDefault(x => x.Match(Key)))
                                    {
                                        Value = null
                                    });
                                }
                            }
                            else
                            {
                                WSFilter subFilter = null;
                                if (param.DataType.IsSameOrSubclassOf(typeof(WSEntity)))
                                {
                                    filter.Save(new WSEntityFFilter(param, member, WSEntityFFilter.OPERATIONS.NotEqual)
                                    {
                                        Value = null
                                    });

                                    subFilter = Value.GetFieldFilter(CFunc, subParam, member, level, Key);
                                    if (subFilter != null && subFilter.IsValid)
                                    {
                                        filter.Save(new WSEntityFFilter(param, member, WSEntityFFilter.OPERATIONS.Filter)
                                        {
                                            Value = subFilter
                                        });
                                    }
                                }
                                else if (param.DataType.IsCollectionOf <WSEntity>())
                                {
                                    level++;

                                    Type elemType          = param.DataType.GetEntityType();
                                    ParameterExpression id = Expression.Parameter(elemType, level.ToHex());
                                    subFilter = Value.GetFieldFilter(CFunc, subParam, id, level, Key, negate);
                                    if (subFilter != null && subFilter.IsValid)
                                    {
                                        dynamic subExpr = subFilter.GetType().GetMethod("ToLambda").MakeGenericMethod(new Type[] { elemType }).Invoke(subFilter, new object[] { id });

                                        filter.Save(new WSEntityListFFilter(subParam, member, WSEntityListFFilter.OPERATIONS.Any)
                                        {
                                            Value = (subExpr == null) ? true : subExpr
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
            return(filter.Any() ? (filter.Count == 1 && !filter.Negate) ? filter.FirstOrDefault() : filter : null);
        }
Exemplo n.º 26
0
 public abstract WSFilter GetFieldFilter(MetaFunctions CFunc, WSTableParam param, Expression parent, int level, string state = null, bool?negate = null);
Exemplo n.º 27
0
 public WSEntityFieldSchema(MetaFunctions _Func, WSTableParam _Param, WSJProperty _Json, WSEntitySchema _Parent) : base(_Func, _Param, _Json, _Parent)
 {
 }
Exemplo n.º 28
0
 internal void Merge(WSTableParam newPrimParam)
 {
     base.Merge(newPrimParam);
 }
Exemplo n.º 29
0
 public bool Contains(WSTableParam param)
 {
     return(false);
 }
Exemplo n.º 30
0
        public virtual bool Match(string key, IEnumerable <WSTableSource> sources = null, Func <Type, WSTableSource> getTSource = null, bool TypeMatchAllowed = true)
        {
            try
            {
                if (!string.IsNullOrEmpty(NAME) && !string.IsNullOrEmpty(key))
                {
                    key = key.ToLower();
                    int _CODE = -1;
                    if (CODE >= 0)
                    {
                        if (NAME.Equals(key))
                        {
                            return(true);
                        }
                        else if (DISPLAY_NAME.Equals(key))
                        {
                            return(true);
                        }
                        else if (ALIACES != null && ALIACES.Contains(key))
                        {
                            return(true);
                        }
                        else if (this is WSTableParam)
                        {
                            WSTableParam p = (WSTableParam)this;
                            if (p.WSColumnRef.NAME.ToLower().Equals(key))
                            {
                                return(true);
                            }
                            else if (TypeMatchAllowed && p.DataType.IsValidDynamicEntity())
                            {
                                WSTableSource src = null;
                                if (getTSource != null)
                                {
                                    src = getTSource(p.DataType.GetEntityType());
                                }

                                else if (sources != null)
                                {
                                    src = sources.FirstOrDefault(s => s.ReturnType == p.DataType.GetEntityType());
                                }

                                else if (func != null)
                                {
                                    src = (WSTableSource)func.GetSourceByType(p.DataType.GetEntityType());
                                }

                                if (src != null && src.Match(key))
                                {
                                    return(true);
                                }
                            }
                        }
                        else if (int.TryParse(key, out _CODE) && _CODE == CODE)
                        {
                            return(true);
                        }
                    }
                    ;
                }
            }
            catch (Exception) { }
            return(false);
        }