Пример #1
0
        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); }
        }
Пример #2
0
        private WSDynamicEntity ReadSession(/*WSDataContext ZoneContext*/)
        {
            WSDynamicEntity entity = null;

            if (Meta != null && !string.IsNullOrEmpty(SessionID) && ZoneContext != null)
            {
                long init_ticks = DateTime.Now.Ticks;
                try
                {
                    status.AddNote("Zone:" + Meta.Zone, WSConstants.ACCESS_LEVEL.READ);

                    System.Reflection.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(SessionID.ToLower());

                    System.Reflection.MethodInfo[] methods = typeof(Enumerable).GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

                    var method = methods.FirstOrDefault(m => m.Name == "FirstOrDefault" && m.GetParameters().Count() == 2).MakeGenericMethod(typeof(WSDynamicEntity));

                    entity = (WSDynamicEntity)method.Invoke(null, new object[] { tObj, func });
                }
                catch (Exception e) { CFunc.RegError(GetType(), e, ref status); }

                //if (ZoneContext != null) ZoneContext.Close(/*SessionID*/);

                TimeSpan ticks1 = new TimeSpan(DateTime.Now.Ticks - init_ticks); init_ticks = DateTime.Now.Ticks;
            }
            return(entity);
        }