예제 #1
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);
 }
예제 #2
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);
 }
예제 #3
0
 private void proceedRootParam(WSJProperty jProp)
 {
     if (WSConstants.ALIACES.SCHEMA.Match(jProp.Key))
     {
         List <WSJson> items = jProp.Value is WSJArray ? ((WSJArray)jProp.Value).Value : jProp.Value is WSJObject ? ((WSJObject)jProp.Value).Value.ToList <WSJson>() : new List <WSJson> {
             jProp.Value
         };
         Filters.CombineMode = jProp.Value is WSJArray ? WSCombineFilter.SQLMode.OrElse : WSCombineFilter.SQLMode.AndAlso;
         foreach (WSJson item in items)
         {
             proceedFieldFilter(item, ref Filters);
         }
     }
     else if (WSConstants.ALIACES.OUTPUT.Match(jProp.Key))
     {
         List <WSJson> items = jProp.Value is WSJArray ? ((WSJArray)jProp.Value).Value : jProp.Value is WSJObject ? ((WSJObject)jProp.Value).Value.ToList <WSJson>() : new List <WSJson> {
             jProp.Value
         };
         Fields.CombineMode = jProp.Value is WSJArray ? WSCombineFilter.SQLMode.OrElse : WSCombineFilter.SQLMode.AndAlso;
         foreach (WSJson item in items)
         {
             proceedFieldFilter(item, ref Fields);
         }
     }
     else
     {
         proceedFieldFilter(jProp, ref Fields);
     }
 }
예제 #4
0
        private void setUp(WSJProperty _Json)//Json = > {source:[id,name,...]}  or {source:{id:1,name:abc,...}}  or {source:{filters:[],fields:{id:1,name:abc,...}}}
        {
            if (Source != null && _Json.IsValid)
            {
                OriginalJson = new WSJObject(new List <WSJProperty> {
                    _Json
                });
                Name = _Json.Key;

                List <WSJson> jFields = new List <WSJson>();

                CombineMode        = _Json.Value is WSJObject ? WSCombineFilter.SQLMode.AndAlso : _Json.Value is WSJArray ? CombineMode = WSCombineFilter.SQLMode.OrElse : WSCombineFilter.SQLMode.AndAlso;
                Fields.CombineMode = CombineMode;

                if (_Json.Value is WSJObject)       //Json = > {source:/***{JFIELDS}***/}  or {source:/***{filters:JFIELDS,fields:JFIELDS}***/}
                {                                   //                     ---------                      --------------------------------
                    jFields.AddRange(((WSJObject)_Json.Value).Value);
                }
                else if (_Json.Value is WSJArray)   //Json = > {source:/***[JFIELDS]***/}  or {source:/***[{filters:JFIELDS},{fields:JFIELDS}]***/}
                {                                   //                     ---------                      ------------------------------------
                    jFields.AddRange(((WSJArray)_Json.Value).Value);
                }
                else if (_Json.Value is WSJValue)   //Json = > {source:/***[JFIELD]***/}  or {source:/***[{filters:JFIELD},{fields:JFIELD}]***/}
                {                                   //                     ---------                      ------------------------------------
                    jFields.Add(_Json.Value);
                }

                foreach (WSJson item in jFields)
                {
                    proceedRootParam(item);
                }
            }
        }
예제 #5
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);
 }
예제 #6
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);
     }
 }
예제 #7
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); }
 }
