Beispiel #1
0
        public EmbeddedResourceEntityResponder(ICacheManager cacheManager, IMimeTyper mimeTyper, IHasher hasher, long maxFileSizeToServe, int bufferSize, MimeSettingProvider mimeSettingProvider, Assembly assembly, string resourcePath)
        {
            _assembly     = assembly;
            _resourcePath = resourcePath;

            ResourcePath      = string.Format("{0}.{1}", assembly.GetName().Name, resourcePath.Replace("/", "."));
            ResourceExtension = Path.GetExtension(ResourcePath);

            var version = _assembly.GetName().Version;

            ResourceLastModified = new DateTime(2000, 1, 1)
                                   .AddDays(version.Build)
                                   .AddSeconds(version.Revision * 2)
                                   .ToUniversalTime();

            using (var bodyStream = assembly.GetManifestResourceStream(ResourcePath))
            {
                if (bodyStream != null)
                {
                    ResourceSize = (int)bodyStream.Length;
                }
            }

            MimeSetting        = mimeSettingProvider.GetSetting(ResourceExtension.ToLower());
            BufferSize         = bufferSize;
            MaxFileSizeToServe = maxFileSizeToServe;
            Hasher             = hasher;
            MimeTyper          = mimeTyper;
            CacheManager       = cacheManager;
        }
        public EmbeddedResourceEntityResponder(ICacheManager cacheManager, IMimeTyper mimeTyper, IHasher hasher, long maxFileSizeToServe, int bufferSize, MimeSettingProvider mimeSettingProvider, Assembly assembly, string resourcePath)
        {
            _assembly = assembly;
            _resourcePath = resourcePath;

            ResourcePath = string.Format("{0}.{1}", assembly.GetName().Name, resourcePath.Replace("/", "."));
            ResourceExtension = Path.GetExtension(ResourcePath);

            var version = _assembly.GetName().Version;
            ResourceLastModified = new DateTime(2000, 1, 1)
                .AddDays(version.Build)
                .AddSeconds(version.Revision * 2)
                .ToUniversalTime();

            using (var bodyStream = assembly.GetManifestResourceStream(ResourcePath))
            {
                if (bodyStream != null)
                {
                    ResourceSize = (int)bodyStream.Length;
                }
            }

            MimeSetting = mimeSettingProvider.GetSetting(ResourceExtension.ToLower());
            BufferSize = bufferSize;
            MaxFileSizeToServe = maxFileSizeToServe;
            Hasher = hasher;
            MimeTyper = mimeTyper;
            CacheManager = cacheManager;
        }
 public FileEntityResponder(ICacheManager cacheManager, IRetryableFileOpener retryableFileOpener, IMimeTyper mimeTyper, IHasher hasher, long maxFileSizeToServe, int bufferSize, MimeSettingProvider mimeSettingProvider, FileInfo fileInfo)
 {
     CacheManager = cacheManager;
     RetryableFileOpener = retryableFileOpener;
     MimeTyper = mimeTyper;
     Hasher = hasher;
     BufferSize = bufferSize;
     MaxFileSizeToServe = maxFileSizeToServe;
     FileInfo = fileInfo;
     MimeSetting = mimeSettingProvider.GetSetting(fileInfo);
 }
Beispiel #4
0
 public FileEntityResponder(ICacheManager cacheManager, IRetryableFileOpener retryableFileOpener, IMimeTyper mimeTyper, IHasher hasher, long maxFileSizeToServe, int bufferSize, MimeSettingProvider mimeSettingProvider, FileInfo fileInfo)
 {
     CacheManager        = cacheManager;
     RetryableFileOpener = retryableFileOpener;
     MimeTyper           = mimeTyper;
     Hasher             = hasher;
     BufferSize         = bufferSize;
     MaxFileSizeToServe = maxFileSizeToServe;
     FileInfo           = fileInfo;
     MimeSetting        = mimeSettingProvider.GetSetting(fileInfo);
 }
Beispiel #5
0
        public MimeSetting GetSetting(string fileExtension)
        {
            MimeSetting fileMimeSetting = null;

            if (!_fileExtensionMatches.TryGetValue(fileExtension, out fileMimeSetting))
            {
                fileMimeSetting = _mimeSettingDefault;
            }

            return(fileMimeSetting);
        }
Beispiel #6
0
        private static Dictionary <string, MimeSetting> GetFileExtensionsForMatches()
        {
            var fileExtensionMatches = new Dictionary <string, MimeSetting>();

            var fileExtensionElements = CurrentStaticFileHandlerConfiguration.Current.FileExtensions;

            foreach (FileExtensionElement fileExtension in fileExtensionElements)
            {
                var extensions = fileExtension.Extension.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var extension in extensions)
                {
                    var key = extension.Trim().ToLower();
                    if (!key.StartsWith("."))
                    {
                        key = "." + key;
                    }

                    var fileExtensionElement = new MimeSetting
                    {
                        Compress                = fileExtension.Compress,
                        Extension               = fileExtension.Extension,
                        MaxMemorySize           = fileExtension.MaxMemorySize,
                        ServeFromMemory         = fileExtension.ServeFromMemory,
                        EtagMethod              = fileExtension.EtagMethod,
                        Expires                 = fileExtension.Expires,
                        MemorySlidingExpiration = fileExtension.MemorySlidingExpiration,
                        UrlEtagQuerystringName  = fileExtension.UrlEtagQuerystringName,
                        UrlEtagHandlingMethod   = fileExtension.UrlEtagHandlingMethod,
                    };

                    fileExtensionMatches.Add(key, fileExtensionElement);
                }
            }

            return(fileExtensionMatches);
        }
        private static Dictionary<string, MimeSetting> GetFileExtensionsForMatches()
        {
            var fileExtensionMatches = new Dictionary<string, MimeSetting>();

            var fileExtensionElements = CurrentStaticFileHandlerConfiguration.Current.FileExtensions;
            foreach (FileExtensionElement fileExtension in fileExtensionElements)
            {
                var extensions = fileExtension.Extension.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var extension in extensions)
                {
                    var key = extension.Trim().ToLower();
                    if (!key.StartsWith("."))
                    {
                        key = "." + key;
                    }

                    var fileExtensionElement = new MimeSetting
                    {
                        Compress = fileExtension.Compress,
                        Extension = fileExtension.Extension,
                        MaxMemorySize = fileExtension.MaxMemorySize,
                        ServeFromMemory = fileExtension.ServeFromMemory,
                        EtagMethod = fileExtension.EtagMethod,
                        Expires = fileExtension.Expires,
                        MemorySlidingExpiration = fileExtension.MemorySlidingExpiration,
                        UrlEtagQuerystringName = fileExtension.UrlEtagQuerystringName,
                        UrlEtagHandlingMethod = fileExtension.UrlEtagHandlingMethod,
                    };

                    fileExtensionMatches.Add(key, fileExtensionElement);
                }
            }

            return fileExtensionMatches;
        }
 public MimeSettingProvider()
 {
     _fileExtensionMatches = GetFileExtensionsForMatches();
     _mimeSettingDefault = GetDefaultFileExtensionForNoMatches();
 }
Beispiel #9
0
 public MimeSettingProvider()
 {
     _fileExtensionMatches = GetFileExtensionsForMatches();
     _mimeSettingDefault   = GetDefaultFileExtensionForNoMatches();
 }