示例#1
0
 protected override void ProcessRecord()
 {
     try {
         var files = new FileSource { Log = Log };
         if (!string.IsNullOrEmpty(ActualDirectory))
             files.SetDirectory(ActualDirectory);
         if (ShouldProcess("Cache", "Clear") && (Force ||
                 ShouldContinue("Do you really want to clear locally cached volumes?",
                     "Clear Cache")))
             files.ClearCache();
     } catch (Exception exception) {
         WriteError(new ErrorRecord(exception, "ClearCacheFailed",
             ErrorCategory.DeviceError, null));
     }
 }
示例#2
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;
     }
 }