예제 #8
0
        internal WSJObject getFieldsJson(byte UserRole, List <Type> readChildes = null, string aliace = null)
        {
            if (UserRole <= WSConstants.ACCESS_LEVEL.READ)
            {
                return(getBaseJson(UserRole));
            }                                                                                //make sure hide multilevel for not registered users
            else if (Source != null && !Source.IsBase)
            {
                WSJArray    jFields = new WSJArray();
                WSJProperty jProp   = new WSJProperty(string.IsNullOrEmpty(aliace) ? Name.ToLower() : aliace, jFields);
                WSJObject   json    = new WSJObject(new List <WSJProperty> {
                    jProp
                });
                if (Fields != null && Fields.Any())
                {
                    IEnumerable <WSBaseSchema> acessibleSchemaes = Fields.Where(x =>
                                                                                (x is WSPrimitiveFieldSchema && UserRole >= ((WSPrimitiveFieldSchema)x).param.READ_ACCESS_MODE.ACCESS_LEVEL)
                                                                                ||
                                                                                (x is WSEntityFieldSchema && UserRole >= ((WSEntityFieldSchema)x).SOURCE.AccessLevel)
                                                                                );
                    if (acessibleSchemaes != null && acessibleSchemaes.Any())
                    {
                        List <WSJson> _fields = new List <WSJson>();
                        foreach (WSBaseSchema f in acessibleSchemaes)
                        {
                            if (f is WSPrimitiveFieldSchema)
                            {
                                _fields.Add(new WSJValue(((WSPrimitiveFieldSchema)f).param.DISPLAY_NAME.ToLower()));
                            }
                            else if (f is WSEntityFieldSchema)
                            {
                                List <Type> _readChildes = new List <Type>()
                                {
                                };
                                if (readChildes != null)
                                {
                                    _readChildes.AddRange(readChildes);
                                }

                                if (!_readChildes.Any(p => p == Source.ReturnType))
                                {
                                    _readChildes.Add(Source.ReturnType);
                                    _fields.Add(((WSEntityFieldSchema)f).SOURCE.BaseSchema.getFullJson(UserRole, _readChildes, ((WSEntityFieldSchema)f).param.DISPLAY_NAME.ToLower()));
                                }
                            }
                        }
                        jFields.Value = _fields != null && _fields.Any(x => x != null) ? _fields.Where(x => x != null).ToList() : new List <WSJson>();
                    }
                }
                return(json);
            }
            return(null);
        }
예제 #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);
        }
예제 #10
0
        private void proceedFieldFilter(WSJProperty jField, ref WSFieldFilters filters)
        {
            bool replace = true;
            List <WSMemberSchema> schemas = readFieldSchema(jField, out replace);

            if (schemas.Any())
            {
                foreach (WSMemberSchema schema in schemas)
                {
                    saveFieldSchema(schema, replace, ref filters);
                }
            }
            else
            {
                IOBaseOptions.Save(new WSJObject(new List <WSJProperty> {
                    jField
                }));
            }
        }
예제 #11
0
        protected override WSJson ToJson(JToken token)
        {
            WSJson json = null;

            if (token != null)
            {
                try
                {
                    if (token is JValue)
                    {
                        JValue inner = (JValue)token;
                        json = new WSJValue(inner.Value == null ? null : inner.Value.ToString());
                    }
                    else if (token is JProperty)
                    {
                        JProperty inner = (JProperty)token;
                        json = new WSJProperty(inner.Name, ToJson(inner.Value));
                    }
                    else if (token is JArray)
                    {
                        JArray   inner  = (JArray)token;
                        WSJArray jArray = new WSJArray();
                        jArray.Value.AddRange(inner.Select(x => ToJson(x)).Where(x => x.IsValid));
                        json = jArray;
                    }
                    else if (token is JObject)
                    {
                        JObject inner = (JObject)token;
                        IEnumerable <WSJProperty> props = inner.Children <JProperty>().Select(x => new WSJProperty(x.Name, ToJson(x.Value)));
                        WSJObject jObject = new WSJObject(props.ToList());
                        json = jObject;
                    }
                }
                catch (Exception) { }
            }
            return(json);
        }
예제 #12
0
        private WSJProperty mergeFilters(WSJson baseFilter, WSJProperty dynamicFilter)
        {
            WSJProperty json = null;

            if (baseFilter == null || !baseFilter.IsValid)
            {
                json = dynamicFilter;
            }
            else
            {
                List <WSJProperty> fProps = new List <WSJProperty>();
                json = new WSJProperty(Source.NAME, new WSJObject(fProps));
                foreach (WSTableParam param in Source.DBParams)
                {
                    List <WSJProperty> mProps = new List <WSJProperty>();

                    WSJProperty bpjValue = getFieldJson(param, baseFilter);
                    if (bpjValue != null && bpjValue.IsValid)
                    {
                        mProps.Add(bpjValue);
                    }

                    if (dynamicFilter != null && dynamicFilter.IsValid)
                    {
                        WSJProperty dpjValue = getFieldJson(param, dynamicFilter);
                        if (dpjValue != null && dpjValue.IsValid)
                        {
                            mProps.Add(dpjValue);
                        }
                    }

                    fProps.AddRange(mProps);
                }
            }
            return(json);
        }
