コード例 #1
0
ファイル: PtpImgUploader.cs プロジェクト: viwhi1/TDMaker
        private UploadResult ParseResult(UploadResult result)
        {
            if (result.IsSuccess)
            {
                result.URL = string.Concat("https://ptpimg.me/", result.Response);
            }

            return result;
        }
コード例 #2
0
ファイル: TaskInfo.cs プロジェクト: noscripter/ShareX
        public TaskInfo(TaskSettings taskSettings)
        {
            if (taskSettings == null)
            {
                taskSettings = TaskSettings.GetDefaultTaskSettings();
            }

            TaskSettings = taskSettings;
            Result = new UploadResult();
        }
コード例 #3
0
        public void ParseResponse(UploadResult result, bool isShortenedURL = false)
        {
            if (result != null && !string.IsNullOrEmpty(result.Response))
            {
                regexResult = ParseRegexList(result.Response);

                string url;

                if (!string.IsNullOrEmpty(URL))
                {
                    url = ParseURL(URL);
                }
                else
                {
                    url = result.Response;
                }

                if (isShortenedURL)
                {
                    result.ShortenedURL = url;
                }
                else
                {
                    result.URL = url;
                }

                result.ThumbnailURL = ParseURL(ThumbnailURL);
                result.DeletionURL = ParseURL(DeletionURL);
            }
        }
コード例 #4
0
        private void TestCustomUploader(CustomUploaderType type, CustomUploaderItem item)
        {
            btnCustomUploaderImageUploaderTest.Enabled = btnCustomUploaderTextUploaderTest.Enabled =
                btnCustomUploaderFileUploaderTest.Enabled = btnCustomUploaderURLShortenerTest.Enabled = false;

            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("ShareX 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 (!IsDisposed)
                {
                    if (result != null)
                    {
                        if ((type != CustomUploaderType.URL && !string.IsNullOrEmpty(result.URL)) || (type == CustomUploaderType.URL && !string.IsNullOrEmpty(result.ShortenedURL)))
                        {
                            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 = true;
                }
            });
        }
コード例 #5
0
ファイル: Uploader.cs プロジェクト: yuhongfang/ShareX
        protected UploadResult UploadData(Stream dataStream, string url, string fileName, string fileFormName = "file", Dictionary<string, string> arguments = null,
            NameValueCollection headers = null, CookieCollection cookies = null, ResponseType responseType = ResponseType.Text, HttpMethod method = HttpMethod.POST,
            string requestContentType = "multipart/form-data", string metadata = null)
        {
            UploadResult result = new UploadResult();

            IsUploading = true;
            StopUploadRequested = false;

            try
            {
                string boundary = CreateBoundary();

                byte[] bytesArguments = MakeInputContent(boundary, arguments, false);
                byte[] bytesDataOpen;
                byte[] bytesDataDatafile = { };

                if (metadata != null)
                {
                    bytesDataOpen = MakeFileInputContentOpen(boundary, fileFormName, fileName, metadata);
                    bytesDataDatafile = MakeFileInputContentOpen(boundary, fileFormName, fileName, null);
                }
                else
                {
                    bytesDataOpen = MakeFileInputContentOpen(boundary, fileFormName, fileName);
                }

                byte[] bytesDataClose = MakeFileInputContentClose(boundary);

                long contentLength = bytesArguments.Length + bytesDataOpen.Length + bytesDataDatafile.Length + dataStream.Length + bytesDataClose.Length;
                HttpWebRequest request = PrepareDataWebRequest(url, boundary, contentLength, requestContentType, cookies, headers, method);

                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(bytesArguments, 0, bytesArguments.Length);
                    requestStream.Write(bytesDataOpen, 0, bytesDataOpen.Length);
                    requestStream.Write(bytesDataDatafile, 0, bytesDataDatafile.Length);
                    if (!TransferData(dataStream, requestStream)) return null;
                    requestStream.Write(bytesDataClose, 0, bytesDataClose.Length);
                }

                result.Response = ResponseToString(request.GetResponse(), responseType);
                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                if (!StopUploadRequested)
                {
                    if (WebExceptionThrow && e is WebException)
                    {
                        throw;
                    }

                    string response = AddWebError(e);

                    if (WebExceptionReturnResponse && e is WebException)
                    {
                        result.Response = response;
                    }
                }
            }
            finally
            {
                currentRequest = null;
                IsUploading = false;
            }

            return result;
        }
