public void EnterPrivateSession <S>(WSDataContext db, ClientFunctions CFunc, WSTableSource SessionSrc, WSUserToken _user, string _1MinTicket, ref WSStatus statusLines, bool renew = false) where S : WSDynamicEntity { try { if (db != null) { if (ExitPrivateSession <S>(db, CFunc, SessionSrc, ref statusLines) && renew && _user.IsValid && ValidateOneMinTicket(_1MinTicket)) { try { AuthToken.User = _user; S _session = (S)Activator.CreateInstance(typeof(S), new object[] { }); setSession(DateTime.Now, SessionID, AuthToken.User.id, ref _session); db.GetTable <S>().InsertOnSubmit(_session); db.SubmitChanges(); Func <S, bool> func = s => s.readPropertyValue(WSConstants.PARAMS.SESSIONID.NAME, "").ToString().ToLower().Equals(SessionID.ToLower()); Session = db.GetTable <S>().FirstOrDefault(func); } catch (Exception e) { CFunc.RegError(GetType(), e, ref statusLines); Session = null; } } } if (Session != null) { setAuthToken(Session, ref _AuthToken); } } catch (Exception e) { CFunc.RegError(GetType(), e, ref statusLines); } }
public bool ExitPrivateSession <S>(WSDataContext db, ClientFunctions CFunc, WSTableSource SessionSrc, ref WSStatus statusLines) where S : WSDynamicEntity { bool DEAUTHORIZED = false; try { AuthToken.issued = DateTime.MinValue; AuthToken.expires = DateTime.MinValue; AuthToken.expires_in = 0; AuthToken.User = null; if (Session == null) { DEAUTHORIZED = true; } else { if (db != null) { //TODO@ANDVO:2016-11-09 : instead of looking for Primary Key value, - look for 'SessionID' field to make sure ALL related records will be removed string idName = SessionSrc.PrimParams.Any() && SessionSrc.PrimParams.Count() == 1 ? SessionSrc.PrimParams.Single().WSColumnRef.NAME : null; object idValue = null; if (Session.TryReadPropertyValue(idName, out idValue)) { ParameterExpression paramExp = Expression.Parameter(SessionSrc.ReturnType, "x"); Expression <Func <S, bool> > expr = new WSJValue(idValue.ToString()).GetFieldFilter(CFunc, (WSTableParam)SessionSrc.GetXParam(idName), paramExp, 0).ToLambda <S>(paramExp); S delItem = db.GetTable <S>().FirstOrDefault(expr); db.GetTable <S>().DeleteOnSubmit(delItem); db.SubmitChanges(); DEAUTHORIZED = true; } } } if (DEAUTHORIZED) { AuthToken.status = WSConstants.AUTH_STATES.DEAUTHORIZED; } } catch (Exception e) { CFunc.RegError(GetType(), e, ref statusLines); AuthToken.status = WSConstants.AUTH_STATES.FAILED_DEAUTHORIZE; } finally { WSServerMeta.ClearCache(SessionID); } return(DEAUTHORIZED); }