Пример #1
0
        public static MobiContext GetCurrent(HttpContext httpContext)
        {
            lock (httpContext.Request)
            {
                MobiContext mobiContext = httpContext.Items[MobiHttpContextItemKey] as MobiContext;
                if (mobiContext != null)
                {
                    return(mobiContext as MobiContext);
                }

                mobiContext = new MobiContext(httpContext, StatisticsApplication.GetRuntime(httpContext));
                httpContext.Items[MobiHttpContextItemKey] = mobiContext;
                return(mobiContext);
            }
        }
Пример #2
0
        protected virtual void InitializeRuntime()
        {
            if (StatisticsApplication.HasRuntime(this))
            {
                return;
            }

            lock (MobiHttpApplicationInitializeRuntimeLockObject)
            {
                //string name = HostingEnvironment.SiteName;
                if (StatisticsApplication.HasRuntime(this))
                {
                    return;
                }

                Data.Application application = MobiChat.Data.Application.CreateManager().Load(HostingEnvironment.SiteName);

                // SUMMARY: for testing from local
                if (application == null && HostingEnvironment.SiteName.Equals("MobiChat.Statistics"))
                {
                    application = MobiChat.Data.Application.CreateManager().Load(5);
                }
                if (application == null)
                {
                    //Log.Fatal(string.Format("Application {0} is not loaded.", HostingEnvironment.SiteName));
                    throw new InvalidOperationException(string.Format("No application with name '{0}' registered in database.", HostingEnvironment.SiteName));
                }

                this._baseApplication = new ApplicationBase(application);

                IRuntime runtime = this._baseApplication.ApplicationData.InstantiateRuntime();
                if (!runtime.Initialize(HostingEnvironment.SiteName))
                {
                    return;
                }

                StatisticsApplication.SetRuntime(this, runtime);

                Log.Debug(string.Format("Application {0} initialized!", HostingEnvironment.SiteName));
                this.InitializeApplication();
            }

            return;
        }
Пример #3
0
        protected virtual void InitializeSession(HttpContext httpContext)
        {
            string sessionID   = httpContext.Session.SessionID;
            Guid   sessionGuid = Guid.Empty;

            if (!Guid.TryParseExact(sessionID, "N", out sessionGuid))
            {
                // TODO: log4net
                //if (Log.IsWarnEnabled)
                //  Log.Warn(new LogMessageBuilder(
                //    new LogErrorCode("paywall.web.core", "paywallhttpcontext", "initializesession"),
                //      "Invalid session ID", sessionGuid));

                throw new ArgumentException("MobiContext: Could not parse Session guid");
            }

            IUserSessionManager usManager = UserSession.CreateManager();
            UserSession         session   = usManager.Load(sessionGuid);

            if (session != null && session.IPAddress != httpContext.Request.UserHostAddress)
            {
                // TODO: Session hijack.. log
            }

            if (session == null)
            {
                IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager();

                // TODO: Remove this in production
                string ipAddress = !httpContext.Request.UserHostAddress.Equals("::1") && !httpContext.Request.UserHostAddress.StartsWith("192.") ?
                                   httpContext.Request.UserHostAddress :
                                   "78.155.61.246";

                IPCountryMap countryMap = ipcmManager.Load(ipAddress);
                Language     language   = countryMap.Country.Language != null ? countryMap.Country.Language : Language.CreateManager().Load("EN", LanguageIdentifier.TwoLetterIsoCode);

                session = new UserSession(-1,
                                          sessionGuid,
                                          StatisticsApplication.GetDefaultUserSessionType(),
                                          null,     // service
                                          this.Runtime.ApplicationData,
                                          null,     // domain,
                                          null,     // user,
                                          countryMap.Country,
                                          language, // language
                                          null,     // mobileOperator
                                          null,     // trackingID,
                                          httpContext.Request.UserHostAddress,
                                          httpContext.Request.UserAgent,
                                          httpContext.Request.Url.ToString().Replace(" ", string.Empty),
                                          httpContext.Request.UrlReferrer != null ? httpContext.Request.UrlReferrer.ToString() : null,
                                          false,
                                          DateTime.Now.AddMinutes(20),
                                          DateTime.Now, DateTime.Now);

                session.Insert();

                //INFO: DO NOT DO ANYTHING WITH THIS LINE BELOW!!!
                httpContext.Session["someValue"] = "bla";
            }

            this._session = new StatisticsUserSession(session);
        }
Пример #4
0
 protected static void SetRuntime(HttpApplication application, IRuntime runtime)
 {
     StatisticsApplication.SetRuntime(application.Application, runtime);
 }
Пример #5
0
 protected static void SetRuntime(HttpContext context, IRuntime runtime)
 {
     StatisticsApplication.SetRuntime(context.Application, runtime);
 }
Пример #6
0
 public static IRuntime GetRuntime(HttpApplication application)
 {
     return(StatisticsApplication.GetRuntime(application.Application));
 }
Пример #7
0
 public static IRuntime GetRuntime(HttpContext context)
 {
     return(StatisticsApplication.GetRuntime(context.Application));
 }
Пример #8
0
 public static bool HasRuntime(HttpApplication application)
 {
     return(StatisticsApplication.HasRuntime(application.Application));
 }
Пример #9
0
 public static bool HasRuntime(HttpContext context)
 {
     return(StatisticsApplication.HasRuntime(context.Application));
 }