コード例 #6
0
ファイル: WorkerTask.cs プロジェクト: Xanaxiel/ShareX
        private UploadResult GetInvalidConfigResult(IUploaderService uploaderService)
        {
            UploadResult ur = new UploadResult();
            // TODO: Translate
            string message = string.Format("{0} configuration is invalid or missing. Please check \"Destination settings\" window to configure it.", uploaderService.ServiceName);
            DebugHelper.WriteLine(message);
            ur.Errors.Add(message);

            OnUploadersConfigWindowRequested(uploaderService);

            return ur;
        }
コード例 #7
0
ファイル: WorkerTask.cs プロジェクト: RailTracker/ShareX
        private UploadResult GetInvalidConfigResult(IUploaderService uploaderService)
        {
            UploadResult ur = new UploadResult();

            string message = string.Format(Resources.WorkerTask_GetInvalidConfigResult__0__configuration_is_invalid_or_missing__Please_check__Destination_settings__window_to_configure_it_,
                uploaderService.ServiceName);
            DebugHelper.WriteLine(message);
            ur.Errors.Add(message);

            OnUploadersConfigWindowRequested(uploaderService);

            return ur;
        }
コード例 #8
0
ファイル: Uploader.cs プロジェクト: wowweemip-fan/ShareX
        protected UploadResult SendRequestFile(string url, Stream data, string fileName, string fileFormName = "file", Dictionary <string, string> args = null,
                                               NameValueCollection headers = null, CookieCollection cookies                = null, ResponseType responseType = ResponseType.Text, HttpMethod method = HttpMethod.POST,
                                               string contentType          = ContentTypeMultipartFormData, string metadata = null)
        {
            UploadResult result = new UploadResult();

            IsUploading         = true;
            StopUploadRequested = false;

            try
            {
                string boundary = CreateBoundary();
                contentType += "; boundary=" + boundary;

                byte[] bytesArguments = MakeInputContent(boundary, args, false);
                byte[] bytesDataOpen;
                byte[] bytesDataDatafile = { };

                if (metadata != null)
                {
                    bytesDataOpen     = MakeFileInputContentOpen(boundary, fileFormName, fileName, metadata);
                    bytesDataDatafile = MakeFileInputContentOpen(boundary, fileFormName, fileName, null);
                }
                else
                {
                    bytesDataOpen = MakeFileInputContentOpen(boundary, fileFormName, fileName);
                }

                byte[] bytesDataClose = MakeFileInputContentClose(boundary);

                long contentLength = bytesArguments.Length + bytesDataOpen.Length + bytesDataDatafile.Length + data.Length + bytesDataClose.Length;

                HttpWebRequest request = CreateWebRequest(method, url, headers, cookies, contentType, contentLength);

                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(bytesArguments, 0, bytesArguments.Length);
                    requestStream.Write(bytesDataOpen, 0, bytesDataOpen.Length);
                    requestStream.Write(bytesDataDatafile, 0, bytesDataDatafile.Length);
                    if (!TransferData(data, requestStream))
                    {
                        return(null);
                    }
                    requestStream.Write(bytesDataClose, 0, bytesDataClose.Length);
                }

                using (WebResponse response = request.GetResponse())
                {
                    result.Response = ResponseToString(response, responseType);
                }

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                if (!StopUploadRequested)
                {
                    string response = AddWebError(e, url);

                    if (ReturnResponseOnError && e is WebException)
                    {
                        result.Response = response;
                    }
                }
            }
            finally
            {
                currentRequest = null;
                IsUploading    = false;

                if (VerboseLogs && !string.IsNullOrEmpty(VerboseLogsPath))
                {
                    WriteVerboseLog(url, args, headers, result.Response);
                }
            }

            return(result);
        }
