Пример #1
0
 public static WSJson ToJson(this string jText)
 {
     lock (ToJsonLock)
     {
         WSJson json = null;
         try
         {
             jText = jText == null ? null : jText.Trim();
             if (!string.IsNullOrEmpty(jText))
             {
                 //WSJObject
                 if ('{' == jText.FirstOrDefault() && '}' == jText.LastOrDefault())
                 {
                     json = JsonConvert.DeserializeObject <WSJson>(jText, new WSFilterConverter());
                 }
                 //WSJArray
                 else if ('[' == jText.FirstOrDefault() && ']' == jText.LastOrDefault())
                 {
                     WSJObject jObj = (WSJObject)JsonConvert.DeserializeObject <WSJson>("{json:" + jText + "}", new WSFilterConverter());
                     json = jObj.Value[0].Value;
                 }
                 //WSJValue
                 else
                 {
                     json = new WSJValue(jText);
                 }
             }
         }
         catch (Exception) { }
         return(json);
     }
 }
Пример #2
0
        internal void Configure(WSSource Source, WSJson json)
        {
            try
            {
                if (Source != null && json != null)
                {
                    if (json is WSJProperty && ((WSJProperty)json).Value is WSJValue)
                    {
                        WSJValue vJson = (WSJValue)((WSJProperty)json).Value;
                        switch (((WSJProperty)json).Key)
                        {
                        case "readaccess":
                            byte readAccessValue = byte.TryParse(vJson.Value, out readAccessValue) ? readAccessValue : READ_ACCESS_MODE.ACCESS_LEVEL;
                            READ_ACCESS_MODE = new WSAccessMode(readAccessValue, READ_ACCESS_MODE.OWNER_ACCESS_ALLOWED);
                            break;

                        case "writeaccess":
                            byte writeAccessValue = byte.TryParse(vJson.Value, out writeAccessValue) ? writeAccessValue : WRITE_ACCESS_MODE.ACCESS_LEVEL;
                            WRITE_ACCESS_MODE = new WSAccessMode(writeAccessValue, WRITE_ACCESS_MODE.OWNER_ACCESS_ALLOWED);
                            break;

                        case "skipempty":
                            bool skipempty = vJson.Value.IsTrue() ? true : vJson.Value.IsFalse() ? false : SkipEmpty;
                            SkipEmpty = skipempty;
                            break;

                        default: break;
                        }
                    }
                }
            }
            catch (Exception) { }
        }
Пример #3
0
 private void proceedRootParam(WSJValue param)
 {
     if (!WSConstants.ALIACES.SCHEMA.Match(param.Value) && !WSConstants.ALIACES.OUTPUT.Match(param.Value))
     {
         proceedFieldFilter(param, ref Fields);
     }
 }
Пример #4
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);
 }
Пример #5
0
        private void proceedFieldFilter(WSJValue jField, ref WSFieldFilters filters)
        {
            bool replace = true;
            List <WSMemberSchema> schemas = readFieldSchema(jField, out replace);

            if (schemas != null && schemas.Any())
            {
                foreach (WSMemberSchema schema in schemas)
                {
                    saveFieldSchema(schema, replace, ref filters);
                }
            }
            else
            {
                IOBaseOptions.Save(jField);
            }
        }
Пример #6
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);
        }
Пример #7
0
 public WSBoolOFilter(WSJValue option)
 {
     this.option = option;
 }
Пример #8
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);
        }