Exemplo n.º 1
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);
        }
Exemplo n.º 2
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.º 3
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.º 4
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);
        }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 public WSUserSet(WSRoleSet RoleSet, Func <string, WSSession> ReadWSSession, MetaFunctions _CFunc)
 {
     CFunc = _CFunc;
     if (RoleSet != null)
     {
         foreach (string DBName in RoleSet.Last().Value.Keys)
         {
             WSSession session = ReadWSSession(DBName);
             if (session != null && RoleSet.ContainsKey(session.user.role) && RoleSet[session.user.role].ContainsKey(DBName))
             {
                 WSUserDBSet DBSet = new WSUserDBSet(session);
                 DBSet.AddRange(RoleSet[session.user.role][DBName].Clone(ref DBSet, CFunc));
                 Add(DBName, DBSet);
             }
         }
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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); }
 }
Exemplo n.º 9
0
        public WSSecurity(WSDynamicEntity _Session, string _SessionID, MetaFunctions _CFunc)
        {
            Session   = _Session;
            SessionID = _SessionID;
            CFunc     = _CFunc;
            try
            {
                AuthToken.User = new WSUserToken();
                if (_Session != null)
                {
                    SessionID = _Session.readPropertyValue("SessionID").ToString();
                    object userObj = _Session.readPropertyValue("User");
                    if (userObj != null)
                    {
                        WSDynamicEntity user = (WSDynamicEntity)userObj;

                        object id        = user.readPropertyValue("UserID");
                        object email     = user.readPropertyValue("Email");
                        object login     = user.readPropertyValue("Login");
                        object firstname = user.readPropertyValue("FirstName");
                        object lastname  = user.readPropertyValue("LastName");
                        object role      = user.readPropertyValue("RoleID");
                        object isactive  = user.readPropertyValue("IsActive");
                        object password  = user.readPropertyValue("Password");

                        AuthToken.User = new WSUserToken()
                        {
                            id        = int.Parse(id.ToString()),
                            email     = email == null ? "" : email.ToString(),
                            login     = login == null ? "" : login.ToString(),
                            firstname = firstname == null ? "" : firstname.ToString(),
                            lastname  = lastname == null ? "" : lastname.ToString(),
                            role      = role == null ? (byte)0 : byte.Parse(role.ToString()),
                            isactive  = isactive == null ? false : isactive.ToString().IsTrue()
                        };
                        WSCurrentUser = new WSCurrentUser(user);
                        UPass         = password == null ? "" : password.ToString();
                    }
                }
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref status); }
        }
Exemplo n.º 10
0
        internal override bool applyInternal(WSRequest Request, MetaFunctions CFunc)
        {
            try {
                if (Value.StartsWith("$") || (Value.StartsWith("[") && Value.EndsWith("]")))
                {
                    string temp = Value.Trim(new char[] { '[', ']' }).TrimStart(new char[] { '$' });

                    if (!string.IsNullOrEmpty(temp))
                    {
                        if (WSConstants.COMMAND_VALUES.Items.Any(v => v.Match(temp)))
                        {
                            if (WSConstants.COMMAND_VALUES.USER_ID.Match(temp))
                            {
                                Value = Request.Security.AuthToken.User.id.ToString();
                            }
                            else
                            {
                                if (WSConstants.COMMAND_VALUES.SQL_COMMAND_VALUE_GETDATE.Match(temp))
                                {
                                    DateTime d = Request.DBContext.GetSystemDate();
                                    Value = d.ToString(WSConstants.DATE_FORMAT);
                                }
                                else if (WSConstants.COMMAND_VALUES.SQL_COMMAND_VALUE_GETTIME.Match(temp))
                                {
                                    DateTime d = Request.DBContext.GetSystemDate();
                                    Value = new TimeSpan(0, d.Hour, d.Minute, d.Second, d.Millisecond).ToString(WSConstants.DATE_FORMAT);
                                }
                            }
                        }
                        else if (WSConstants.COMMAND_KEYS.Items.Any(v => v.Match(temp)))
                        {
                            if (WSConstants.COMMAND_KEYS.SHARED_KEY.Match(temp))
                            {
                                Value = Request.SOURCE.GetXParam(temp).ReadValue(Request.INPUT).ToString();
                            }
                        }
                    }
                }
                return(true);
            } catch (Exception e) { CFunc.RegError(GetType(), e, ref Request.status); }
            return(false);
        }
Exemplo n.º 11
0
        public ObjectTranslator( Lua interpreter, IntPtr luaState )
        {
            this.interpreter = interpreter;
            typeChecker = new CheckType( this );
            metaFunctions = new MetaFunctions( this );
            assemblies = new List<Assembly>();

            importTypeFunction = new LuaCSFunction( this.importType );
            loadAssemblyFunction = new LuaCSFunction( this.loadAssembly );
            registerTableFunction = new LuaCSFunction( this.registerTable );
            unregisterTableFunction = new LuaCSFunction( this.unregisterTable );
            getMethodSigFunction = new LuaCSFunction( this.getMethodSignature );
            getConstructorSigFunction = new LuaCSFunction( this.getConstructorSignature );

            createLuaObjectList( luaState );
            createIndexingMetaFunction( luaState );
            createBaseClassMetatable( luaState );
            createClassMetatable( luaState );
            createFunctionMetatable( luaState );
            setGlobalFunctions( luaState );
        }
