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); }
private void proceedRootParam(WSJArray jArr) { if (jArr.Value.Any()) { proceedRootParam(jArr.Value[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); }
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); }
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) { } }
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); }
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; } } }
private void proceedFieldFilter(WSJArray jArr, ref WSFieldFilters filters) { proceedFieldFilter(jArr.Value[0], ref filters); }
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 { WSJArray jArr1 = (WSJArray)json; IEnumerable <WSJValue> jValues = Value.OfType <WSJValue>(); jValues = jValues == null ? new List <WSJValue>() : jValues; IEnumerable <WSJValue> jValues1 = jArr1.Value.OfType <WSJValue>(); jValues1 = jValues1 == null ? new List <WSJValue>() : jValues1; if (!jValues.Any() && !jValues1.Any()) { } else { if (jValues.Count() > jValues1.Count()) { status = WSStatus.ERROR_Copy(); status.AddNote($"Extra properties generated by the current service:[{jValues.Where(p1 => !jValues1.Any(p => p1.Value.Equals(p.Value))).Select(x => x.Value).Aggregate((a, b) => a + "," + b)}]"); return(false); } else { WSStatus subStatus = WSStatus.NONE_Copy(); foreach (WSJValue jVal1 in jValues1) { status = jValues.Any(jVal => jVal1.Match(jVal, out subStatus)) ? WSStatus.SUCCESS_Copy() : subStatus; if (status.CODE != WSStatus.SUCCESS.CODE) { return(false); } } } } IEnumerable <WSJObject> jObjects = Value.OfType <WSJObject>(); jObjects = jObjects == null ? new List <WSJObject>() : jObjects; IEnumerable <WSJObject> jObjects1 = jArr1.Value.OfType <WSJObject>(); jObjects1 = jObjects1 == null ? new List <WSJObject>() : jObjects1; if (!jObjects.Any() && !jObjects1.Any()) { } else { if (jObjects.Count() > jObjects1.Count()) { status = WSStatus.ERROR_Copy(); status.AddNote($"Extra objects generated by the current service"); return(false); } else { WSStatus subStatus = WSStatus.NONE_Copy(); foreach (WSJObject jObj1 in jObjects1) { status = jObjects.Any(jObj => jObj1.Match(jObj, out subStatus)) ? WSStatus.SUCCESS_Copy() : subStatus; if (status.CODE != WSStatus.SUCCESS.CODE) { return(false); } } } } IEnumerable <WSJArray> jArrays = Value.OfType <WSJArray>(); jArrays = jArrays == null ? new List <WSJArray>() : jArrays; IEnumerable <WSJArray> jArrays1 = jArr1.Value.OfType <WSJArray>(); jArrays1 = jArrays1 == null ? new List <WSJArray>() : jArrays1; if (!jArrays.Any() && !jArrays1.Any()) { } else { if (jArrays.Count() > jArrays1.Count()) { status = WSStatus.ERROR_Copy(); status.AddNote($"Extra arrays generated by the current service"); return(false); } else { WSStatus subStatus = WSStatus.NONE_Copy(); foreach (WSJArray jObj1 in jArrays1) { status = jArrays.Any(jObj => jObj1.Match(jObj, out subStatus)) ? WSStatus.SUCCESS_Copy() : subStatus; if (status.CODE != WSStatus.SUCCESS.CODE) { return(false); } } } } status = WSStatus.SUCCESS_Copy(); } } catch (Exception) { } return(status.CODE == WSStatus.SUCCESS.CODE); }
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); }