コード例 #9
0
ファイル: Uploader.cs プロジェクト: wowweemip-fan/ShareX
        protected UploadResult SendRequestBytes(string url, Stream data, string fileName, long contentPosition = 0, long contentLength = -1, Dictionary <string, string> args = null,
                                                NameValueCollection headers = null, CookieCollection cookies = null, ResponseType responseType = ResponseType.Text, HttpMethod method = HttpMethod.PUT)
        {
            UploadResult result = new UploadResult();

            IsUploading         = true;
            StopUploadRequested = false;

            try
            {
                url = URLHelpers.CreateQuery(url, args);

                if (contentLength == -1)
                {
                    contentLength = data.Length;
                }
                contentLength = Math.Min(contentLength, data.Length - contentPosition);

                string contentType = Helpers.GetMimeType(fileName);

                if (headers == null)
                {
                    headers = new NameValueCollection();
                }
                long startByte  = contentPosition;
                long endByte    = startByte + contentLength - 1;
                long dataLength = data.Length;
                headers.Add("Content-Range", $"bytes {startByte}-{endByte}/{dataLength}");

                HttpWebRequest request = CreateWebRequest(method, url, headers, cookies, contentType, contentLength);

                using (Stream requestStream = request.GetRequestStream())
                {
                    if (!TransferData(data, requestStream, contentPosition, contentLength))
                    {
                        return(null);
                    }
                }

                using (WebResponse response = request.GetResponse())
                {
                    result.Response = ResponseToString(response, responseType);
                }

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                if (!StopUploadRequested)
                {
                    string response = AddWebError(e, url);

                    if (ReturnResponseOnError && e is WebException)
                    {
                        result.Response = response;
                    }
                }
            }
            finally
            {
                currentRequest = null;
                IsUploading    = false;

                if (VerboseLogs && !string.IsNullOrEmpty(VerboseLogsPath))
                {
                    WriteVerboseLog(url, args, headers, result.Response);
                }
            }

            return(result);
        }
コード例 #10
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();
            rtbResponseText.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();
                    rtbResponseText.Text = result.ResponseInfo?.ResponseText;

                    tcCustomUploader.SelectedTab = tpTest;
                }

                btnImageUploaderTest.Enabled    = btnTextUploaderTest.Enabled = btnFileUploaderTest.Enabled =
                    btnURLShortenerTest.Enabled = btnURLSharingServiceTest.Enabled = true;
            }
        }
コード例 #11
0
        protected UploadResult UploadData(Stream dataStream, string url, string fileName, string fileFormName = "file", Dictionary <string, string> arguments = null,
                                          NameValueCollection headers = null, CookieCollection cookies         = null, ResponseType responseType = ResponseType.Text, HttpMethod method = HttpMethod.POST,
                                          string requestContentType   = "multipart/form-data", string metadata = null)
        {
            UploadResult result = new UploadResult();

            IsUploading         = true;
            StopUploadRequested = false;

            try
            {
                string boundary = CreateBoundary();

                byte[] bytesArguments = MakeInputContent(boundary, arguments, false);
                byte[] bytesDataOpen;
                byte[] bytesDataDatafile = { };

                if (metadata != null)
                {
                    bytesDataOpen     = MakeFileInputContentOpen(boundary, fileFormName, fileName, metadata);
                    bytesDataDatafile = MakeFileInputContentOpen(boundary, fileFormName, fileName, null);
                }
                else
                {
                    bytesDataOpen = MakeFileInputContentOpen(boundary, fileFormName, fileName);
                }

                byte[] bytesDataClose = MakeFileInputContentClose(boundary);

                long           contentLength = bytesArguments.Length + bytesDataOpen.Length + bytesDataDatafile.Length + dataStream.Length + bytesDataClose.Length;
                HttpWebRequest request       = PrepareDataWebRequest(url, boundary, contentLength, requestContentType, cookies, headers, method);

                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(bytesArguments, 0, bytesArguments.Length);
                    requestStream.Write(bytesDataOpen, 0, bytesDataOpen.Length);
                    requestStream.Write(bytesDataDatafile, 0, bytesDataDatafile.Length);
                    if (!TransferData(dataStream, requestStream))
                    {
                        return(null);
                    }
                    requestStream.Write(bytesDataClose, 0, bytesDataClose.Length);
                }

                result.Response  = ResponseToString(request.GetResponse(), responseType);
                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                if (!StopUploadRequested)
                {
                    if (ThrowWebExceptions && e is WebException)
                    {
                        throw;
                    }
                    AddWebError(e);
                }
            }
            finally
            {
                currentRequest = null;
                IsUploading    = false;
            }

            return(result);
        }