예제 #13
0
        internal override bool applyInternal(WSRequest Request, MetaFunctions CFunc)
        {
            if (Request != null)
            {
                try
                {
                    if (Value != null && Value.Any())
                    {
                        for (int i = 0; i < Value.Count; i++)
                        {
                            if (Value[i] is WSJObject)
                            {
                                WSJProperty prop = ((WSJObject)Value[i]).Value[0];
                                if (prop.Key.StartsWith("$"))
                                {
                                    string commandKey = prop.Key.TrimStart(new char[] { '$' });

                                    if (prop.Value is WSJObject && prop.Value.IsValid)
                                    {
                                        #region apply $match command
                                        if (WSConstants.COMMAND_KEYS.MATCH.Match(commandKey))
                                        {
                                            WSJProperty jMatch = ((WSJObject)prop.Value).Value[0];

                                            #region SET $currentuser validation Filter
                                            if (WSConstants.COMMAND_KEYS.CURRENT_USER.Match(jMatch.Key))
                                            {
                                                WSJson jUser = jMatch.Value.Clone();
                                                if (jUser != null && jUser.IsValid)
                                                {
                                                    Value[i] = new WSJValue(Request.Security.IsValidUser(jUser) ? "1" : "0");
                                                }
                                            }
                                            #endregion
                                        }
                                        #endregion

                                        #region apply $read command
                                        else if (WSConstants.COMMAND_KEYS.READ.Match(commandKey))
                                        {
                                            WSJProperty jTarget   = ((WSJObject)prop.Value).Value[0];
                                            string      targetKey = jTarget.Key.TrimStart(new char[] { '$' });

                                            #region SET $currentuser validation Filter
                                            if (WSConstants.COMMAND_KEYS.CURRENT_USER.Match(targetKey))
                                            {
                                                List <WSJson> items = new List <WSJson> {
                                                };
                                                try
                                                {
                                                    items.AddRange(
                                                        (Request.Security.WSCurrentUser != null && Request.Security.WSCurrentUser.entity != null ? Request.Security.WSCurrentUser.entity.read(CFunc, jTarget.Value) : new List <dynamic> {
                                                    })
                                                        .Select(x =>
                                                                new WSJValue((x as object).ToString())
                                                                )
                                                        );
                                                }
                                                catch (Exception e) { CFunc.RegError(GetType(), e, ref Request.status); }
                                                Value[i] = new WSJArray(items);
                                            }
                                            #endregion
                                        }
                                        #endregion

                                        continue;
                                    }
                                }
                            }
                            Value[i].apply(Request, CFunc);
                        }
                    }
                    return(true);
                }
                catch (Exception e) { CFunc.RegError(GetType(), e, ref Request.status); }
            }
            return(false);
        }
예제 #14
0
        private WSStatus WriteCollapsedValues(JsonWriter writer, JsonSerializer serializer, WSEntity entity, WSSource xSource, WSJson collapseOption, WSRequest Request, MetaFunctions CFunc)
        {
            WSStatus status = WSStatus.NONE_Copy();

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

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

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

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


                /*}
                 *
                 *******************************************************************************/
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref status); }
            return(status);
        }
예제 #15
0
 public WSEntityFieldSchema(MetaFunctions _Func, WSTableParam _Param, WSJProperty _Json, WSEntitySchema _Parent) : base(_Func, _Param, _Json, _Parent)
 {
 }
