Example #1
0
        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);
        }
        protected override string OneMinTicket(DateTime?_initTime = default(DateTime?))
        {
            DateTime initTime = _initTime == null ? DateTime.Now : (DateTime)_initTime;
            string   key1     = string.Empty;

            try { new OBMWS.WSConverter().ToMd5Hash(initTime.ToString("yyyyMMddhhmm"), out key1, true); } catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); WSServerMeta.LogError(GetType(), e, ref status); }
            return(key1);
        }