Exemplo n.º 12
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.º 13
0
        public WSSources <T> Clone(ref WSUserDBSet DBSet, MetaFunctions Func)
        {
            WSSources <T> srcs = new WSSources <T>();

            try
            {
                foreach (T src in this)
                {
                    if (src is WSTableSource)
                    {
                        WSSource tSrc = DBSet == null ? (src as WSTableSource).Clone(Func) : (src as WSTableSource).Clone(Func, DBSet.DBSession.user.role);

                        srcs.Add((T)tSrc);
                    }
                    else
                    {
                        srcs.Add((src as WSSource).Clone(Func, DBSet.DBSession.user.role, false) as T);
                    }
                }
            }
            catch (Exception) { }
            return(srcs);
        }
Exemplo n.º 14
0
 public override WSFilter GetOptionFilter(MetaFunctions CFunc, Expression parent, int level, string state = null, bool?negate = null)
 {
     try
     {
         if (Value.IsTrue() || Value.IsFalse())
         {
             return(new WSBoolOFilter(this));
         }
         else if (WSConstants.SPECIAL_CASES.Any(x => x.Match(Value)))
         {
             state = Value;
             if (parent.Type.IsSameOrSubclassOf(typeof(WSEntity)) || parent.Type.IsCollectionOf <WSEntity>())
             {
                 WSTableSource Source = (WSTableSource)CFunc.GetSourceByType/*<WSTableSource>*/ (parent.Type);
                 if (parent.Type.IsSameOrSubclassOf(typeof(WSEntity)) && WSEntityFFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(state)))
                 {
                     return(new WSEntityFilter(Source, parent, WSEntityFFilter.OPERATIONS.STATE_OPERATIONS.FirstOrDefault(x => x.Match(state))));
                 }
             }
         }
     }
     catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); }
     return(null);
 }
Exemplo n.º 15
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.º 16
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.º 17
0
 public WSV1ResponseRecord(MetaFunctions _CFunc)
     : base(_CFunc, null, WSAccessMode.READ.ACCESS_LEVEL)
 {
 }
Exemplo n.º 18
0
 public V1SystemResponseRecord(MetaFunctions _CFunc, V1SystemResponseEntity _entity, byte _role, string _RootName = null) : base(_CFunc, _entity, _role, _RootName)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MiscFunctions"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 /// <remarks></remarks>
 public MiscFunctions(Map map)
 {
     this.map = map;
     ForMeta = new MetaFunctions(map);
 }
Exemplo n.º 20
0
 public WSRedirectRecord(MetaFunctions _CFunc, WSAuthEntity auth, Uri _RedirectToUrl = null) : base(_CFunc, auth, null)
 {
     RedirectToUrl = _RedirectToUrl;
 }
Exemplo n.º 21
0
 public V1SystemResponseRecord(MetaFunctions _CFunc) : base(_CFunc, null, WSAccessMode.READ.ACCESS_LEVEL, null)
 {
 }
Exemplo n.º 22
0
 public WSSchema(MetaFunctions _Func, WSEntitySchema _Parent) { Func = _Func; Parent = _Parent; }
Exemplo n.º 23
0
 public WSMemberSchema(MetaFunctions _Func, WSEntitySchema _Parent) : base(_Func, _Parent)
 {
 }
Exemplo n.º 24
0
 public abstract WSFilter GetOptionFilter(MetaFunctions CFunc, Expression parent, int level, string state = null, bool?negate = null);
Exemplo n.º 25
0
 public abstract Expression SortTable <T>(MetaFunctions CFunc, WSDataContext dc, List <PropertyInfo> parents, Expression expression, ref WSStatus iostatus);
Exemplo n.º 26
0
 public abstract bool MatchEntity(MetaFunctions CFunc, WSDynamicEntity entity, WSTableSource src, string key = null, string matchOperation = null);
Exemplo n.º 27
0
 public abstract WSFilter GetFieldFilter(MetaFunctions CFunc, WSTableParam param, Expression parent, int level, string state = null, bool?negate = null);
Exemplo n.º 28
0
 internal abstract bool applyInternal(WSRequest request, MetaFunctions CFunc);
Exemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MiscFunctions"/> class.
 /// </summary>
 /// <param name="map">The map.</param>
 /// <remarks></remarks>
 public MiscFunctions(Map map)
 {
     this.map = map;
     ForMeta  = new MetaFunctions(map);
 }
Exemplo n.º 30
0
 public WSSystemRecord(MetaFunctions _CFunc, WSSystemEntity _entity, byte _role) : base(_CFunc, _entity, _role)
 {
 }
Exemplo n.º 31
0
 public WSV1ResponseRecord(MetaFunctions _CFunc, WSV1ResponseEntity _entity, byte role_, string _RootName = null)
     : base(_CFunc, _entity, role_, _RootName)
 {
 }
Exemplo n.º 32
0
 public WSSecurityDefault(WSDynamicEntity _Session, string _SessionID, MetaFunctions _CFunc) : base(_Session, _SessionID, _CFunc)
 {
 }