예제 #1
0
        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;
            }
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        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;
            }
        }