コード例 #12
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);
                        using (TextUploadForm form = new TextUploadForm("ShareX text upload test"))
                        {
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                string text = form.Content;

                                if (!string.IsNullOrEmpty(text))
                                {
                                    result = textUploader.UploadText(text, "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.Website);
                        result.Errors.AddRange(urlShortener.Errors);
                        break;

                    case CustomUploaderDestinationType.URLSharingService:
                        CustomURLSharer urlSharer = new CustomURLSharer(item);
                        result = urlSharer.ShareURL(Links.Website);
                        result.Errors.AddRange(urlSharer.Errors);
                        break;
                    }
                }
                catch (Exception e)
                {
                    result = new UploadResult();
                    result.Errors.Add(e.Message);
                }
            });

            if (!IsDisposed)
            {
                lastResult = result;

                if (result != null)
                {
                    ResponseForm.ShowInstance(result);
                }

                btnImageUploaderTest.Enabled    = btnTextUploaderTest.Enabled = btnFileUploaderTest.Enabled =
                    btnURLShortenerTest.Enabled = btnURLSharingServiceTest.Enabled = true;
            }
        }
コード例 #13
0
        protected UploadResult SendRequestFile(string url, Stream data, string fileName, string fileFormName, Dictionary <string, string> args = null,
                                               NameValueCollection headers = null, CookieCollection cookies = null, HttpMethod method = HttpMethod.POST, string contentType = RequestHelpers.ContentTypeMultipartFormData,
                                               string relatedData          = null)
        {
            UploadResult result = new UploadResult();

            IsUploading         = true;
            StopUploadRequested = false;

            try
            {
                string boundary = RequestHelpers.CreateBoundary();
                contentType += "; boundary=" + boundary;

                byte[] bytesArguments = RequestHelpers.MakeInputContent(boundary, args, false);
                byte[] bytesDataOpen;

                if (relatedData != null)
                {
                    bytesDataOpen = RequestHelpers.MakeRelatedFileInputContentOpen(boundary, "application/json; charset=UTF-8", relatedData, fileName);
                }
                else
                {
                    bytesDataOpen = RequestHelpers.MakeFileInputContentOpen(boundary, fileFormName, fileName);
                }

                byte[] bytesDataClose = RequestHelpers.MakeFileInputContentClose(boundary);

                long contentLength = bytesArguments.Length + bytesDataOpen.Length + data.Length + bytesDataClose.Length;

                HttpWebRequest request = CreateWebRequest(method, url, headers, cookies, contentType, contentLength);

                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(bytesArguments, 0, bytesArguments.Length);
                    requestStream.Write(bytesDataOpen, 0, bytesDataOpen.Length);
                    if (!TransferData(data, requestStream))
                    {
                        return(null);
                    }
                    requestStream.Write(bytesDataClose, 0, bytesDataClose.Length);
                }

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    result.ResponseInfo = ProcessWebResponse(response);
                    result.Response     = result.ResponseInfo?.ResponseText;
                }

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                if (!StopUploadRequested)
                {
                    string response = ProcessError(e, url);

                    if (ReturnResponseOnError && e is WebException)
                    {
                        result.Response = response;
                    }
                }
            }
            finally
            {
                currentWebRequest = null;
                IsUploading       = false;
            }

            return(result);
        }
コード例 #14
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;
            }
        }