private bool Match(ClientFunctions CFunc, WSDynamicEntity refEntity) { try { if (refEntity == null) { return(false); } else if (refEntity.GetType() != GetType()) { return(false); } else { Type orgType = GetType(); WSTableSource orgSrc = (WSTableSource)getSource(CFunc); IEnumerable <WSTableParam> orgParams = orgSrc.DBParams.Where(p => p.DataType.IsSimple()); Type refType = refEntity.GetType(); WSTableSource refSrc = ((WSTableSource)CFunc.GetSourceByType(refType)); IEnumerable <WSTableParam> refParams = refSrc.DBParams.Where(p => p.DataType.IsSimple()); IEnumerable <WSTableParam> orgExceptParams = orgParams.Where(p1 => !refParams.Any(p2 => p2.Match(p1))); IEnumerable <WSTableParam> refExceptParams = refParams.Where(p1 => !orgParams.Any(p2 => p2.Match(p1))); if (orgExceptParams.Any() || refExceptParams.Any()) { return(false); } else { foreach (WSTableParam param in orgParams) { object orgInfo = orgType.GetProperties().FirstOrDefault(p => p.Name.Equals(param.WSColumnRef.NAME)).GetValue(this, null); object refInfo = refType.GetProperties().FirstOrDefault(p => p.Name.Equals(param.WSColumnRef.NAME)).GetValue(refEntity, null); if (!(orgInfo == null && refInfo == null) && !orgInfo.ToString().Equals(refInfo.ToString())) { return(false); } } return(true); } } } catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status, $"Match():321"); } return(false); }
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); }
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); }
private WSSession ReadWSSession(string dbName) { WSSession session = null; if (!string.IsNullOrEmpty(dbName)) { try { WSSecurityMeta meta = SecurityMap[dbName]; session = new WSSession(Request.SessionID, meta); /********************** * ANDVO@NOTE: * DO NOT do [ZoneContext = Request.ZoneContext;] * because it will use Request's zone, when it MUST BE zone for the argument:'dbName' !!! * */ using (WSDataContext ZoneContext = GetInternalContext(meta.Zone, Request.ID, $"{GetType().Name}.ReadWSSession('{dbName}')")) { if (ZoneContext != null && !ZoneContext.IsDisposed && ZoneContext.Connection.State == System.Data.ConnectionState.Open) { if (meta.SessionType != null) { MethodInfo mInfo = ZoneContext.GetType().GetMethod("GetTable", new Type[] { }); var tObj = mInfo.MakeGenericMethod(new Type[] { meta.SessionType }).Invoke(ZoneContext, new object[] { }); Func <WSDynamicEntity, bool> func = s => s.readPropertyValue(WSConstants.PARAMS.SESSIONID.NAME, "").ToString().ToLower().Equals(Request.SessionID.ToLower()); MethodInfo[] methods = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public); var method = methods.FirstOrDefault(m => m.Name == "FirstOrDefault" && m.GetParameters().Count() == 2).MakeGenericMethod(typeof(WSDynamicEntity)); WSDynamicEntity sessionEntity = (WSDynamicEntity)method.Invoke(null, new object[] { tObj, func }); if (sessionEntity != null) { WSDynamicEntity userEntity = (WSDynamicEntity)sessionEntity.GetType().GetProperties().Single(x => x.PropertyType == meta.UserType).GetValue(sessionEntity, null); if (userEntity != null) { object _id = userEntity.TryReadPropertyValue("UserID", out _id) ? _id : null; object _email = userEntity.TryReadPropertyValue("Email", out _email) ? _email : null; object _firstname = userEntity.TryReadPropertyValue("FirstName", out _firstname) ? _firstname : null; object _lastname = userEntity.TryReadPropertyValue("LastName", out _lastname) ? _lastname : null; object _isactive = userEntity.TryReadPropertyValue("IsActive", out _isactive) ? _isactive : null; object _login = userEntity.TryReadPropertyValue("Login", out _login) ? _login : null; WSDynamicEntity roleEntity = (WSDynamicEntity)userEntity.GetType().GetProperties().FirstOrDefault(x => x.PropertyType == meta.RoleType).GetValue(userEntity, null); if (roleEntity != null) { object _role = roleEntity.TryReadPropertyValue("ID", out _role) ? _role : null; object _roleName = roleEntity.TryReadPropertyValue("Name", out _roleName) ? _roleName : null; int id = int.TryParse(_id.ToString(), out id) ? id : -1; string email = _email != null?_email.ToString() : string.Empty; string login = _login != null?_login.ToString() : string.Empty; string firstname = _firstname != null?_firstname.ToString() : string.Empty; string lastname = _lastname != null?_lastname.ToString() : string.Empty; bool isactive = bool.TryParse(_isactive.ToString(), out isactive) ? isactive : false; byte role = byte.TryParse(_role == null ? null : _role.ToString(), out role) ? role : WSConstants.DEFAULT_USER_ROLE; string roleName = _roleName != null?_roleName.ToString() : string.Empty; session.user = new WSUserToken() { id = id, email = email, login = login, firstname = firstname, lastname = lastname, isactive = isactive, role = role, roleName = roleName }; } } } } } } } catch (Exception e) { RegError(GetType(), e, ref LoadStatus); } } return(session); }
public override bool MatchEntity(MetaFunctions CFunc, WSDynamicEntity entity, WSTableSource src, string key = null, string matchOperation = null) { bool isMatch = true; try { if (!IsValid) { isMatch = false; } else { if (string.IsNullOrEmpty(key)) { key = Key; } else { matchOperation = Key; } if (Value is WSJValue) { isMatch = ((WSJValue)Value).MatchEntity(CFunc, entity, src, key, matchOperation); } else { if (src.DBAssociationParams.Any(p => p.Match(Key))) { WSTableParam param = src.DBAssociationParams.FirstOrDefault(p => p.Match(Key)); src = (WSTableSource)CFunc.GetSourceByType(param.DataType.GetEntityType()); object oEntity = entity.GetType().GetProperty(param.WSColumnRef.NAME).GetValue(entity, null); if (oEntity.GetType().IsCollectionOf <WSDynamicEntity>()) { foreach (WSDynamicEntity e in (IEnumerable <WSDynamicEntity>)oEntity) { if (Value is WSJObject) { if (((WSJObject)Value).MatchEntity(CFunc, e, src)) { isMatch = true; } } else if (Value is WSJArray) { if (((WSJArray)Value).MatchEntity(CFunc, e, src)) { isMatch = true; } } } } else { if (Value is WSJObject) { isMatch = ((WSJObject)Value).MatchEntity(CFunc, (WSDynamicEntity)oEntity, src); } else if (Value is WSJArray) { isMatch = ((WSJArray)Value).MatchEntity(CFunc, (WSDynamicEntity)oEntity, src); } } } else { if (Value is WSJObject) { isMatch = ((WSJObject)Value).MatchEntity(CFunc, entity, src, key); } else if (Value is WSJArray) { isMatch = ((WSJArray)Value).MatchEntity(CFunc, entity, src, key); } } } } } catch (Exception e) { isMatch = false; WSStatus status = WSStatus.NONE.clone(); CFunc.RegError(GetType(), e, ref status); } return(isMatch); }