public UploadResult UploadImage(Stream stream, string fileName) { ImageUploader imageUploader = null; switch (Info.TaskSettings.ImageDestination) { case ImageDestination.Imgur: if (Program.UploadersConfig.ImgurOAuth2Info == null) { Program.UploadersConfig.ImgurOAuth2Info = new OAuth2Info(APIKeys.ImgurClientID, APIKeys.ImgurClientSecret); } string albumID = null; if (Program.UploadersConfig.ImgurUploadSelectedAlbum && Program.UploadersConfig.ImgurSelectedAlbum != null) { albumID = Program.UploadersConfig.ImgurSelectedAlbum.id; } imageUploader = new Imgur(Program.UploadersConfig.ImgurOAuth2Info) { UploadMethod = Program.UploadersConfig.ImgurAccountType, DirectLink = Program.UploadersConfig.ImgurDirectLink, ThumbnailType = Program.UploadersConfig.ImgurThumbnailType, UseGIFV = Program.UploadersConfig.ImgurUseGIFV, UploadAlbumID = albumID }; break; case ImageDestination.ImageShack: Program.UploadersConfig.ImageShackSettings.ThumbnailWidth = Info.TaskSettings.AdvancedSettings.ThumbnailPreferredWidth; Program.UploadersConfig.ImageShackSettings.ThumbnailHeight = Info.TaskSettings.AdvancedSettings.ThumbnailPreferredHeight; imageUploader = new ImageShackUploader(APIKeys.ImageShackKey, Program.UploadersConfig.ImageShackSettings); break; case ImageDestination.TinyPic: imageUploader = new TinyPicUploader(APIKeys.TinyPicID, APIKeys.TinyPicKey, Program.UploadersConfig.TinyPicAccountType, Program.UploadersConfig.TinyPicRegistrationCode); break; case ImageDestination.Flickr: imageUploader = new FlickrUploader(APIKeys.FlickrKey, APIKeys.FlickrSecret, Program.UploadersConfig.FlickrAuthInfo, Program.UploadersConfig.FlickrSettings); break; case ImageDestination.Photobucket: imageUploader = new Photobucket(Program.UploadersConfig.PhotobucketOAuthInfo, Program.UploadersConfig.PhotobucketAccountInfo); break; case ImageDestination.Picasa: imageUploader = new Picasa(Program.UploadersConfig.PicasaOAuth2Info) { AlbumID = Program.UploadersConfig.PicasaAlbumID }; break; case ImageDestination.Twitter: OAuthInfo twitterOAuth = Program.UploadersConfig.TwitterOAuthInfoList.ReturnIfValidIndex(Program.UploadersConfig.TwitterSelectedAccount); imageUploader = new Twitter(twitterOAuth) { SkipMessageBox = Program.UploadersConfig.TwitterSkipMessageBox, DefaultMessage = Program.UploadersConfig.TwitterDefaultMessage ?? string.Empty }; break; case ImageDestination.Chevereto: imageUploader = new Chevereto(Program.UploadersConfig.CheveretoWebsite, Program.UploadersConfig.CheveretoAPIKey) { DirectURL = Program.UploadersConfig.CheveretoDirectURL }; break; case ImageDestination.Vgyme: imageUploader = new VgymeUploader(); break; case ImageDestination.SomeImage: imageUploader = new SomeImage(APIKeys.SomeImageKey); break; case ImageDestination.CustomImageUploader: CustomUploaderItem customUploader = GetCustomUploader(Program.UploadersConfig.CustomImageUploaderSelected); if (customUploader != null) { imageUploader = new CustomImageUploader(customUploader); } break; } if (imageUploader != null) { PrepareUploader(imageUploader); return imageUploader.Upload(stream, fileName); } return null; }
private void TestCustomUploader(CustomUploaderType type, CustomUploaderItem item) { btnCustomUploaderImageUploaderTest.Enabled = btnCustomUploaderTextUploaderTest.Enabled = btnCustomUploaderFileUploaderTest.Enabled = btnCustomUploaderURLShortenerTest.Enabled = false; UploadResult result = null; txtCustomUploaderLog.ResetText(); TaskEx.Run(() => { try { switch (type) { case CustomUploaderType.Image: using (Stream stream = ShareXYZResources.Logo.GetStream()) { CustomImageUploader imageUploader = new CustomImageUploader(item); result = imageUploader.Upload(stream, "Test.png"); result.Errors = imageUploader.Errors; } break; case CustomUploaderType.Text: CustomTextUploader textUploader = new CustomTextUploader(item); result = textUploader.UploadText("ShareXYZ text upload test", "Test.txt"); result.Errors = textUploader.Errors; break; case CustomUploaderType.File: using (Stream stream = ShareXYZResources.Logo.GetStream()) { CustomFileUploader fileUploader = new CustomFileUploader(item); result = fileUploader.Upload(stream, "Test.png"); result.Errors = fileUploader.Errors; } break; case CustomUploaderType.URL: CustomURLShortener urlShortener = new CustomURLShortener(item); result = urlShortener.ShortenURL(Links.URL_WEBSITE); result.Errors = urlShortener.Errors; break; } } catch (Exception e) { result = new UploadResult(); result.Errors.Add(e.Message); } }, () => { if (!IsDisposed) { if (result != null) { if ((type != CustomUploaderType.URL && !string.IsNullOrEmpty(result.URL)) || (type == CustomUploaderType.URL && !string.IsNullOrEmpty(result.ShortenedURL))) { txtCustomUploaderLog.AppendText("URL: " + result + Environment.NewLine); if (!string.IsNullOrEmpty(result.ThumbnailURL)) { txtCustomUploaderLog.AppendText("Thumbnail URL: " + result.ThumbnailURL + Environment.NewLine); } if (!string.IsNullOrEmpty(result.DeletionURL)) { txtCustomUploaderLog.AppendText("Deletion URL: " + result.DeletionURL + Environment.NewLine); } } else if (result.IsError) { txtCustomUploaderLog.AppendText(Resources.UploadersConfigForm_Error + ": " + result.ErrorsToString() + Environment.NewLine); } else { txtCustomUploaderLog.AppendText(Resources.UploadersConfigForm_TestCustomUploader_Error__Result_is_empty_ + Environment.NewLine); } txtCustomUploaderLog.ScrollToCaret(); btnCustomUploaderShowLastResponse.Tag = result.Response; btnCustomUploaderShowLastResponse.Enabled = !string.IsNullOrEmpty(result.Response); } btnCustomUploaderImageUploaderTest.Enabled = btnCustomUploaderTextUploaderTest.Enabled = btnCustomUploaderFileUploaderTest.Enabled = btnCustomUploaderURLShortenerTest.Enabled = true; } }); }