예제 #1
0
        private void TestCustomUploader(CustomUploaderType type, CustomUploaderItem item)
        {
            UploadResult result = null;

            txtCustomUploaderLog.ResetText();

            TaskEx.Run(() =>
            {
                try
                {
                    switch (type)
                    {
                        case CustomUploaderType.Image:
                            using (Stream stream = ShareXResources.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(Application.ProductName + " text upload test", "Test.txt");
                            result.Errors = textUploader.Errors;
                            break;
                        case CustomUploaderType.File:
                            using (Stream stream = ShareXResources.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 (result != null)
                {
                    if ((type != CustomUploaderType.URL && !string.IsNullOrEmpty(result.URL)) || (type == CustomUploaderType.URL && !string.IsNullOrEmpty(result.ShortenedURL)))
                    {
                        txtCustomUploaderLog.AppendText("URL: " + result + Environment.NewLine);
                    }
                    else if (result.IsError)
                    {
                        txtCustomUploaderLog.AppendText("Error: " + result.ErrorsToString() + Environment.NewLine);
                    }
                    else
                    {
                        txtCustomUploaderLog.AppendText("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;
            });
        }
예제 #2
0
파일: UploadTask.cs 프로젝트: rijuG/ShareX
        public UploadResult ShortenURL(string url)
        {
            URLShortener urlShortener = null;

            switch (Info.TaskSettings.URLShortenerDestination)
            {
                case UrlShortenerType.BITLY:
                    if (Program.UploadersConfig.BitlyOAuth2Info == null)
                    {
                        Program.UploadersConfig.BitlyOAuth2Info = new OAuth2Info(APIKeys.BitlyClientID, APIKeys.BitlyClientSecret);
                    }

                    urlShortener = new BitlyURLShortener(Program.UploadersConfig.BitlyOAuth2Info)
                    {
                        Domain = Program.UploadersConfig.BitlyDomain
                    };
                    break;
                case UrlShortenerType.Google:
                    urlShortener = new GoogleURLShortener(Program.UploadersConfig.GoogleURLShortenerAccountType, APIKeys.GoogleAPIKey,
                        Program.UploadersConfig.GoogleURLShortenerOAuth2Info);
                    break;
                case UrlShortenerType.ISGD:
                    urlShortener = new IsgdURLShortener();
                    break;
                case UrlShortenerType.TINYURL:
                    urlShortener = new TinyURLShortener();
                    break;
                case UrlShortenerType.TURL:
                    urlShortener = new TurlURLShortener();
                    break;
                case UrlShortenerType.YOURLS:
                    urlShortener = new YourlsURLShortener
                    {
                        APIURL = Program.UploadersConfig.YourlsAPIURL,
                        Signature = Program.UploadersConfig.YourlsSignature,
                        Username = Program.UploadersConfig.YourlsUsername,
                        Password = Program.UploadersConfig.YourlsPassword
                    };
                    break;
                case UrlShortenerType.NLCM:
                    urlShortener = new NlcmURLShortener();
                    break;
                case UrlShortenerType.AdFly:
                    urlShortener = new AdFlyURLShortener
                    {
                        APIKEY = Program.UploadersConfig.AdFlyAPIKEY,
                        APIUID = Program.UploadersConfig.AdFlyAPIUID
                    };
                    break;
                case UrlShortenerType.CustomURLShortener:
                    if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomURLShortenerSelected))
                    {
                        urlShortener = new CustomURLShortener(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomURLShortenerSelected]);
                    }
                    break;
            }

            if (urlShortener != null)
            {
                return urlShortener.ShortenURL(url);
            }

            return null;
        }
예제 #3
0
        public UploadResult ShortenURL(string url)
        {
            URLShortener urlShortener = null;

            switch (Info.TaskSettings.URLShortenerDestination)
            {
                case UrlShortenerType.BITLY:
                    urlShortener = new BitlyURLShortener(ApiKeys.BitlyLogin, ApiKeys.BitlyKey);
                    break;
                case UrlShortenerType.Google:
                    urlShortener = new GoogleURLShortener(Program.UploadersConfig.GoogleURLShortenerAccountType, ApiKeys.GoogleAPIKey,
                        Program.UploadersConfig.GoogleURLShortenerOAuth2Info);
                    break;
                case UrlShortenerType.ISGD:
                    urlShortener = new IsgdURLShortener();
                    break;
                case UrlShortenerType.Jmp:
                    urlShortener = new JmpURLShortener(ApiKeys.BitlyLogin, ApiKeys.BitlyKey);
                    break;
                /*case UrlShortenerType.THREELY:
                urlShortener = new ThreelyURLShortener(Program.ThreelyKey);
                break;*/
                case UrlShortenerType.TINYURL:
                    urlShortener = new TinyURLShortener();
                    break;
                case UrlShortenerType.TURL:
                    urlShortener = new TurlURLShortener();
                    break;
                case UrlShortenerType.CustomURLShortener:
                    if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomURLShortenerSelected))
                    {
                        urlShortener = new CustomURLShortener(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomURLShortenerSelected]);
                    }
                    break;
            }

            if (urlShortener != null)
            {
                return urlShortener.ShortenURL(url);
            }

            return null;
        }