private string CreateThumbnail(string url, FTPUploader fu) { if (!string.IsNullOrEmpty(url)) { if (CreateThumbnail()) { double thar = Engine.ConfigUploaders.FTPThumbnailWidthLimit / (double)TempImage.Width; using ( Image img = HelpersLib.GraphicsHelper.Core.ChangeImageSize(TempImage, Engine.ConfigUploaders.FTPThumbnailWidthLimit, (int)(thar * TempImage.Height))) { var sb = new StringBuilder(Path.GetFileNameWithoutExtension(Info.LocalFilePath)); sb.Append(".th"); sb.Append(Path.GetExtension(Info.LocalFilePath)); Debug.Assert(Info.LocalFilePath != null, "Info.LocalFilePath != null"); string thPath = Path.Combine(Path.GetDirectoryName(Info.LocalFilePath), sb.ToString()); img.Save(thPath); if (File.Exists(thPath)) { string thumb = fu.Upload(thPath).URL; if (!string.IsNullOrEmpty(thumb)) { return thumb; } } } } return null; } return null; }
/// <summary> /// Funtion to FTP the Screenshot /// </summary> /// <returns>Retuns a List of Screenshots</returns> public UploadResult UploadToFTP(int FtpAccountId, Stream data) { var ur_remote_file_ftp = new UploadResult { LocalFilePath = Info.LocalFilePath, Host = FileDestination.FTP.GetDescription() }; try { MyWorker.ReportProgress((int)ProgressType.UpdateProgressMax, TaskbarProgressBarState.Indeterminate); if (Adapter.CheckFTPAccounts(this, FtpAccountId)) { FTPAccount acc = Engine.ConfigUploaders.FTPAccountList2[FtpAccountId]; DestinationName = string.Format("FTP - {0}", acc.Name); DebugHelper.WriteLine(string.Format("Uploading {0} to FTP: {1}", Info.FileName, acc.Host)); MyWorker.ReportProgress((int)ProgressType.UpdateProgressMax, TaskbarProgressBarState.Normal); FTPUploader fu = new FTPUploader(acc); fu.ProgressChanged += UploadProgressChanged; ur_remote_file_ftp.URL = File.Exists(Info.LocalFilePath) ? fu.Upload(Info.LocalFilePath).URL : fu.Upload(data, Info.FileName).URL; ur_remote_file_ftp.ThumbnailURL = CreateThumbnail(ur_remote_file_ftp.URL, fu); if (!string.IsNullOrEmpty(ur_remote_file_ftp.URL)) { AddUploadResult(ur_remote_file_ftp); } } } catch (Exception ex) { DebugHelper.WriteException(ex, "Error while uploading to FTP Server"); Errors.Add("FTP upload failed.\r\n" + ex.Message); } return ur_remote_file_ftp; }