Example #1
0
        private UploadResult UploadScreenshot(string ssPath)
        {
            ImageUploader imageUploader = null;
            UploadResult ur = null;

            if (File.Exists(ssPath))
            {
                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);
                            }

                            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;
                    }
                }

                if (imageUploader != null)
                {
                    ReportProgress(ProgressType.UPDATE_STATUSBAR_DEBUG, string.Format("Uploading {0}.", Path.GetFileName(ssPath)));
                    ur = imageUploader.Upload(ssPath);
                }

                if (ur != null)
                {
                    if (!string.IsNullOrEmpty(ur.URL))
                    {
                        ReportProgress(ProgressType.UPDATE_STATUSBAR_DEBUG, string.Format("Uploaded {0}.", Path.GetFileName(ssPath)));
                    }
                }
                else
                {
                    ReportProgress(ProgressType.UPDATE_STATUSBAR_DEBUG, string.Format("Failed uploading {0}. Try again later.", Path.GetFileName(ssPath)));
                }
            }
            return ur;
        }
Example #2
0
        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;
        }