예제 #1
0
 public YfrogUploader(YfrogOptions options)
 {
     Options = options;
 }
예제 #2
0
 public YfrogUploader(YfrogOptions options)
 {
     Options = options;
 }
예제 #3
0
        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.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;
        }
예제 #4
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;
        }
예제 #5
0
        public UploadResult UploadImage(Stream stream, string fileName)
        {
            ImageUploader imageUploader = null;

            switch (UploadManager.ImageUploader)
            {
                case ImageDestination.ImageShack:
                    imageUploader = new ImageShackUploader(ZKeys.ImageShackKey, Program.UploadersConfig.ImageShackAccountType,
                        Program.UploadersConfig.ImageShackRegistrationCode)
                    {
                        IsPublic = Program.UploadersConfig.ImageShackShowImagesInPublic
                    };
                    break;
                case ImageDestination.TinyPic:
                    imageUploader = new TinyPicUploader(ZKeys.TinyPicID, ZKeys.TinyPicKey, Program.UploadersConfig.TinyPicAccountType,
                        Program.UploadersConfig.TinyPicRegistrationCode);
                    break;
                case ImageDestination.Imgur:
                    imageUploader = new Imgur(Program.UploadersConfig.ImgurAccountType, ZKeys.ImgurAnonymousKey, Program.UploadersConfig.ImgurOAuthInfo)
                    {
                        ThumbnailType = Program.UploadersConfig.ImgurThumbnailType
                    };
                    break;
                case ImageDestination.Flickr:
                    imageUploader = new FlickrUploader(ZKeys.FlickrKey, ZKeys.FlickrSecret, Program.UploadersConfig.FlickrAuthInfo, Program.UploadersConfig.FlickrSettings);
                    break;
                case ImageDestination.Photobucket:
                    imageUploader = new Photobucket(Program.UploadersConfig.PhotobucketOAuthInfo, Program.UploadersConfig.PhotobucketAccountInfo);
                    break;
                case ImageDestination.UploadScreenshot:
                    imageUploader = new UploadScreenshot(ZKeys.UploadScreenshotKey);
                    break;
                case ImageDestination.Twitpic:
                    TwitPicOptions twitPicOptions = new TwitPicOptions();
                    twitPicOptions.Username = Program.UploadersConfig.TwitPicUsername;
                    twitPicOptions.Password = Program.UploadersConfig.TwitPicPassword;
                    twitPicOptions.TwitPicThumbnailMode = Program.UploadersConfig.TwitPicThumbnailMode;
                    twitPicOptions.ShowFull = Program.UploadersConfig.TwitPicShowFull;
                    imageUploader = new TwitPicUploader(twitPicOptions);
                    break;
                case ImageDestination.Twitsnaps:
                    int index = Program.UploadersConfig.TwitterSelectedAccount;

                    if (Program.UploadersConfig.TwitterOAuthInfoList.HasValidIndex(index))
                    {
                        imageUploader = new TwitSnapsUploader(ZKeys.TwitsnapsKey, Program.UploadersConfig.TwitterOAuthInfoList[index]);
                    }
                    break;
                case ImageDestination.yFrog:
                    YfrogOptions yFrogOptions = new YfrogOptions(ZKeys.ImageShackKey);
                    yFrogOptions.Username = Program.UploadersConfig.YFrogUsername;
                    yFrogOptions.Password = Program.UploadersConfig.YFrogPassword;
                    yFrogOptions.Source = Application.ProductName;
                    imageUploader = new YfrogUploader(yFrogOptions);
                    break;
            }

            if (imageUploader != null)
            {
                PrepareUploader(imageUploader);
                return imageUploader.Upload(stream, fileName);
            }

            return null;
        }
