public virtual void Copy(GDataFile file) { FileInfo fileInfo = PreserveHierarchy ? new FileInfo(Path.Combine(DestinationDirectory.FullName, file.RelativeFullName)) : new FileInfo(Path.Combine(DestinationDirectory.FullName, file.Name)); if (!fileInfo.Directory.Exists) { if (Logger.IsDebugEnabled) { Logger.DebugFormat("Creating destination directory: {0}.", fileInfo.DirectoryName); } fileInfo.Directory.Create(); } if (Logger.IsInfoEnabled) { Logger.InfoFormat("Copying file: {0} to: {1}", file.Name, fileInfo.FullName); } using (FileStream fileStream = File.Create(fileInfo.FullName)) { const int bufferSize = 2048; byte[] buffer = new byte[bufferSize]; int count; do { count = file.BaseStream.Read(buffer, 0, bufferSize); fileStream.Write(buffer, 0, count); } while (count > 0); } }
protected override void Execute(GDataFile item) { if (Logger.IsDebugEnabled) { Logger.DebugFormat("Copying file: {0}.", item.Name); } Copy(item); }
public virtual void Send(GDataFile file) { if (Logger.IsInfoEnabled) { Logger.InfoFormat("Sending file: {0} to: {1}", file.Name, To); } MailMessage message = new MailMessage(Credentials.UserName, To, file.Name, String.Empty); Attachment attachment = new Attachment(file.BaseStream, file.Name, file.MediaType); message.Attachments.Add(attachment); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = Credentials; client.EnableSsl = true; client.Timeout = client.Timeout * 10; client.Send(message); }