Table of Contents

Class BaseUploadQueue

Namespace
Ink_Canvas.Helpers
Assembly
InkCanvasForClass.dll

通用上传队列基类

public abstract class BaseUploadQueue : IDisposable
Inheritance
BaseUploadQueue
Implements
Derived
Inherited Members

Fields

BATCH_SIZE

protected const int BATCH_SIZE = 10

Field Value

int

MAX_RETRY_COUNT

protected const int MAX_RETRY_COUNT = 3

Field Value

int

_isQueueInitialized

是否已初始化队列

protected bool _isQueueInitialized

Field Value

bool

_queueProcessingLock

队列处理锁,防止并发处理

protected readonly SemaphoreSlim _queueProcessingLock

Field Value

SemaphoreSlim

_queueSaveLock

队列保存锁,防止并发保存

protected readonly SemaphoreSlim _queueSaveLock

Field Value

SemaphoreSlim

_uploadQueue

上传队列

protected readonly ConcurrentQueue<UploadQueueItem> _uploadQueue

Field Value

ConcurrentQueue<UploadQueueItem>

Properties

AllowedExtensions

允许的文件扩展名

protected virtual HashSet<string> AllowedExtensions { get; }

Property Value

HashSet<string>

QueueFileName

队列文件名

protected abstract string QueueFileName { get; }

Property Value

string

Methods

ClearQueueFile()

清空队列文件

protected void ClearQueueFile()

Dispose()

释放资源

public void Dispose()

Dispose(bool)

释放资源

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

是否手动释放

EnqueueFile(string, int, CancellationToken)

将文件加入上传队列

protected void EnqueueFile(string filePath, int retryCount = 0, CancellationToken cancellationToken = default)

Parameters

filePath string
retryCount int
cancellationToken CancellationToken

~BaseUploadQueue()

析构函数

protected ~BaseUploadQueue()

GetMaxFileSize(string)

获取最大文件大小

protected virtual long GetMaxFileSize(string extension)

Parameters

extension string

文件扩展名

Returns

long

最大文件大小(字节)

GetQueueFilePath()

获取队列文件路径

protected string GetQueueFilePath()

Returns

string

InitializeQueue()

初始化上传队列

public void InitializeQueue()

IsRetryableError(string)

判断错误是否可重试

protected bool IsRetryableError(string filePath)

Parameters

filePath string

Returns

bool

IsUploadEnabled()

检查上传是否启用

protected abstract bool IsUploadEnabled()

Returns

bool

IsValidFile(string)

验证文件是否有效

protected virtual bool IsValidFile(string filePath)

Parameters

filePath string

Returns

bool

ProcessUploadQueueAsync(CancellationToken)

处理上传队列,批量上传文件

protected Task ProcessUploadQueueAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

SaveQueueToFileAsync(CancellationToken)

保存队列到文件

protected Task SaveQueueToFileAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

UploadFileAsync(string, CancellationToken)

异步上传文件

public Task<bool> UploadFileAsync(string filePath, CancellationToken cancellationToken = default)

Parameters

filePath string
cancellationToken CancellationToken

Returns

Task<bool>

UploadFileInternalAsync(string, CancellationToken)

内部上传方法,执行实际上传操作

protected abstract Task<bool> UploadFileInternalAsync(string filePath, CancellationToken cancellationToken)

Parameters

filePath string
cancellationToken CancellationToken

Returns

Task<bool>