mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Added UploaderErrorManager
This commit is contained in:
parent
5f1a4efa8e
commit
810203a891
11 changed files with 156 additions and 25 deletions
|
@ -41,7 +41,7 @@ public class Uploader
|
||||||
public event Action<string> EarlyURLCopyRequested;
|
public event Action<string> EarlyURLCopyRequested;
|
||||||
|
|
||||||
public bool IsUploading { get; protected set; }
|
public bool IsUploading { get; protected set; }
|
||||||
public List<string> Errors { get; private set; } = new List<string>();
|
public UploaderErrorManager Errors { get; private set; } = new UploaderErrorManager();
|
||||||
public bool IsError => !StopUploadRequested && Errors != null && Errors.Count > 0;
|
public bool IsError => !StopUploadRequested && Errors != null && Errors.Count > 0;
|
||||||
public int BufferSize { get; set; } = 8192;
|
public int BufferSize { get; set; } = 8192;
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ private string ProcessError(Exception e, string requestURL)
|
||||||
|
|
||||||
string errorText = sb.ToString();
|
string errorText = sb.ToString();
|
||||||
|
|
||||||
if (Errors == null) Errors = new List<string>();
|
if (Errors == null) Errors = new UploaderErrorManager();
|
||||||
Errors.Add(errorText);
|
Errors.Add(errorText);
|
||||||
|
|
||||||
DebugHelper.WriteLine("Error:\r\n" + errorText);
|
DebugHelper.WriteLine("Error:\r\n" + errorText);
|
||||||
|
|
|
@ -303,7 +303,7 @@ public string CreateShareableLink(string path, bool directLink)
|
||||||
{
|
{
|
||||||
linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response);
|
linkMetadata = JsonConvert.DeserializeObject<DropboxLinkMetadata>(response);
|
||||||
}
|
}
|
||||||
else if (IsError && Errors[Errors.Count - 1].Contains("\"shared_link_already_exists\"")) // Ugly workaround
|
else if (IsError && Errors.Errors[Errors.Count - 1].Text.Contains("\"shared_link_already_exists\"")) // Ugly workaround
|
||||||
{
|
{
|
||||||
DropboxListSharedLinksResult result = ListSharedLinks(path, true);
|
DropboxListSharedLinksResult result = ListSharedLinks(path, true);
|
||||||
|
|
||||||
|
|
|
@ -269,7 +269,7 @@ private string GetSummary(string issueId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This query can returns error so we have to remove last error from errors list
|
// This query can returns error so we have to remove last error from errors list
|
||||||
Errors.RemoveAt(Errors.Count - 1);
|
Errors.Errors.RemoveAt(Errors.Count - 1);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace ShareX.UploadersLib.FileUploaders
|
namespace ShareX.UploadersLib.FileUploaders
|
||||||
{
|
{
|
||||||
|
@ -39,7 +38,7 @@ public static class SendSpaceManager
|
||||||
public static string Password;
|
public static string Password;
|
||||||
public static SendSpace.UploadInfo UploadInfo;
|
public static SendSpace.UploadInfo UploadInfo;
|
||||||
|
|
||||||
public static List<string> PrepareUploadInfo(string apiKey, string username = null, string password = null)
|
public static UploaderErrorManager PrepareUploadInfo(string apiKey, string username = null, string password = null)
|
||||||
{
|
{
|
||||||
SendSpace sendSpace = new SendSpace(apiKey);
|
SendSpace sendSpace = new SendSpace(apiKey);
|
||||||
|
|
||||||
|
|
|
@ -623,7 +623,7 @@ await Task.Run(() =>
|
||||||
{
|
{
|
||||||
CustomImageUploader imageUploader = new CustomImageUploader(item);
|
CustomImageUploader imageUploader = new CustomImageUploader(item);
|
||||||
result = imageUploader.Upload(stream, "Test.png");
|
result = imageUploader.Upload(stream, "Test.png");
|
||||||
result.Errors.AddRange(imageUploader.Errors);
|
result.Errors.Add(imageUploader.Errors);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CustomUploaderDestinationType.TextUploader:
|
case CustomUploaderDestinationType.TextUploader:
|
||||||
|
@ -637,7 +637,7 @@ await Task.Run(() =>
|
||||||
if (!string.IsNullOrEmpty(text))
|
if (!string.IsNullOrEmpty(text))
|
||||||
{
|
{
|
||||||
result = textUploader.UploadText(text, "Test.txt");
|
result = textUploader.UploadText(text, "Test.txt");
|
||||||
result.Errors.AddRange(textUploader.Errors);
|
result.Errors.Add(textUploader.Errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -647,18 +647,18 @@ await Task.Run(() =>
|
||||||
{
|
{
|
||||||
CustomFileUploader fileUploader = new CustomFileUploader(item);
|
CustomFileUploader fileUploader = new CustomFileUploader(item);
|
||||||
result = fileUploader.Upload(stream, "Test.png");
|
result = fileUploader.Upload(stream, "Test.png");
|
||||||
result.Errors.AddRange(fileUploader.Errors);
|
result.Errors.Add(fileUploader.Errors);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CustomUploaderDestinationType.URLShortener:
|
case CustomUploaderDestinationType.URLShortener:
|
||||||
CustomURLShortener urlShortener = new CustomURLShortener(item);
|
CustomURLShortener urlShortener = new CustomURLShortener(item);
|
||||||
result = urlShortener.ShortenURL(Links.Website);
|
result = urlShortener.ShortenURL(Links.Website);
|
||||||
result.Errors.AddRange(urlShortener.Errors);
|
result.Errors.Add(urlShortener.Errors);
|
||||||
break;
|
break;
|
||||||
case CustomUploaderDestinationType.URLSharingService:
|
case CustomUploaderDestinationType.URLSharingService:
|
||||||
CustomURLSharer urlSharer = new CustomURLSharer(item);
|
CustomURLSharer urlSharer = new CustomURLSharer(item);
|
||||||
result = urlSharer.ShareURL(Links.Website);
|
result = urlSharer.ShareURL(Links.Website);
|
||||||
result.Errors.AddRange(urlSharer.Errors);
|
result.Errors.Add(urlSharer.Errors);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
42
ShareX.UploadersLib/Helpers/UploaderErrorInfo.cs
Normal file
42
ShareX.UploadersLib/Helpers/UploaderErrorInfo.cs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#region License Information (GPL v3)
|
||||||
|
|
||||||
|
/*
|
||||||
|
ShareX - A program that allows you to take screenshots and share any file type
|
||||||
|
Copyright (c) 2007-2022 ShareX Team
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ShareX.UploadersLib
|
||||||
|
{
|
||||||
|
public class UploaderErrorInfo
|
||||||
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Text { get; set; }
|
||||||
|
public Exception Exception { get; set; }
|
||||||
|
|
||||||
|
public UploaderErrorInfo(string title, string text)
|
||||||
|
{
|
||||||
|
Title = title;
|
||||||
|
Text = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
74
ShareX.UploadersLib/Helpers/UploaderErrorManager.cs
Normal file
74
ShareX.UploadersLib/Helpers/UploaderErrorManager.cs
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#region License Information (GPL v3)
|
||||||
|
|
||||||
|
/*
|
||||||
|
ShareX - A program that allows you to take screenshots and share any file type
|
||||||
|
Copyright (c) 2007-2022 ShareX Team
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
|
using ShareX.UploadersLib.Properties;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ShareX.UploadersLib
|
||||||
|
{
|
||||||
|
public class UploaderErrorManager
|
||||||
|
{
|
||||||
|
public List<UploaderErrorInfo> Errors { get; private set; }
|
||||||
|
|
||||||
|
public int Count => Errors.Count;
|
||||||
|
|
||||||
|
public UploaderErrorManager()
|
||||||
|
{
|
||||||
|
Errors = new List<UploaderErrorInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(string text)
|
||||||
|
{
|
||||||
|
Add(Resources.Error, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(string title, string text)
|
||||||
|
{
|
||||||
|
Errors.Add(new UploaderErrorInfo(title, text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(UploaderErrorManager manager)
|
||||||
|
{
|
||||||
|
Errors.AddRange(manager.Errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Insert(int index, string text)
|
||||||
|
{
|
||||||
|
Insert(index, Resources.Error, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Insert(int index, string title, string text)
|
||||||
|
{
|
||||||
|
Errors.Insert(index, new UploaderErrorInfo(title, text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Join(Environment.NewLine + Environment.NewLine, Errors.Select(x => x.Text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -254,6 +254,7 @@
|
||||||
<Compile Include="Helpers\MimeTypes.cs" />
|
<Compile Include="Helpers\MimeTypes.cs" />
|
||||||
<Compile Include="Helpers\ResponseInfo.cs" />
|
<Compile Include="Helpers\ResponseInfo.cs" />
|
||||||
<Compile Include="Helpers\RequestHelpers.cs" />
|
<Compile Include="Helpers\RequestHelpers.cs" />
|
||||||
|
<Compile Include="Helpers\UploaderErrorManager.cs" />
|
||||||
<Compile Include="OAuth\GoogleOAuth2.cs" />
|
<Compile Include="OAuth\GoogleOAuth2.cs" />
|
||||||
<Compile Include="OAuth\IOAuthBase.cs" />
|
<Compile Include="OAuth\IOAuthBase.cs" />
|
||||||
<Compile Include="OAuth\OAuth2ProofKey.cs" />
|
<Compile Include="OAuth\OAuth2ProofKey.cs" />
|
||||||
|
@ -284,6 +285,7 @@
|
||||||
<Compile Include="BaseServices\TextUploaderService.cs" />
|
<Compile Include="BaseServices\TextUploaderService.cs" />
|
||||||
<Compile Include="TextUploaders\Pastie.cs" />
|
<Compile Include="TextUploaders\Pastie.cs" />
|
||||||
<Compile Include="TextUploaders\TeknikPastebin.cs" />
|
<Compile Include="TextUploaders\TeknikPastebin.cs" />
|
||||||
|
<Compile Include="Helpers\UploaderErrorInfo.cs" />
|
||||||
<Compile Include="UploaderFactory.cs" />
|
<Compile Include="UploaderFactory.cs" />
|
||||||
<Compile Include="ImageUploaders\Chevereto.cs" />
|
<Compile Include="ImageUploaders\Chevereto.cs" />
|
||||||
<Compile Include="ImageUploaders\CheveretoUploader.cs" />
|
<Compile Include="ImageUploaders\CheveretoUploader.cs" />
|
||||||
|
|
|
@ -24,8 +24,6 @@ You should have received a copy of the GNU General Public License
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace ShareX.UploadersLib
|
namespace ShareX.UploadersLib
|
||||||
|
@ -52,7 +50,7 @@ public bool IsSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Response { get; set; }
|
public string Response { get; set; }
|
||||||
public List<string> Errors { get; set; }
|
public UploaderErrorManager Errors { get; set; }
|
||||||
public bool IsURLExpected { get; set; }
|
public bool IsURLExpected { get; set; }
|
||||||
|
|
||||||
public bool IsError
|
public bool IsError
|
||||||
|
@ -67,7 +65,7 @@ public bool IsError
|
||||||
|
|
||||||
public UploadResult()
|
public UploadResult()
|
||||||
{
|
{
|
||||||
Errors = new List<string>();
|
Errors = new UploaderErrorManager();
|
||||||
IsURLExpected = true;
|
IsURLExpected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +102,7 @@ public string ErrorsToString()
|
||||||
{
|
{
|
||||||
if (IsError)
|
if (IsError)
|
||||||
{
|
{
|
||||||
return string.Join(Environment.NewLine + Environment.NewLine, Errors.ToArray());
|
return Errors.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -300,7 +300,7 @@ private static void Task_TaskCompleted(WorkerTask task)
|
||||||
}
|
}
|
||||||
else if (task.Status == TaskStatus.Failed)
|
else if (task.Status == TaskStatus.Failed)
|
||||||
{
|
{
|
||||||
string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray());
|
string errors = info.Result.Errors.ToString();
|
||||||
|
|
||||||
DebugHelper.WriteLine($"Task failed. File name: {info.FileName}, Errors:\r\n{errors}");
|
DebugHelper.WriteLine($"Task failed. File name: {info.FileName}, Errors:\r\n{errors}");
|
||||||
|
|
||||||
|
@ -320,12 +320,18 @@ private static void Task_TaskCompleted(WorkerTask task)
|
||||||
|
|
||||||
if (info.Result.Errors.Count > 0)
|
if (info.Result.Errors.Count > 0)
|
||||||
{
|
{
|
||||||
string errorMessage = info.Result.Errors[0];
|
UploaderErrorInfo error = info.Result.Errors.Errors[0];
|
||||||
|
|
||||||
if (info.TaskSettings.GeneralSettings.ShowToastNotificationAfterTaskCompleted && !string.IsNullOrEmpty(errorMessage) &&
|
string title = error.Title;
|
||||||
|
if (string.IsNullOrEmpty(title))
|
||||||
|
{
|
||||||
|
title = Resources.TaskManager_task_UploadCompleted_Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.TaskSettings.GeneralSettings.ShowToastNotificationAfterTaskCompleted && !string.IsNullOrEmpty(error.Text) &&
|
||||||
(!info.TaskSettings.GeneralSettings.DisableNotificationsOnFullscreen || !CaptureHelpers.IsActiveWindowFullscreen()))
|
(!info.TaskSettings.GeneralSettings.DisableNotificationsOnFullscreen || !CaptureHelpers.IsActiveWindowFullscreen()))
|
||||||
{
|
{
|
||||||
TaskHelpers.ShowNotificationTip(errorMessage, "ShareX - " + Resources.TaskManager_task_UploadCompleted_Error, 5000);
|
TaskHelpers.ShowNotificationTip(error.Text, "ShareX - " + title, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -526,7 +526,7 @@ private bool DoUpload(Stream data, string fileName, int retry = 0)
|
||||||
|
|
||||||
if (uploader != null)
|
if (uploader != null)
|
||||||
{
|
{
|
||||||
AddErrorMessage(uploader.Errors.ToArray());
|
AddErrorMessage(uploader.Errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
isError |= Info.Result.IsError;
|
isError |= Info.Result.IsError;
|
||||||
|
@ -535,14 +535,24 @@ private bool DoUpload(Stream data, string fileName, int retry = 0)
|
||||||
return isError;
|
return isError;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddErrorMessage(params string[] errorMessages)
|
private void AddErrorMessage(UploaderErrorManager errors)
|
||||||
{
|
{
|
||||||
if (Info.Result == null)
|
if (Info.Result == null)
|
||||||
{
|
{
|
||||||
Info.Result = new UploadResult();
|
Info.Result = new UploadResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
Info.Result.Errors.AddRange(errorMessages);
|
Info.Result.Errors.Add(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddErrorMessage(string error)
|
||||||
|
{
|
||||||
|
if (Info.Result == null)
|
||||||
|
{
|
||||||
|
Info.Result = new UploadResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
Info.Result.Errors.Add(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool DoThreadJob()
|
private bool DoThreadJob()
|
||||||
|
@ -840,7 +850,7 @@ private void DoAfterUploadJobs()
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
Info.Result.ShortenedURL = result.ShortenedURL;
|
Info.Result.ShortenedURL = result.ShortenedURL;
|
||||||
Info.Result.Errors.AddRange(result.Errors);
|
Info.Result.Errors.Add(result.Errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,7 +860,7 @@ private void DoAfterUploadJobs()
|
||||||
|
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
Info.Result.Errors.AddRange(result.Errors);
|
Info.Result.Errors.Add(result.Errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Info.Job == TaskJob.ShareURL)
|
if (Info.Job == TaskJob.ShareURL)
|
||||||
|
|
Loading…
Reference in a new issue