private async Task TestCustomUploader(CustomUploaderDestinationType type, int index) { if (!Config.CustomUploadersList.IsValidIndex(index)) { return; } btnImageUploaderTest.Enabled = btnTextUploaderTest.Enabled = btnFileUploaderTest.Enabled = btnURLShortenerTest.Enabled = btnURLSharingServiceTest.Enabled = false; rtbResult.ResetText(); txtResponseText.ResetText(); lbCustomUploaderList.SelectedIndex = index; CustomUploaderItem item = Config.CustomUploadersList[index]; UploadResult result = null; await Task.Run(() => { try { switch (type) { case CustomUploaderDestinationType.ImageUploader: using (Stream stream = ShareXResources.Logo.GetStream()) { CustomImageUploader imageUploader = new CustomImageUploader(item); result = imageUploader.Upload(stream, "Test.png"); result.Errors = imageUploader.Errors; } break; case CustomUploaderDestinationType.TextUploader: CustomTextUploader textUploader = new CustomTextUploader(item); result = textUploader.UploadText("ShareX text upload test", "Test.txt"); result.Errors = textUploader.Errors; break; case CustomUploaderDestinationType.FileUploader: using (Stream stream = ShareXResources.Logo.GetStream()) { CustomFileUploader fileUploader = new CustomFileUploader(item); result = fileUploader.Upload(stream, "Test.png"); result.Errors = fileUploader.Errors; } break; case CustomUploaderDestinationType.URLShortener: CustomURLShortener urlShortener = new CustomURLShortener(item); result = urlShortener.ShortenURL(Links.URL_WEBSITE); result.Errors = urlShortener.Errors; break; case CustomUploaderDestinationType.URLSharingService: CustomURLSharer urlSharer = new CustomURLSharer(item); result = urlSharer.ShareURL(Links.URL_WEBSITE); result.Errors = urlSharer.Errors; break; } } catch (Exception e) { result = new UploadResult(); result.Errors.Add(e.Message); } }); if (!IsDisposed) { if (result != null) { StringBuilder sbResult = new StringBuilder(); if (((type == CustomUploaderDestinationType.ImageUploader || type == CustomUploaderDestinationType.TextUploader || type == CustomUploaderDestinationType.FileUploader) && !string.IsNullOrEmpty(result.URL)) || (type == CustomUploaderDestinationType.URLShortener && !string.IsNullOrEmpty(result.ShortenedURL)) || (type == CustomUploaderDestinationType.URLSharingService && !result.IsError && !string.IsNullOrEmpty(result.URL))) { if (!string.IsNullOrEmpty(result.ShortenedURL)) { sbResult.AppendLine("Shortened URL: " + result.ShortenedURL); } if (!string.IsNullOrEmpty(result.URL)) { sbResult.AppendLine("URL: " + result.URL); } if (!string.IsNullOrEmpty(result.ThumbnailURL)) { sbResult.AppendLine("Thumbnail URL: " + result.ThumbnailURL); } if (!string.IsNullOrEmpty(result.DeletionURL)) { sbResult.AppendLine("Deletion URL: " + result.DeletionURL); } } else if (result.IsError) { sbResult.AppendLine(result.ErrorsToString()); } else { sbResult.AppendLine(Resources.UploadersConfigForm_TestCustomUploader_Error__Result_is_empty_); } rtbResult.Text = sbResult.ToString(); txtResponseText.Text = result.ResponseInfo?.ResponseText; tcCustomUploader.SelectedTab = tpTest; } btnImageUploaderTest.Enabled = btnTextUploaderTest.Enabled = btnFileUploaderTest.Enabled = btnURLShortenerTest.Enabled = btnURLSharingServiceTest.Enabled = true; } }
public UploadResult UploadImage(Stream stream, string fileName) { ImageUploader imageUploader = null; switch (Info.TaskSettings.ImageDestination) { 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.Imgur: if (Program.UploadersConfig.ImgurOAuth2Info == null) { Program.UploadersConfig.ImgurOAuth2Info = new OAuth2Info(APIKeys.ImgurClientID, APIKeys.ImgurClientSecret); } imageUploader = new Imgur_v3(Program.UploadersConfig.ImgurOAuth2Info) { UploadMethod = Program.UploadersConfig.ImgurAccountType, ThumbnailType = Program.UploadersConfig.ImgurThumbnailType, UploadAlbumID = Program.UploadersConfig.ImgurAlbumID }; 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.Twitpic: int indexTwitpic = Program.UploadersConfig.TwitterSelectedAccount; if (Program.UploadersConfig.TwitterOAuthInfoList != null && Program.UploadersConfig.TwitterOAuthInfoList.IsValidIndex(indexTwitpic)) { imageUploader = new TwitPicUploader(APIKeys.TwitPicKey, Program.UploadersConfig.TwitterOAuthInfoList[indexTwitpic]) { TwitPicThumbnailMode = Program.UploadersConfig.TwitPicThumbnailMode, ShowFull = Program.UploadersConfig.TwitPicShowFull }; } break; case ImageDestination.Twitsnaps: int indexTwitsnaps = Program.UploadersConfig.TwitterSelectedAccount; if (Program.UploadersConfig.TwitterOAuthInfoList.IsValidIndex(indexTwitsnaps)) { imageUploader = new TwitSnapsUploader(APIKeys.TwitsnapsKey, Program.UploadersConfig.TwitterOAuthInfoList[indexTwitsnaps]); } break; case ImageDestination.yFrog: YfrogOptions yFrogOptions = new YfrogOptions(APIKeys.ImageShackKey); yFrogOptions.Username = Program.UploadersConfig.YFrogUsername; yFrogOptions.Password = Program.UploadersConfig.YFrogPassword; yFrogOptions.Source = Application.ProductName; imageUploader = new YfrogUploader(yFrogOptions); break; case ImageDestination.MediaCrush: imageUploader = new MediaCrushUploader(); break; case ImageDestination.CustomImageUploader: if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomImageUploaderSelected)) { imageUploader = new CustomImageUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomImageUploaderSelected]); } break; } if (imageUploader != null) { PrepareUploader(imageUploader); return(imageUploader.Upload(stream, fileName)); } return(null); }
private async Task TestCustomUploader(CustomUploaderDestinationType type, int index) { if (!Config.CustomUploadersList.IsValidIndex(index)) { return; } btnImageUploaderTest.Enabled = btnTextUploaderTest.Enabled = btnFileUploaderTest.Enabled = btnURLShortenerTest.Enabled = btnURLSharingServiceTest.Enabled = false; lbCustomUploaderList.SelectedIndex = index; CustomUploaderItem item = Config.CustomUploadersList[index]; UploadResult result = null; await Task.Run(() => { try { switch (type) { case CustomUploaderDestinationType.ImageUploader: using (Stream stream = ShareXResources.Logo.GetStream()) { CustomImageUploader imageUploader = new CustomImageUploader(item); result = imageUploader.Upload(stream, "Test.png"); result.Errors.AddRange(imageUploader.Errors); } break; case CustomUploaderDestinationType.TextUploader: CustomTextUploader textUploader = new CustomTextUploader(item); result = textUploader.UploadText("ShareX text upload test", "Test.txt"); result.Errors.AddRange(textUploader.Errors); break; case CustomUploaderDestinationType.FileUploader: using (Stream stream = ShareXResources.Logo.GetStream()) { CustomFileUploader fileUploader = new CustomFileUploader(item); result = fileUploader.Upload(stream, "Test.png"); result.Errors.AddRange(fileUploader.Errors); } break; case CustomUploaderDestinationType.URLShortener: CustomURLShortener urlShortener = new CustomURLShortener(item); result = urlShortener.ShortenURL(Links.URL_WEBSITE); result.Errors.AddRange(urlShortener.Errors); break; case CustomUploaderDestinationType.URLSharingService: CustomURLSharer urlSharer = new CustomURLSharer(item); result = urlSharer.ShareURL(Links.URL_WEBSITE); result.Errors.AddRange(urlSharer.Errors); break; } } catch (Exception e) { result = new UploadResult(); result.Errors.Add(e.Message); } }); if (!IsDisposed) { if (result != null) { ResponseForm.ShowInstance(result); } btnImageUploaderTest.Enabled = btnTextUploaderTest.Enabled = btnFileUploaderTest.Enabled = btnURLShortenerTest.Enabled = btnURLSharingServiceTest.Enabled = true; } }
private UploadResult UploadImage(string ssPath) { ImageUploader imageUploader = null; if (!string.IsNullOrEmpty(Program.Settings.PtpImgCode)) { imageUploader = new PtpImageUploader(Crypt.Decrypt(Program.Settings.PtpImgCode)); } else { switch ((ImageDestination)Program.Settings.ImageUploaderType) { case ImageDestination.TinyPic: imageUploader = new TinyPicUploader(ZKeys.TinyPicID, ZKeys.TinyPicKey, Program.UploadersConfig.TinyPicAccountType, Program.UploadersConfig.TinyPicRegistrationCode); break; 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_v3(Program.UploadersConfig.ImgurOAuth2Info) { UploadMethod = Program.UploadersConfig.ImgurAccountType, DirectLink = Program.UploadersConfig.ImgurDirectLink, ThumbnailType = Program.UploadersConfig.ImgurThumbnailType, UploadAlbumID = albumID }; 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); break; case ImageDestination.Chevereto: imageUploader = new Chevereto(Program.UploadersConfig.CheveretoWebsite, Program.UploadersConfig.CheveretoAPIKey) { DirectURL = Program.UploadersConfig.CheveretoDirectURL }; break; case ImageDestination.HizliResim: imageUploader = new HizliResim() { DirectURL = true }; break; case ImageDestination.CustomImageUploader: if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomImageUploaderSelected)) { imageUploader = new CustomImageUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomImageUploaderSelected]); } break; case ImageDestination.FileUploader: return(UploadFile(ssPath)); } } if (imageUploader != null) { ReportProgress(ProgressType.UPDATE_STATUSBAR_DEBUG, string.Format("Uploading {0}.", Path.GetFileName(ssPath))); return(imageUploader.Upload(ssPath)); } return(null); }
private UploadResult UploadImage(string ssPath) { ImageUploader imageUploader = null; if (!string.IsNullOrEmpty(App.Settings.PtpImgCode)) { imageUploader = new PtpImageUploader(Crypt.Decrypt(App.Settings.PtpImgCode)); } else { switch (App.Settings.ProfileActive.ImageUploaderType) { case ImageDestination.Imgur: if (App.UploadersConfig.ImgurOAuth2Info == null) { App.UploadersConfig.ImgurOAuth2Info = new OAuth2Info(APIKeys.ImgurClientID, APIKeys.ImgurClientSecret); } string albumID = null; if (App.UploadersConfig.ImgurUploadSelectedAlbum && App.UploadersConfig.ImgurSelectedAlbum != null) { albumID = App.UploadersConfig.ImgurSelectedAlbum.id; } imageUploader = new Imgur(App.UploadersConfig.ImgurOAuth2Info) { UploadMethod = App.UploadersConfig.ImgurAccountType, DirectLink = App.UploadersConfig.ImgurDirectLink, ThumbnailType = App.UploadersConfig.ImgurThumbnailType, UploadAlbumID = albumID }; break; case ImageDestination.TinyPic: imageUploader = new TinyPicUploader(APIKeys.TinyPicID, APIKeys.TinyPicKey, App.UploadersConfig.TinyPicAccountType, App.UploadersConfig.TinyPicRegistrationCode); break; case ImageDestination.Flickr: imageUploader = new FlickrUploader(APIKeys.FlickrKey, APIKeys.FlickrSecret, App.UploadersConfig.FlickrAuthInfo, App.UploadersConfig.FlickrSettings); break; case ImageDestination.Photobucket: imageUploader = new Photobucket(App.UploadersConfig.PhotobucketOAuthInfo, App.UploadersConfig.PhotobucketAccountInfo); break; case ImageDestination.Picasa: imageUploader = new Picasa(App.UploadersConfig.PicasaOAuth2Info) { AlbumID = App.UploadersConfig.PicasaAlbumID }; break; case ImageDestination.Twitter: OAuthInfo twitterOAuth = App.UploadersConfig.TwitterOAuthInfoList.ReturnIfValidIndex(App.UploadersConfig.TwitterSelectedAccount); imageUploader = new Twitter(twitterOAuth); break; case ImageDestination.Chevereto: imageUploader = new Chevereto(App.UploadersConfig.CheveretoWebsite, App.UploadersConfig.CheveretoAPIKey) { DirectURL = App.UploadersConfig.CheveretoDirectURL }; break; case ImageDestination.HizliResim: imageUploader = new HizliResim() { DirectURL = true }; break; case ImageDestination.CustomImageUploader: if (App.UploadersConfig.CustomUploadersList.IsValidIndex(App.UploadersConfig.CustomImageUploaderSelected)) { imageUploader = new CustomImageUploader(App.UploadersConfig.CustomUploadersList[App.UploadersConfig.CustomImageUploaderSelected]); } break; case ImageDestination.FileUploader: return UploadFile(ssPath); } } if (imageUploader != null) { PrepareUploader(imageUploader); return imageUploader.Upload(ssPath); } return null; }
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); } imageUploader = new Imgur_v3(Program.UploadersConfig.ImgurOAuth2Info) { UploadMethod = Program.UploadersConfig.ImgurAccountType, DirectLink = Program.UploadersConfig.ImgurDirectLink, ThumbnailType = Program.UploadersConfig.ImgurThumbnailType, UploadAlbumID = Program.UploadersConfig.ImgurAlbumID }; 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); break; case ImageDestination.CustomImageUploader: if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomImageUploaderSelected)) { imageUploader = new CustomImageUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomImageUploaderSelected]); } break; } if (imageUploader != null) { PrepareUploader(imageUploader); return(imageUploader.Upload(stream, fileName)); } return(null); }
private async Task TestCustomUploader(CustomUploaderDestinationType type, CustomUploaderItem item) { btnCustomUploaderImageUploaderTest.Enabled = btnCustomUploaderTextUploaderTest.Enabled = btnCustomUploaderFileUploaderTest.Enabled = btnCustomUploaderURLShortenerTest.Enabled = btnCustomUploaderURLSharingServiceTest.Enabled = false; UploadResult result = null; txtCustomUploaderLog.ResetText(); await Task.Run(() => { try { switch (type) { case CustomUploaderDestinationType.ImageUploader: using (Stream stream = ShareXResources.Logo.GetStream()) { CustomImageUploader imageUploader = new CustomImageUploader(item); result = imageUploader.Upload(stream, "Test.png"); result.Errors = imageUploader.Errors; } break; case CustomUploaderDestinationType.TextUploader: CustomTextUploader textUploader = new CustomTextUploader(item); result = textUploader.UploadText("ShareX text upload test", "Test.txt"); result.Errors = textUploader.Errors; break; case CustomUploaderDestinationType.FileUploader: using (Stream stream = ShareXResources.Logo.GetStream()) { CustomFileUploader fileUploader = new CustomFileUploader(item); result = fileUploader.Upload(stream, "Test.png"); result.Errors = fileUploader.Errors; } break; case CustomUploaderDestinationType.URLShortener: CustomURLShortener urlShortener = new CustomURLShortener(item); result = urlShortener.ShortenURL(Links.URL_WEBSITE); result.Errors = urlShortener.Errors; break; case CustomUploaderDestinationType.URLSharingService: CustomURLSharer urlSharer = new CustomURLSharer(item); result = urlSharer.ShareURL(Links.URL_WEBSITE); result.Errors = urlSharer.Errors; break; } } catch (Exception e) { result = new UploadResult(); result.Errors.Add(e.Message); } }); if (!IsDisposed) { if (result != null) { if (((type == CustomUploaderDestinationType.ImageUploader || type == CustomUploaderDestinationType.TextUploader || type == CustomUploaderDestinationType.FileUploader) && !string.IsNullOrEmpty(result.URL)) || (type == CustomUploaderDestinationType.URLShortener && !string.IsNullOrEmpty(result.ShortenedURL)) || (type == CustomUploaderDestinationType.URLSharingService && !result.IsError && !string.IsNullOrEmpty(result.URL))) { 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 = btnCustomUploaderURLSharingServiceTest.Enabled = true; } }