Example #1
0
        /// <summary>
        /// Finds the format.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="credentials">The credentials.</param>
        /// <returns>The format associated with the file.</returns>
        public IFormat FindFormat(string fileName, Credentials?credentials)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(DefaultFormat);
            }
            fileName = fileName.ToUpperInvariant();
            var TempFile  = new FileInfo(fileName, credentials);
            var Extension = TempFile.Extension.Replace(".", string.Empty).ToUpperInvariant();

            if (FormatsByFileType.ContainsKey(Extension))
            {
                return(FormatsByFileType[Extension]);
            }
            using var TempStream = new MemoryStream(TempFile.ReadBinary());
            return(FindFormat(TempStream, string.Empty));
        }
Example #2
0
 /// <summary>
 /// Adds the formats.
 /// </summary>
 /// <param name="formats">The formats.</param>
 private void AddFormats(IEnumerable <IFormat> formats)
 {
     foreach (var Format in formats)
     {
         foreach (var FileType in Format.FileTypes)
         {
             if (!FormatsByFileType.ContainsKey(FileType))
             {
                 FormatsByFileType.Add(FileType, Format);
             }
         }
         foreach (var ContentType in Format.ContentTypes)
         {
             if (!FormatsByMimeType.ContainsKey(ContentType))
             {
                 FormatsByMimeType.Add(ContentType, Format);
             }
         }
     }
 }