예제 #16
0
        public WSCall(HttpContext _InContext)
        {
            try
            {
                if (_InContext != null)
                {
                    INPUT = new Dictionary <string, string>();

                    #region READ POST PARAMETERS
                    if (_InContext.Request.HttpMethod.Equals("POST"))
                    {
                        #region READ FORM PARAMETERS
                        foreach (string fKey in _InContext.Request.Form.AllKeys)
                        {
                            if (!string.IsNullOrEmpty(fKey))
                            {
                                string fValue = _InContext.Request.Form[fKey];
                                INPUT.Save(fKey, fValue);
                            }
                        }
                        #endregion


                        string[]             allKeys    = _InContext.Request.Params.AllKeys;
                        IEnumerable <string> actualKeys = allKeys.Where(x => x != null && !WSConstants.STANDARD_ASP_URL_PARAMS.Select(p => p.ToLower()).Contains(x.ToLower()));
                        string[]             PKeys      = actualKeys.ToArray();

                        foreach (string PKey in _InContext.Request.Params)
                        {
                            if (!string.IsNullOrEmpty(PKey))
                            {
                                if (!WSConstants.STANDARD_ASP_URL_PARAMS.Any(x => x.Equals(PKey)))
                                {
                                    bool   isValid = true;
                                    string PVal    = _InContext.Request.Params[PKey];
                                    if (PKey.ToLower().Equals("url"))
                                    {
                                        string RawUrl = _InContext.Request.RawUrl;
                                        if (PVal.Equals(RawUrl))
                                        {
                                            isValid = false;
                                        }
                                        else
                                        {
                                            PVal = PVal.Split(new char[] { ',' }).FirstOrDefault(x => !x.ToLower().Equals(RawUrl.ToLower())); isValid = !string.IsNullOrEmpty(PVal);
                                        }
                                    }
                                    if (isValid)
                                    {
                                        INPUT.Save(PKey, PVal, false);
                                    }
                                }
                            }
                            else
                            {
                                string jValue = _InContext.Request.Params[PKey];
                                status.AddNote("POST: try saving empty key {" + PKey + ":" + jValue + "}", WSConstants.ACCESS_LEVEL.READ);
                                if (!string.IsNullOrEmpty(jValue))
                                {
                                    WSJson json = jValue.ToJson();
                                    if (json == null)
                                    {
                                        status.AddNote("POST:failed convert json {" + jValue + "}. Try autoresolve.", WSConstants.ACCESS_LEVEL.READ);
                                        json = ("{data:" + jValue + "}").ToJson();
                                        json = json != null && (json is WSJObject) ? ((WSJObject)json).Value[0].Value : null;
                                    }

                                    if (json == null)
                                    {
                                        status.AddNote("POST:failed convert json {" + jValue + "}", WSConstants.ACCESS_LEVEL.READ);
                                    }
                                    else
                                    {
                                        if (json is WSJArray)
                                        {
                                            WSJArray jArray = (WSJArray)json;
                                            foreach (WSJson innerJson in jArray.Value)
                                            {
                                                if (innerJson is WSJProperty)
                                                {
                                                    WSJProperty jProp = (WSJProperty)innerJson;
                                                    INPUT.Save(jProp.Key, jProp.Value.ToString(), false);
                                                }
                                            }
                                        }
                                        else if (json is WSJObject)
                                        {
                                            foreach (WSJProperty jProp in ((WSJObject)json).Value)
                                            {
                                                string jVal = Newtonsoft.Json.JsonConvert.SerializeObject(jProp.Value, new WSFilterConverter());
                                                INPUT.Save(jProp.Key, jVal, false);
                                            }
                                        }
                                        else if (json is WSJProperty)
                                        {
                                            WSJProperty jProp = (WSJProperty)json;
                                            string      jVal  = Newtonsoft.Json.JsonConvert.SerializeObject(jProp.Value, new WSFilterConverter());
                                            INPUT.Save(jProp.Key, jVal, false);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    #endregion

                    #region READ QUERY-STRING PARAMETERS
                    foreach (var queryParam in _InContext.Request.QueryString.Keys)
                    {
                        if (queryParam != null)
                        {
                            string qKey   = queryParam.ToString();
                            string qValue = _InContext.Request.QueryString[qKey];
                            INPUT.Save(qKey, qValue);
                        }
                    }
                    #endregion

                    #region READ ROUTE-DATA PARAM
                    foreach (var urlParam in _InContext.Request.RequestContext.RouteData.Values)
                    {
                        if (!WSConstants.STANDARD_ASP_URL_PARAMS.Select(p => p.ToLower()).Contains(urlParam.Key.ToLower()))
                        {
                            string uKey   = urlParam.Key;
                            string uValue = urlParam.Value.ToString();
                            INPUT.Save(uKey, uValue);
                        }
                    }
                    #endregion

                    SessionID = INPUT.Any(x => WSConstants.PARAMS.SESSIONID.Match(x.Key)) ? INPUT.FirstOrDefault(x => WSConstants.PARAMS.SESSIONID.Match(x.Key)).Value : string.Empty;
                    if (string.IsNullOrEmpty(SessionID))
                    {
                        if (_InContext.Session != null)
                        {
                            SessionID = _InContext.Session.SessionID;
                        }
                        else
                        {
                            SessionID = _InContext.Request.Params["ASP.NET_SessionId"];
                        }
                    }

                    IsLocal = _InContext.Request == null || _InContext.Request.IsLocal;

                    UserHostAddress = _InContext.Request.UserHostAddress;

                    HttpMethod = _InContext.Request.HttpMethod;

                    Url = _InContext.Request.Url;

                    Files = _InContext.Request.Files;
                }
            }
            catch (Exception) { }
        }
예제 #17
0
        internal override bool applyInternal(WSRequest Request, MetaFunctions CFunc)
        {
            try
            {
                if (Value != null && Value.IsValid)
                {
                    if (Value is WSJObject)
                    {
                        Func <WSJProperty, bool> READFunc = v => v.Key.StartsWith("$") && WSConstants.COMMAND_KEYS.READ.Match(v.Key.TrimStart(new char[] { '$' }));

                        WSJProperty READProperty = ((WSJObject)Value).Value.FirstOrDefault(READFunc);

                        if (READProperty != null)
                        {
                            string commandKey = READProperty.Key.TrimStart(new char[] { '$' });
                            WSJson temp       = new WSJArray();


                            #region MATCH / READ properties
                            //if (prop.Value is WSJObject && prop.Value.IsValid)
                            //{
                            //    #region apply $match command
                            //    if (WSConstants.COMMAND_KEYS.MATCH.Match(commandKey))
                            //    {
                            //        WSJProperty jMatch = ((WSJObject)prop.Value).Value[0];

                            //        #region SET $currentuser validation Filter
                            //        if (WSConstants.COMMAND_KEYS.CURRENT_USER.Match(jMatch.Key))
                            //        {
                            //            WSJson jUser = jMatch.Value.Clone();
                            //            if (jUser != null && jUser.IsValid)
                            //            {
                            //                Value[i] = new WSJValue(Request.Security.IsValidUser(jUser) ? "1" : "0");
                            //            }
                            //        }
                            //        #endregion
                            //    }
                            //    #endregion

                            //    #region apply $read command
                            //    else if (WSConstants.COMMAND_KEYS.READ.Match(commandKey))
                            //    {
                            //        WSJProperty jTarget = ((WSJObject)prop.Value).Value[0];
                            //        string targetKey = jTarget.Key.TrimStart(new char[] { '$' });

                            //        #region SET $currentuser validation Filter
                            //        if (WSConstants.COMMAND_KEYS.CURRENT_USER.Match(targetKey))
                            //        {
                            //            List<WSJson> items = new List<WSJson> { };
                            //            try
                            //            {
                            //                items.AddRange(
                            //                    (Request.Security.WSCurrentUser != null && Request.Security.WSCurrentUser.entity != null ? Request.Security.WSCurrentUser.entity.read(CFunc, jTarget.Value) : new List<dynamic> { })
                            //                    .Select(x =>
                            //                        new WSJValue((x as object).ToString())
                            //                    )
                            //                );
                            //            }
                            //            catch (Exception e) { CFunc.RegError(GetType(), e, ref Request.status); }
                            //            Value[i] = new WSJArray(items);
                            //        }
                            //        #endregion
                            //    }
                            //    #endregion

                            //    continue;
                            //}
                            #endregion


                            #region apply 'READ' property
                            if (WSConstants.COMMAND_KEYS.READ.Match(commandKey) && READProperty.Value.IsValid)
                            {
                                if (READProperty.Value is WSJObject)
                                {
                                    List <WSJProperty> props = ((WSJObject)READProperty.Value).Value;
                                    if (props != null && props.Any())
                                    {
                                        Func <WSJProperty, bool> CurUserFunc  = v => WSConstants.COMMAND_KEYS.CURRENT_USER.Match(v.Key);
                                        Func <WSJProperty, bool> ExplicitFunc = v => WSConstants.COMMAND_KEYS.EXPLICIT.Match(v.Key);

                                        if (props.Any(CurUserFunc))
                                        {
                                            #region SET $currentuser validation Filter
                                            WSJProperty CurrentUser = props.FirstOrDefault(CurUserFunc);
                                            if (CurrentUser != null /* && WSConstants.COMMAND_KEYS.CURRENT_USER.Match(CurrentUser.Key)*/)
                                            {
                                                List <WSJson> items = new List <WSJson> {
                                                };
                                                try
                                                {
                                                    items.AddRange(
                                                        (Request.Security.WSCurrentUser != null && Request.Security.WSCurrentUser.entity != null ? Request.Security.WSCurrentUser.entity.read(CFunc, CurrentUser.Value) : new List <dynamic> {
                                                    })
                                                        .Select(x =>
                                                                new WSJValue((x as object).ToString())
                                                                )
                                                        );
                                                }
                                                catch (Exception e) { CFunc.RegError(GetType(), e, ref Request.status); }
                                                temp = new WSJArray(items);
                                            }
                                            #endregion
                                        }
                                    }
                                }
                            }
                            #endregion


                            Value = temp;
                            return(true);
                        }
                    }
                }
                Value.apply(Request, CFunc);
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref Request.status); }
            return(false);
        }
예제 #18
0
 public WSEntityListSchema(WSTableParam _Param, WSJProperty _Json, MetaFunctions _Func, WSEntitySchema _Parent) : base(_Func, _Parent)
 {
     Param = _Param;
     if (_Json != null && !_Json.IsEmpty)
     {
         if (WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(_Json.Key)))
         {
             IOBaseOptions.Save(new WSJObject(new List <WSJProperty>()
             {
                 _Json
             }));
         }
         else if (_Json.Value != null)
         {
             if (_Json.Value is WSJArray)
             {
                 WSJArray arr  = (WSJArray)_Json.Value;
                 WSJArray temp = new WSJArray();
                 foreach (WSJson item in arr.Value)
                 {
                     if (item is WSJValue && WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)item).Value)))
                     {
                         IOBaseOptions.Save(item);
                     }
                     else
                     {
                         temp.Value.Add(item);
                     }
                 }
                 _Json.Value = temp;
             }
             else if (_Json.Value is WSJObject)
             {
                 WSJObject          obj       = (WSJObject)_Json.Value;
                 List <WSJProperty> tempItems = new List <WSJProperty>();
                 WSJObject          temp      = new WSJObject(tempItems);
                 WSJObject          baseLocal = new WSJObject(tempItems);
                 foreach (WSJProperty item in obj.Value)
                 {
                     if (WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(item.Key)))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else if (item.Value is WSJValue && WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)item.Value).Value)))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else if (item.Value is WSJArray && !item.Value.IsEmpty && !((WSJArray)item.Value).Value.Any(v => !(v is WSJValue) || !WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)v).Value))))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else if (item.Value is WSJObject && !item.Value.IsEmpty && !((WSJObject)item.Value).Value.Any(p => !(p.Value is WSJValue) || !WSEntityFilter.OPERATIONS.STATE_OPERATIONS.Any(x => x.Match(((WSJValue)p.Value).Value))))
                     {
                         baseLocal.Value.Add(item);
                     }
                     else
                     {
                         temp.Value.Add(item);
                     }
                 }
                 _Json.Value = temp;
                 if (!baseLocal.IsEmpty)
                 {
                     IOBaseOptions.Save(baseLocal);
                 }
             }
         }
     }
     if (Param != null)
     {
         EntitySchema = new WSEntitySchema((WSTableSource)Func.GetSourceByType(Param.DataType.GetEntityType()), _Json, Func, Parent);
         if (EntitySchema != null)
         {
             Name = EntitySchema.Name;
         }
     }
 }
예제 #19
0
        private List <WSMemberSchema> readFieldSchema(WSJProperty json, out bool replace)// json => WSJValue || WSJProperty || WSJObject
        {
            replace = true;
            List <WSMemberSchema> fSchema = new List <WSMemberSchema>();

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

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

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