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;
        }
        public void ImgurAuthOpen()
        {
            try
            {
                OAuthInfo oauth = new OAuthInfo(APIKeys.ImgurConsumerKey, APIKeys.ImgurConsumerSecret);

                string url = new Imgur(oauth).GetAuthorizationURL();

                if (!string.IsNullOrEmpty(url))
                {
                    Config.ImgurOAuthInfo = oauth;
                    ZAppHelper.LoadBrowserAsync(url);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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;
                        }
                    }
                }
            }
        }
        public void ImgurAuthComplete()
        {
            try
            {
                string verification = txtImgurVerificationCode.Text;

                if (!string.IsNullOrEmpty(verification) && Config.ImgurOAuthInfo != null &&
                    !string.IsNullOrEmpty(Config.ImgurOAuthInfo.AuthToken) && !string.IsNullOrEmpty(Config.ImgurOAuthInfo.AuthSecret))
                {
                    bool result = new Imgur(Config.ImgurOAuthInfo).GetAccessToken(verification);

                    if (result)
                    {
                        lblImgurAccountStatus.Text = "Login successful: " + Config.ImgurOAuthInfo.UserToken;
                        MessageBox.Show("Login successful.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        lblImgurAccountStatus.Text = "Login failed.";
                        MessageBox.Show("Login failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        atcImgurAccountType.SelectedAccountType = AccountType.Anonymous;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }