/// <summary>
        /// Get a file
        /// </summary>
        /// <param name="context">Context used to locate and return files</param>
        public virtual bool GetFile(FileContext context)
        {
            var fullPath = GetFullPath(context.Request.Uri);
            if (fullPath == null || !File.Exists(fullPath))
                return false;

            var streamPath = fullPath;

            if (_substituteGzipFiles && context.Request.Headers["Accept-Encoding"] != null && 
                context.Request.Headers["Accept-Encoding"].Contains("gzip"))
            {
                var compressedPath = fullPath + ".gz";
                if (File.Exists(compressedPath))
                {
                    streamPath = compressedPath;
                    context.SetGzipSubstitute();
                }
            }

            var date = File.GetLastWriteTimeUtc(fullPath);

            // browser ignores second fractions.
            date = date.AddTicks(-(date.Ticks % TimeSpan.TicksPerSecond));

            if (date <= context.BrowserCacheDate)
            {
                context.SetNotModified(fullPath, date);
                return true;
            }

            var stream = new FileStream(streamPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            context.SetFile(fullPath, stream, date);
            return true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a file
        /// </summary>
        /// <param name="context">Context used to locate and return files</param>
        public virtual bool GetFile(FileContext context)
        {
            var fullPath = GetFullPath(context.Request.Uri);

            if (fullPath == null || !File.Exists(fullPath))
            {
                return(false);
            }


            var date = File.GetLastWriteTimeUtc(fullPath);

            // browser ignores second fractions.
            date = date.AddTicks(-(date.Ticks % TimeSpan.TicksPerSecond));

            if (date <= context.BrowserCacheDate)
            {
                context.SetNotModified(fullPath, date);
                return(true);
            }

            var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            context.SetFile(fullPath, stream, date);
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Get a file
        /// </summary>
        /// <param name="context">Context used to locate and return files</param>
        public virtual bool GetFile(FileContext context)
        {
            var fullPath = GetFullPath(context.Request.Uri);

            if (fullPath == null)
            {
                return(false);
            }

            if (fullPath == _basePath)
            {
                fullPath = GetDefaultFile();
            }

            if (!File.Exists(fullPath))
            {
                return(false);
            }

            var streamPath = fullPath;

            if (_substituteGzipFiles && context.Request.Headers["Accept-Encoding"] != null &&
                context.Request.Headers["Accept-Encoding"].Contains("gzip"))
            {
                var compressedPath = fullPath + ".gz";
                if (File.Exists(compressedPath))
                {
                    streamPath = compressedPath;
                    context.SetGzipSubstitute();
                }
            }

            var date = File.GetLastWriteTimeUtc(fullPath);

            // browser ignores second fractions.
            date = date.AddTicks(-(date.Ticks % TimeSpan.TicksPerSecond));

            if (date <= context.BrowserCacheDate)
            {
                context.SetNotModified(fullPath, date);
                return(true);
            }

            var stream = new FileStream(streamPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            context.SetFile(fullPath, stream, date);
            return(true);
        }
        /// <summary>
        /// Get a file
        /// </summary>
        /// <param name="context">Context used to locate and return files</param>
        public virtual bool GetFile(FileContext context)
        {
            var fullPath = GetFullPath(context.Request.Uri);
            if (fullPath == null || !File.Exists(fullPath))
                return false;


            var date = File.GetLastWriteTimeUtc(fullPath);
            if (date <= context.BrowserCacheDate)
            {
                context.SetNotModified(fullPath, date);
                return true;
            }

            var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            context.SetFile(fullPath, stream, date);
            return true;
        }
        /// <summary>
        /// Get a file
        /// </summary>
        /// <param name="context">Context used to locate and return files</param>
        public virtual bool GetFile(FileContext context)
        {
            var fullPath = GetFullPath(context.Request.Uri);
            if (fullPath == null || !File.Exists(fullPath))
                return false;


            var date = File.GetLastWriteTimeUtc(fullPath);

            // browser ignores second fractions.
            date = date.AddTicks(-(date.Ticks % TimeSpan.TicksPerSecond));

            if (date <= context.BrowserCacheDate)
            {
                context.SetNotModified(fullPath, date);
                return true;
            }

            var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            context.SetFile(fullPath, stream, date);
            return true;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get a file
        /// </summary>
        /// <param name="context">Context used to locate and return files</param>
        public virtual bool GetFile(FileContext context)
        {
            var fullPath = GetFullPath(context.Request.Uri);

            if (fullPath == null || !File.Exists(fullPath))
            {
                return(false);
            }


            var date = File.GetLastWriteTimeUtc(fullPath);

            if (date <= context.BrowserCacheDate)
            {
                context.SetNotModified(fullPath, date);
                return(true);
            }

            var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            context.SetFile(fullPath, stream, date);
            return(true);
        }