Пример #1
0
 public ContentReader(Book book, ContentReaderParameters parameters, Log log)
 {
     string identifier = null;
     if (parameters.Index > 0)
         identifier = parameters.Index.ToString(CultureInfo.InvariantCulture);
     else if (!string.IsNullOrEmpty(parameters.File))
         identifier = parameters.File;
     else if (!string.IsNullOrEmpty(parameters.Format))
         identifier = parameters.Format;
     var volume = book.GetVolume(identifier);
     var files = new FileSource { Log = log };
     Encoding encoding;
     Content = files.Open(volume, out encoding);
     if (parameters.WasStreamTypeSpecified)
         encoding = parameters.GetEncoding();
     try {
         if (!parameters.UsingByteEncoding)
             Reader = new StreamReader(Content, encoding);
     } catch {
         Content.Close();
         throw;
     }
 }
Пример #2
0
 Volume GetVolume(Book book, ContentReaderParameters parameters)
 {
     // Every volume can have more formats (MIME types) assigned. Choose the first one
     // that starts with the specified value not to have to enter the entire MIME type
     // including the charset part.
     Volume volume;
     if (parameters.Index > 0) {
         volume = book.Volumes.ElementAt(parameters.Index);
     } else if (!string.IsNullOrEmpty(parameters.File)) {
         volume = book.Volumes.FirstOrDefault(item =>
                     item.URL.EndsWithCI(parameters.File));
         if (volume == null)
             throw new ApplicationException("File not available.");
     } else if (!string.IsNullOrEmpty(parameters.Format)) {
         volume = book.Volumes.FirstOrDefault(item => item.Formats.Any(
             format => format.StartsWithII(parameters.Format)));
         if (volume == null)
             throw new ApplicationException("Format not available.");
     } else {
         volume = book.Volumes.First();
     }
     return volume;
 }
Пример #3
0
 public IContentReader GetContentReader(string path)
 {
     // If Get-Content receives the item from pipe dynamic parameters will be
     // created by the drive provider of the current container.
     var parameters = DynamicParameters as ContentReaderParameters;
     if (parameters == null) {
         parameters = new ContentReaderParameters();
         var fileParameters = DynamicParameters as FileSystemContentDynamicParametersBase;
         if (fileParameters != null)
             parameters.Encoding = fileParameters.Encoding;
     }
     EnsureLog();
     return new ContentReader(Cache.GetBook(path), parameters, Cache.Log);
 }