/// <summary>
        /// Executes the handler within the given <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="IMansionWebContext"/> in which to execute the current request.</param>
        /// <param name="outputPipe">The <see cref="WebOutputPipe"/> to which the must should be written.</param>
        protected override void DoExecute(IMansionWebContext context, WebOutputPipe outputPipe)
        {
            // retrieve the resource
            var originalResourcePath = context.Request.RequestUrl.Path.Substring(Prefix.Length + 1);
            var resourcePath = new RelativeResourcePath(originalResourcePath, true);

            // set output pipe properties
            outputPipe.Response.ContentType = WebUtilities.GetMimeType(originalResourcePath);
            outputPipe.Encoding = Encoding.UTF8;

            // if the resource does not exist, send a 404
            if (!resourceService.Exists(context, resourcePath))
            {
                // send 404
                outputPipe.Response.StatusCode = HttpStatusCode.NotFound;
                outputPipe.Response.StatusDescription = "Not Found";
                return;
            }

            // merge all the resources
            foreach (var resource in resourceService.Get(context, resourcePath))
            {
                // parse the resource script
                var script = scriptService.Parse(context, resource);

                // execute the script and write the result back to the output pipe
                outputPipe.Writer.Write(script.Execute<string>(context));
            }

            // set expires header age
            outputPipe.Response.CacheSettings.Expires = DateTime.Now.AddYears(1);
        }
        /// <summary>
        /// Executes the handler within the given <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="IMansionWebContext"/> in which to execute the current request.</param>
        /// <param name="outputPipe">The <see cref="WebOutputPipe"/> to which the must should be written.</param>
        protected override void DoExecute(IMansionWebContext context, WebOutputPipe outputPipe)
        {
            // retrieve the resource
            var originalResourcePath = context.Request.RequestUrl.Path.Substring(Prefix.Length + 1);
            var resourcePath = new RelativeResourcePath(originalResourcePath, false);

            // set output pipe properties
            outputPipe.Response.ContentType = WebUtilities.GetMimeType(originalResourcePath);
            outputPipe.Encoding = Encoding.UTF8;

            // if the resource exist process it otherwise 404
            if (!resourceService.Exists(context, resourcePath))
            {
                // send 404
                outputPipe.Response.StatusCode = HttpStatusCode.NotFound;
                outputPipe.Response.StatusDescription = "Not Found";
                return;
            }

            // parse the resource script
            var resource = resourceService.GetSingle(context, resourcePath);

            // stream the file
            using (var reader = resource.OpenForReading())
                reader.RawStream.CopyTo(outputPipe.RawStream);

            // set expires header age
            outputPipe.Response.CacheSettings.Expires = DateTime.Now.AddYears(1);
        }
        /// <summary>
        /// Executes the handler within the given <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="IMansionWebContext"/> in which to execute the current request.</param>
        /// <returns>Returns the <see cref="WebResponse"/>.</returns>
        protected override WebResponse DoExecute(IMansionWebContext context)
        {
            // create the response
            var response = WebResponse.Create(context);

            // create an web output pipe, push it to the stack and allow implementors to process the request on it
            using (var outputPipe = new WebOutputPipe(response))
            using (context.OutputPipeStack.Push(outputPipe))
                DoExecute(context, outputPipe);

            // return the response
            return response;
        }
        /// <summary>
        /// Executes the handler within the given <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="IMansionWebContext"/> in which to execute the current request.</param>
        /// <param name="outputPipe">The <see cref="WebOutputPipe"/> to which the must should be written.</param>
        protected override void DoExecute(IMansionWebContext context, WebOutputPipe outputPipe)
        {
            // retrieve the resource
            var originalResourcePath = context.Request.RequestUrl.Path.Substring(Prefix.Length + 1);

            // split the path
            var pathParts = originalResourcePath.Split(Dispatcher.Constants.UrlPartTrimCharacters, StringSplitOptions.RemoveEmptyEntries);

            // parse the path
            var contentPath = contentService.ParsePath(context, new PropertyBag {
                {"category", pathParts[0]},
                {"relativePath", string.Join(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), pathParts)}
            });

            // set output pipe properties
            outputPipe.Response.ContentType = WebUtilities.GetMimeType(originalResourcePath);
            outputPipe.Encoding = Encoding.UTF8;

            // if the resource exist process it otherwise 404
            if (contentService.Exists(context, contentPath))
            {
                // parse the resource script
                var resource = contentService.GetResource(context, contentPath);
                var len = resource.Length;

                // stream the file
                var buffer = new byte[1024];
                using (var reader = resource.OpenForReading())
                {
                    int bytes;
                    while (len > 0 && (bytes = reader.RawStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        outputPipe.RawStream.Write(buffer, 0, bytes);
                        len -= bytes;
                    }
                }

                // set cache age
                outputPipe.Response.CacheSettings.Expires = DateTime.Now.AddYears(1);
            }
            else
            {
                // send 404
                outputPipe.Response.StatusCode = HttpStatusCode.NotFound;
                outputPipe.Response.StatusDescription = "Not Found";
            }
        }
        /// <summary>
        /// Executes the handler within the given <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="IMansionWebContext"/> in which to execute the current request.</param>
        /// <param name="outputPipe">The <see cref="WebOutputPipe"/> to which the must should be written.</param>
        protected override void DoExecute(IMansionWebContext context, WebOutputPipe outputPipe)
        {
            // always disable cache for backoffice users
            if (context.BackofficeUserState.IsAuthenticated)
                outputPipe.Response.CacheSettings.OutputCacheEnabled = false;

            // determine path to the script which to execute
            var scriptPath = new RelativeResourcePath(context.Request.RequestUrl.Path, false);

            // check if the request is to an actual script file, use the default script in that case
            if (!resourceService.Exists(context, scriptPath))
                scriptPath = context.IsBackoffice ? DefaultBackofficePath : DefaultFrontofficePath;

            // parse the script
            using (var script = scriptService.Parse(context, resourceService.GetSingle(context, scriptPath)))
            {
                script.Initialize(context);
                script.Execute(context);
            }
        }
 /// <summary>
 /// Executes the handler within the given <paramref name="context"/>.
 /// </summary>
 /// <param name="context">The <see cref="IMansionWebContext"/> in which to execute the current request.</param>
 /// <param name="outputPipe">The <see cref="WebOutputPipe"/> to which the must should be written.</param>
 protected abstract void DoExecute(IMansionWebContext context, WebOutputPipe outputPipe);