예제 #6
0
        private void UploadImage(ImageDestination imageUploaderType, Stream data)
        {
            ImageUploader imageUploader = null;

            switch (imageUploaderType)
            {
                case ImageDestination.ImageShack:
                    imageUploader = new ImageShackUploader(Engine.ConfigUI.ApiKeysConfig.ImageShackKey,
                                                           Engine.ConfigUploaders.ImageShackAccountType,
                                                           Engine.ConfigUploaders.ImageShackRegistrationCode)
                                        {
                                            IsPublic = Engine.ConfigUploaders.ImageShackShowImagesInPublic
                                        };
                    break;
                case ImageDestination.TinyPic:
                    imageUploader = new TinyPicUploader(Engine.ConfigUI.ApiKeysConfig.TinyPicID, Engine.ConfigUI.ApiKeysConfig.TinyPicKey,
                                                        Engine.ConfigUploaders.TinyPicAccountType,
                                                        Engine.ConfigUploaders.TinyPicRegistrationCode);
                    break;
                case ImageDestination.Imgur:
                    imageUploader = new Imgur(Engine.ConfigUploaders.ImgurAccountType, Engine.ConfigUI.ApiKeysConfig.ImgurAnonymousKey,
                                              Engine.ConfigUploaders.ImgurOAuthInfo)
                                        {
                                            ThumbnailType = Engine.ConfigUploaders.ImgurThumbnailType
                                        };
                    break;
                case ImageDestination.Flickr:
                    imageUploader = new FlickrUploader(Engine.ConfigUI.ApiKeysConfig.FlickrKey, Engine.ConfigUI.ApiKeysConfig.FlickrSecret,
                                                       Engine.ConfigUploaders.FlickrAuthInfo,
                                                       Engine.ConfigUploaders.FlickrSettings);
                    break;
                case ImageDestination.Photobucket:
                    imageUploader = new Photobucket(Engine.ConfigUploaders.PhotobucketOAuthInfo,
                                                    Engine.ConfigUploaders.PhotobucketAccountInfo);
                    break;
                case ImageDestination.UploadScreenshot:
                    imageUploader = new UploadScreenshot(Engine.ConfigUI.ApiKeysConfig.UploadScreenshotKey);
                    break;
                case ImageDestination.Twitpic:
                    var twitpicOpt = new TwitPicOptions();
                    twitpicOpt.Username = Engine.ConfigUploaders.TwitPicUsername;
                    twitpicOpt.Password = Engine.ConfigUploaders.TwitPicPassword;
                    // twitpicOpt.TwitPicUploadType = Engine.conf.TwitPicUploadMode;
                    twitpicOpt.TwitPicThumbnailMode = Engine.ConfigUploaders.TwitPicThumbnailMode;
                    twitpicOpt.ShowFull = Engine.ConfigUploaders.TwitPicShowFull;
                    imageUploader = new TwitPicUploader(twitpicOpt);
                    break;
                case ImageDestination.Twitsnaps:
                    imageUploader = new TwitSnapsUploader(Engine.ConfigUI.ApiKeysConfig.TwitsnapsKey, Adapter.TwitterGetActiveAccount());
                    break;
                case ImageDestination.yFrog:
                    var yfrogOp = new YfrogOptions(Engine.ConfigUI.ApiKeysConfig.ImageShackKey);
                    yfrogOp.Username = Engine.ConfigUploaders.YFrogUsername;
                    yfrogOp.Password = Engine.ConfigUploaders.YFrogPassword;
                    yfrogOp.Source = Application.ProductName;
                    // yfrogOp.UploadType = Engine.conf.YfrogUploadMode;
                    imageUploader = new YfrogUploader(yfrogOp);
                    break;
                /*case ImageDestination.MediaWiki:
                    UploadToMediaWiki();
                    break;*/
                case ImageDestination.FileUploader:
                    foreach (FileDestination ft in WorkflowConfig.DestConfig.FileUploaders)
                    {
                        UploadFile(ft, data);
                    }
                    break;
            }

            if (imageUploader != null)
            {
                imageUploader.ProgressChanged += (x) => UploadProgressChanged(x);
                DestinationName = WorkflowConfig.DestConfig.ToStringImageUploaders();
                DebugHelper.WriteLine("Initialized " + DestinationName);

                if (data != null)
                {
                    if (Engine.ConfigUI == null)
                    {
                        Engine.ConfigUI = new XMLSettings();
                    }

                    for (int i = 0; i <= Engine.ConfigUI.ErrorRetryCount; i++)
                    {
                        var ur_remote_img = new UploadResult { LocalFilePath = Info.LocalFilePath };
                        ur_remote_img = imageUploader.Upload(data, Info.FileName);
                        ur_remote_img.Host = imageUploaderType.GetDescription();
                        AddUploadResult(ur_remote_img);
                        Errors = imageUploader.Errors;

                        if (UploadResults.Count > 0 && string.IsNullOrEmpty(UploadResults[UploadResults.Count - 1].URL))
                        {
                            MyWorker.ReportProgress((int)ProgressType.ShowTrayWarning,
                                                    string.Format("Retrying... Attempt {1}",
                                                                  imageUploaderType.GetDescription(), i + 1));
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }