public void DownloadFile(IFileBase file, string destinationDirectory) { foreach (IFamilyHandler handler in CreateFamilyHandlers()) { if (!handler.ShouldProcess(file, ExportFamily)) { continue; } string filename = handler.GetTargetFilename(file, FileSystem); if (destinationDirectory != null) { filename = FileSystem.Path.Combine(destinationDirectory, filename); } FireDownloading(file, filename); Stream output = FileSystem.File.Create(filename); using (output) { handler.Download(DriveService, file, output); } FireDownloaded(file, filename); } }
protected ConfigSettingsBase(string settingsPath, IFileBase file, IDirectoryBase directoryWrapper) { _settingsPath = settingsPath; _directoryWrapper = directoryWrapper; _fileWrapper = file; Load(); }
public FileBase(IFileBase fileBase) : this(fileBase.Id, fileBase.MimeType, fileBase.Name, fileBase.Trashed, fileBase.Size, fileBase.ModifiedTime) { }
// TODO support powerpoint protected override string TargetMimeType(IFileBase file) { switch (file.MimeType) { case MimeTypes.GoogleDoc: return MimeTypes.MicrosoftWord; case MimeTypes.GoogleSheet: return MimeTypes.MicrosoftExcel; case MimeTypes.GoogleSlide: return MimeTypes.MicrosoftPowerpoint; case MimeTypes.GoogleDrawing: // png should not be handled in here, rethink ExportFamily return MimeTypes.Png; default: throw new NotSupportedException("Unknown mime type: " + file.MimeType); } }
protected override string TargetFileExtension(IFileBase file) { switch (file.MimeType) { case MimeTypes.GoogleDoc: return "docx"; case MimeTypes.GoogleSheet: return "xlsx"; case MimeTypes.GoogleSlide: return "pptx"; case MimeTypes.GoogleDrawing: return "png"; default: throw new NotSupportedException("Unknown mime type: " + file.MimeType); } }
public ZipController(IFileBase fileBase) { this.file = fileBase ?? new FileBase(); }
public FileDownloadedEventArgs(IFileBase file, string localPath) : base(file, localPath) { }
/// <summary> /// Creates an instance of this class. /// </summary> /// <param name="file">The Google file.</param> /// <param name="localPath">The local file.</param> public FileWithPathEventArgs(IFileBase file, string localPath) : base(file) { LocalPath = localPath; }
protected abstract string TargetMimeType(IFileBase file);
public bool ShouldProcess(IFileBase file, ExportFamily family) { return file.IsExportable(); }
private void FireDownloading(IFileBase file, string localPath) { var downloading = Downloading; if (downloading != null) { downloading(this, new FileDownloadingEventArgs(file, localPath)); } }
private void FireDownloaded(IFileBase file, string localPath) { var downloaded = Downloaded; if (downloaded != null) { downloaded(this, new FileDownloadedEventArgs(file, localPath)); } }
// TODO: support all openoffice formats protected override string TargetMimeType(IFileBase file) { return MimeTypes.OpenText; }
protected override string TargetFileExtension(IFileBase file) { return "odt"; }
public OfficeFile(string filename) { // Ensure file exists. if (!System.IO.File.Exists(filename)) { throw new FileNotFoundException(String.Format("File {0} does not exist.", filename)); } // Get file info for new file. var fileInfo = new FileInfo(filename); // Attempt to instantiate file accessors. try { // Switch depending on file extension. switch (fileInfo.Extension.ToLower()) { case ".accdb": case ".mdb": // Use Dao. this._fileAccessor = new FileAccessors.Dao.DaoFile(filename); break; case ".doc": case ".dot": case ".ppt": case ".pot": case ".xls": case ".xlm": case ".xlt": // Use Npoi. this._fileAccessor = new FileAccessors.Npoi.NpoiFile(filename); break; case ".docx": case ".docm": case ".dotx": case ".dotm": // Use Docx. this._fileAccessor = new FileAccessors.OpenXml.DocxFile(filename); break; case ".pptx": case ".pptm": case ".potx": case ".potm": // Use Pptx. this._fileAccessor = new FileAccessors.OpenXml.PptxFile(filename); break; case ".xlsx": case ".xlsm": case ".xlst": // Use Xlsx. this._fileAccessor = new FileAccessors.OpenXml.XlsxFile(filename); break; default: // Use generic. this._fileAccessor = new FileAccessors.Generic.GenericFile(filename); break; } } catch { // Try using generic. try { this._fileAccessor = new FileAccessors.Generic.GenericFile(filename); } catch { throw new Exception(String.Format("Cannot get properties from file {0}.", filename)); } } }
public void Download(IDriveService driveService, IFileBase file, Stream output) { driveService.Files.Export(file.Id, TargetMimeType(file)).Download(output); }
public string GetTargetFilename(IFileBase file, IFileSystem fileSystem) { return fileSystem.Path.ChangeExtension(file.Name, TargetFileExtension(file)); }
public ConfigSettingsBaseForTesting(string settingsPath, IFileBase file, IDirectoryBase directoryWrapper) : base(settingsPath, file, directoryWrapper) { }
protected abstract string TargetFileExtension(IFileBase file);
public FileEventArgs(IFileBase file) { File = file; }
protected AuditingSettings(string settingsPath, IFileBase file, IDirectoryBase directoryWrapper) : base(settingsPath, file, directoryWrapper) { }