Exemple #1
0
        /// <summary>
        /// Loads the request session
        /// </summary>
        /// <param name="context">Nancy context</param>
        /// <param name="sessionStore">Session store</param>
        /// <returns>Always returns null</returns>
        private static Response LoadSession(NancyContext context, RedisBasedSessions sessionStore)
        {
            if (context.Request == null)
            {
                return(null);
            }

            context.Request.Session = sessionStore.Load(context.Request);

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Initialise and add redis based session hooks to the application pipeine
        /// </summary>
        /// <param name="pipelines">Application pipelines</param>
        /// <param name="configuration">Redis based sessions configuration.</param>
        /// <returns>Formatter selector for choosing a non-default serializer</returns>
        public static IObjectSerializerSelector Enable(IPipelines pipelines, RedisBasedSessionsConfiguration configuration)
        {
            if (pipelines == null)
            {
                throw new ArgumentNullException("pipelines");
            }

            var sessionStore = new RedisBasedSessions(configuration);

            pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => LoadSession(ctx, sessionStore));
            pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => SaveSession(ctx, sessionStore));

            return(sessionStore);
        }
Exemple #3
0
 /// <summary>
 /// Saves the request session into the response
 /// </summary>
 /// <param name="context">Nancy context</param>
 /// <param name="sessionStore">Session store</param>
 private static void SaveSession(NancyContext context, RedisBasedSessions sessionStore)
 {
     sessionStore.Save(context.Request.Session, context.Response);
 }
        /// <summary>
        /// Initialise and add redis based session hooks to the application pipeine
        /// </summary>
        /// <param name="pipelines">Application pipelines</param>
        /// <param name="configuration">Redis based sessions configuration.</param>
        /// <returns>Formatter selector for choosing a non-default serializer</returns>
        public static IObjectSerializerSelector Enable(IPipelines pipelines, RedisBasedSessionsConfiguration configuration)
        {
            if (pipelines == null)
            {
                throw new ArgumentNullException("pipelines");
            }

            var sessionStore = new RedisBasedSessions(configuration);

            pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => LoadSession(ctx, sessionStore));
            pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => SaveSession(ctx, sessionStore));

            return sessionStore;
        }
        /// <summary>
        /// Loads the request session
        /// </summary>
        /// <param name="context">Nancy context</param>
        /// <param name="sessionStore">Session store</param>
        /// <returns>Always returns null</returns>
        private static Response LoadSession(NancyContext context, RedisBasedSessions sessionStore)
        {
            if (context.Request == null)
            {
                return null;
            }

            context.Request.Session = sessionStore.Load(context.Request);

            return null;
        }
 /// <summary>
 /// Saves the request session into the response
 /// </summary>
 /// <param name="context">Nancy context</param>
 /// <param name="sessionStore">Session store</param>
 private static void SaveSession(NancyContext context, RedisBasedSessions sessionStore)
 {
     sessionStore.Save(context.Request.Session, context.Response);
 }