private void UploadFile(FileDestination fileUploaderType, Stream data) { FileUploader fileUploader = null; switch (fileUploaderType) { case FileDestination.FTP: if (Engine.ConfigUI.ShowFTPSettingsBeforeUploading) { var ucf = new UploadersConfigForm(Engine.ConfigUploaders, Engine.ConfigUI.ApiKeysConfig); ucf.Icon = Resources.zss_main; ucf.tcUploaders.SelectedTab = ucf.tpFileUploaders; ucf.tcFileUploaders.SelectedTab = ucf.tpFTP; ucf.ShowDialog(); } switch (Job1) { case EDataType.Text: UploadToFTP(Engine.ConfigUploaders.FTPSelectedText, data); break; case EDataType.Image: UploadToFTP(Engine.ConfigUploaders.FTPSelectedImage, data); break; default: case EDataType.File: UploadToFTP(Engine.ConfigUploaders.FTPSelectedFile, data); break; } break; case FileDestination.Minus: fileUploader = new Minus(Engine.ConfigUploaders.MinusConfig, new OAuthInfo(Engine.ConfigUI.ApiKeysConfig.MinusConsumerKey, Engine.ConfigUI.ApiKeysConfig.MinusConsumerSecret)); break; case FileDestination.Dropbox: string uploadPath = new NameParser { IsFolderPath = true }.Convert(Dropbox.TidyUploadPath(Engine.ConfigUploaders.DropboxUploadPath)); fileUploader = new Dropbox(Engine.ConfigUploaders.DropboxOAuthInfo, uploadPath, Engine.ConfigUploaders.DropboxAccountInfo) { AutoCreateShareableLink = Engine.ConfigUploaders.DropboxAutoCreateShareableLink }; break; case FileDestination.Box: fileUploader = new Box(ZKeys.BoxKey) { AuthToken = Engine.ConfigUploaders.BoxAuthToken, FolderID = Engine.ConfigUploaders.BoxFolderID, Share = Engine.ConfigUploaders.BoxShare }; break; case FileDestination.SendSpace: fileUploader = new SendSpace(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey); switch (Engine.ConfigUploaders.SendSpaceAccountType) { case AccountType.Anonymous: SendSpaceManager.PrepareUploadInfo(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey); break; case AccountType.User: SendSpaceManager.PrepareUploadInfo(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey, Engine.ConfigUploaders.SendSpaceUsername, Engine.ConfigUploaders.SendSpacePassword); break; } break; case FileDestination.RapidShare: fileUploader = new RapidShare(Engine.ConfigUploaders.RapidShareUsername, Engine.ConfigUploaders.RapidSharePassword, Engine.ConfigUploaders.RapidShareFolderID); break; case FileDestination.CustomUploader: fileUploader = new CustomUploader(Engine.ConfigUploaders.CustomUploadersList[Engine.ConfigUploaders.CustomUploaderSelected]); break; } if (fileUploader != null) { MyWorker.ReportProgress((int)ProgressType.UpdateProgressMax, TaskbarProgressBarState.Indeterminate); DestinationName = fileUploaderType.GetDescription(); DebugHelper.WriteLine("Initialized " + DestinationName); fileUploader.ProgressChanged += UploadProgressChanged; UploadResult ur_remote_file = fileUploader.Upload(data, Info.FileName); if (ur_remote_file != null) { ur_remote_file.Host = fileUploaderType.GetDescription(); ur_remote_file.LocalFilePath = Info.LocalFilePath; AddUploadResult(ur_remote_file); } Errors = fileUploader.Errors; } }
public UploadResult UploadFile(Stream stream, string fileName) { FileUploader fileUploader = null; switch (UploadManager.FileUploader) { case FileDestination.Dropbox: NameParser parser = new NameParser { IsFolderPath = true }; string uploadPath = parser.Convert(Dropbox.TidyUploadPath(Program.UploadersConfig.DropboxUploadPath)); fileUploader = new Dropbox(Program.UploadersConfig.DropboxOAuthInfo, uploadPath, Program.UploadersConfig.DropboxAccountInfo) { AutoCreateShareableLink = Program.UploadersConfig.DropboxAutoCreateShareableLink }; break; case FileDestination.RapidShare: fileUploader = new RapidShare(Program.UploadersConfig.RapidShareUsername, Program.UploadersConfig.RapidSharePassword, Program.UploadersConfig.RapidShareFolderID); break; case FileDestination.SendSpace: fileUploader = new SendSpace(ZKeys.SendSpaceKey); switch (Program.UploadersConfig.SendSpaceAccountType) { case AccountType.Anonymous: SendSpaceManager.PrepareUploadInfo(ZKeys.SendSpaceKey); break; case AccountType.User: SendSpaceManager.PrepareUploadInfo(ZKeys.SendSpaceKey, Program.UploadersConfig.SendSpaceUsername, Program.UploadersConfig.SendSpacePassword); break; } break; case FileDestination.Minus: fileUploader = new Minus(Program.UploadersConfig.MinusConfig, new OAuthInfo(ZKeys.MinusConsumerKey, ZKeys.MinusConsumerSecret)); break; case FileDestination.Box: fileUploader = new Box(ZKeys.BoxKey) { AuthToken = Program.UploadersConfig.BoxAuthToken, FolderID = Program.UploadersConfig.BoxFolderID, Share = Program.UploadersConfig.BoxShare }; break; case FileDestination.CustomUploader: if (Program.UploadersConfig.CustomUploadersList.HasValidIndex(Program.UploadersConfig.CustomUploaderSelected)) { fileUploader = new CustomUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomUploaderSelected]); } break; case FileDestination.FTP: int index = Program.UploadersConfig.GetFtpIndex(Info.DataType); if (Program.UploadersConfig.FTPAccountList2.HasValidIndex(index)) { fileUploader = new FTPUploader(Program.UploadersConfig.FTPAccountList2[index]); } break; case FileDestination.Email: using (EmailForm emailForm = new EmailForm(Program.UploadersConfig.EmailRememberLastTo ? Program.UploadersConfig.EmailLastTo : string.Empty, Program.UploadersConfig.EmailDefaultSubject, Program.UploadersConfig.EmailDefaultBody)) { if (emailForm.ShowDialog() == DialogResult.OK) { if (Program.UploadersConfig.EmailRememberLastTo) { Program.UploadersConfig.EmailLastTo = emailForm.ToEmail; } fileUploader = new Email { SmtpServer = Program.UploadersConfig.EmailSmtpServer, SmtpPort = Program.UploadersConfig.EmailSmtpPort, FromEmail = Program.UploadersConfig.EmailFrom, Password = Program.UploadersConfig.EmailPassword, ToEmail = emailForm.ToEmail, Subject = emailForm.Subject, Body = emailForm.Body }; } else { IsStopped = true; } } break; } if (fileUploader != null) { PrepareUploader(fileUploader); return fileUploader.Upload(stream, fileName); } return null; }
private void TestCustomUploader(CustomUploaderInfo cui) { UploadResult ur = null; AsyncHelper.AsyncJob(() => { try { using (Stream stream = Resources.ZScreen_256.GetStream()) { CustomUploader cu = new CustomUploader(cui); ur = cu.Upload(stream, "Test.png"); ur.Errors = cu.Errors; } } catch { } }, () => { if (ur != null) { if (!string.IsNullOrEmpty(ur.URL)) { txtCustomUploaderLog.AppendText("URL: " + ur.URL + Environment.NewLine); } else if (ur.IsError) { txtCustomUploaderLog.AppendText("Error: " + ur.ErrorsToString() + Environment.NewLine); } else { txtCustomUploaderLog.AppendText("Error: Result is empty." + Environment.NewLine); } txtCustomUploaderLog.ScrollToCaret(); } btnCustomUploaderTest.Enabled = true; }); }