Skip to content

Commit

Permalink
Merge pull request #29 from trannamtrung1st/change-event-to-list
Browse files Browse the repository at this point in the history
Issues #28:
  • Loading branch information
trannamtrung1st authored Mar 19, 2022
2 parents ca6eb64 + a6641b2 commit adc5012
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ private void CustomizeResponse(ConnectorResult connectorResult, IVolume volume,
//_driver.SetupBackgroundThumbnailGenerator(_thumbnailGenerator, _pictureEditor, _videoEditor, cancellationToken: cancellationToken);

// Events
_driver.OnBeforeUpload += (file, destFile, formFile, isOverwrite, isChunking) =>
_driver.OnBeforeUpload.Add((file, destFile, formFile, isOverwrite, isChunking) =>
{
UpdatePulseStatus();
return Task.CompletedTask;
};
});

_driver.OnAfterUpload += (file, destFile, formFile, isOverwrite, isChunking) =>
_driver.OnAfterUpload.Add((file, destFile, formFile, isOverwrite, isChunking) =>
{
if (!isChunking)
{
Expand All @@ -179,16 +179,16 @@ private void CustomizeResponse(ConnectorResult connectorResult, IVolume volume,
}
return Task.CompletedTask;
};
});

_driver.OnAfterChunkMerged += (file, isOverwrite) =>
_driver.OnAfterChunkMerged.Add((file, isOverwrite) =>
{
Console.WriteLine($"Uploaded to: {file?.FullName}");
var status = CurrentUploadStatus;
status.UploadedFiles.Add(file.Name);
StartUploadDoneChecking();
return Task.CompletedTask;
};
});

// Quota management: This is set up per volume. Use VolumeId as key.
// The plugin support quota management on Volume (root) level only. It means that you can not set quota for directories.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ private async Task SetupConnectorAsync()
}

// Events
_driver.OnBeforeMove += (fileSystem, newDest, isOverwrite) =>
_driver.OnBeforeMove.Add((fileSystem, newDest, isOverwrite) =>
{
Console.WriteLine("Move: " + fileSystem.FullName);
Console.WriteLine("To: " + newDest);
return Task.CompletedTask;
};
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected virtual void InterceptPaste(IInvocation invocation, QuotaOptions quota
Func<string, Task<long>> dstCreateFunc = (_) => dstDirectory.GetPhysicalStorageUsageAsync(cancellationToken);
long toSize = 0, decreaseSize = 0, fromSize = 0;

driver.OnBeforeMove += async (fileSystem, newDest, isOverwrite) =>
driver.OnBeforeMove.Add(async (fileSystem, newDest, isOverwrite) =>
{
if (fileSystem is IFile file)
{
Expand Down Expand Up @@ -191,9 +191,9 @@ protected virtual void InterceptPaste(IInvocation invocation, QuotaOptions quota
proceeded = true;
}
};
});

driver.OnAfterMove += (fileSystem, newFileSystem, isOverwrite) =>
driver.OnAfterMove.Add((fileSystem, newFileSystem, isOverwrite) =>
{
if (dstStorageCache == null) return Task.CompletedTask;
Expand All @@ -208,7 +208,7 @@ protected virtual void InterceptPaste(IInvocation invocation, QuotaOptions quota
fromStorageCache = null;
return Task.CompletedTask;
};
});
}

try
Expand Down Expand Up @@ -260,7 +260,7 @@ protected virtual void InterceptCopy<T>(IInvocation invocation, IVolume dstVolum
Func<string, Task<long>> createFunc = (_) => dstDirectory.GetPhysicalStorageUsageAsync(cancellationToken);
long copySize = 0;

driver.OnBeforeCopy += async (fileSystem, destPath, isOverwrite) =>
driver.OnBeforeCopy.Add(async (fileSystem, destPath, isOverwrite) =>
{
if (fileSystem is IFile file)
{
Expand All @@ -279,16 +279,16 @@ protected virtual void InterceptCopy<T>(IInvocation invocation, IVolume dstVolum
proceeded = true;
}
};
});

driver.OnAfterCopy += (fileSystem, destPath, isOverwrite) =>
driver.OnAfterCopy.Add((fileSystem, destPath, isOverwrite) =>
{
if (storageCache == null) return Task.CompletedTask;
storageCache.Storage += copySize;
storageManager.Unlock(storageCache);
storageCache = null;
return Task.CompletedTask;
};
});
}

try
Expand Down Expand Up @@ -318,7 +318,7 @@ protected virtual void InterceptRm(IInvocation invocation, QuotaOptions quotaOpt

long? rmLength = null;

driver.OnBeforeRemove += async (IFileSystem fileSystem) =>
driver.OnBeforeRemove.Add(async (IFileSystem fileSystem) =>
{
if (fileSystem is IFile file)
{
Expand All @@ -329,9 +329,9 @@ protected virtual void InterceptRm(IInvocation invocation, QuotaOptions quotaOpt
rmLength = (await dir
.GetSizeAndCountAsync(false, _ => true, _ => true, cancellationToken: cancellationToken)).Size;
}
};
});

driver.OnAfterRemove += (IFileSystem fileSystem) =>
driver.OnAfterRemove.Add((IFileSystem fileSystem) =>
{
if (rmLength == 0) return Task.CompletedTask;
Expand All @@ -355,7 +355,7 @@ protected virtual void InterceptRm(IInvocation invocation, QuotaOptions quotaOpt
}
return Task.CompletedTask;
};
});
}

try
Expand Down Expand Up @@ -396,7 +396,7 @@ protected virtual void InterceptUpload(IInvocation invocation, QuotaOptions quot

long uploadLength = 0;

driver.OnBeforeUpload += async (file, destFile, formFile, isOverwrite, isChunking) =>
driver.OnBeforeUpload.Add(async (file, destFile, formFile, isOverwrite, isChunking) =>
{
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand Down Expand Up @@ -434,28 +434,28 @@ protected virtual void InterceptUpload(IInvocation invocation, QuotaOptions quot
throw new QuotaException(maximum.Value, storageCache.Storage, quotaOptions);
proceededDirs.Add(volumeDir);
};
});

driver.OnAfterUpload += (file, destFile, formFile, isOverwrite, isChunking) =>
driver.OnAfterUpload.Add((file, destFile, formFile, isOverwrite, isChunking) =>
{
if (storageCache == null && uploadLength == 0) return Task.CompletedTask;
storageCache.Storage += uploadLength;
uploadLength = 0;
storageManager.Unlock(storageCache);
storageCache = null;
return Task.CompletedTask;
};
});

long transferLength = 0;
long originalLength = 0;
long tempTransferedLength = 0;

driver.OnBeforeChunkMerged += async (file, isOverwrite) =>
driver.OnBeforeChunkMerged.Add(async (file, isOverwrite) =>
{
originalLength = isOverwrite ? await file.LengthAsync : 0;
};
});

driver.OnBeforeChunkTransfer += async (chunkFile, destFile, isOverwrite) =>
driver.OnBeforeChunkTransfer.Add(async (chunkFile, destFile, isOverwrite) =>
{
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand All @@ -472,9 +472,9 @@ protected virtual void InterceptUpload(IInvocation invocation, QuotaOptions quot
throw new QuotaException(maximum.Value, storageCache.Storage, quotaOptions);
proceededDirs.Add(volumeDir);
};
});

driver.OnAfterChunkTransfer += (chunkFile, destFile, isOverwrite) =>
driver.OnAfterChunkTransfer.Add((chunkFile, destFile, isOverwrite) =>
{
if (storageCache != null && tempTransferedLength > 0)
{
Expand All @@ -485,9 +485,9 @@ protected virtual void InterceptUpload(IInvocation invocation, QuotaOptions quot
storageManager.Unlock(storageCache);
storageCache = null;
return Task.CompletedTask;
};
});

driver.OnAfterChunkMerged += (file, isOverwrite) =>
driver.OnAfterChunkMerged.Add((file, isOverwrite) =>
{
if (storageCache == null)
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand All @@ -502,9 +502,9 @@ protected virtual void InterceptUpload(IInvocation invocation, QuotaOptions quot
storageCache = null;
return Task.CompletedTask;
};
});

driver.OnUploadError += (Exception exception) =>
driver.OnUploadError.Add((Exception exception) =>
{
storageManager.Unlock(storageCache);
storageCache = null;
Expand All @@ -513,20 +513,20 @@ protected virtual void InterceptUpload(IInvocation invocation, QuotaOptions quot
throw exception;
return Task.CompletedTask;
};
});

long rmLength = 0;

driver.OnBeforeRollbackChunk += async (fileSystem) =>
driver.OnBeforeRollbackChunk.Add(async (fileSystem) =>
{
if (fileSystem is IFile file)
{
rmLength = await file.LengthAsync;
proceededDirs.Add(volumeDir);
}
};
});

driver.OnAfterRollbackChunk += (fileSystem) =>
driver.OnAfterRollbackChunk.Add((fileSystem) =>
{
if (rmLength == 0 || fileSystem is IDirectory) return Task.CompletedTask;
Expand All @@ -536,7 +536,7 @@ protected virtual void InterceptUpload(IInvocation invocation, QuotaOptions quot
storageCache.Storage -= rmLength;
rmLength = 0;
return Task.CompletedTask;
};
});
}

try
Expand Down Expand Up @@ -587,7 +587,7 @@ protected virtual void InterceptWriteToTarget<TResp>(IInvocation invocation, Quo
long writeLength = 0;
long oldLength = 0;

driver.OnBeforeWriteData += async (data, file) =>
driver.OnBeforeWriteData.Add(async (data, file) =>
{
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand All @@ -599,18 +599,18 @@ protected virtual void InterceptWriteToTarget<TResp>(IInvocation invocation, Quo
throw new QuotaException(maximum.Value, storageCache.Storage, quotaOptions);
proceeded = true;
};
});

driver.OnAfterWriteData += async (data, file) =>
driver.OnAfterWriteData.Add(async (data, file) =>
{
if (storageCache == null) return;
await file.RefreshAsync(cancellationToken);
storageCache.Storage += await file.LengthAsync - oldLength;
storageManager.Unlock(storageCache);
storageCache = null;
};
});

driver.OnBeforeWriteStream += async (openStreamFunc, file) =>
driver.OnBeforeWriteStream.Add(async (openStreamFunc, file) =>
{
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand All @@ -631,18 +631,18 @@ protected virtual void InterceptWriteToTarget<TResp>(IInvocation invocation, Quo
throw new QuotaException(maximum.Value, storageCache.Storage, quotaOptions);
proceeded = true;
};
});

driver.OnAfterWriteStream += async (openStreamFunc, file) =>
driver.OnAfterWriteStream.Add(async (openStreamFunc, file) =>
{
if (storageCache == null) return;
await file.RefreshAsync(cancellationToken);
storageCache.Storage += await file.LengthAsync - oldLength;
storageManager.Unlock(storageCache);
storageCache = null;
};
});

driver.OnBeforeWriteContent += async (content, encoding, file) =>
driver.OnBeforeWriteContent.Add(async (content, encoding, file) =>
{
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand All @@ -654,16 +654,16 @@ protected virtual void InterceptWriteToTarget<TResp>(IInvocation invocation, Quo
throw new QuotaException(maximum.Value, storageCache.Storage, quotaOptions);
proceeded = true;
};
});

driver.OnAfterWriteContent += async (content, encoding, file) =>
driver.OnAfterWriteContent.Add(async (content, encoding, file) =>
{
if (storageCache == null) return;
await file.RefreshAsync(cancellationToken);
storageCache.Storage += await file.LengthAsync - oldLength;
storageManager.Unlock(storageCache);
storageCache = null;
};
});
}

try
Expand Down Expand Up @@ -701,7 +701,7 @@ protected virtual void InterceptArchive(IInvocation invocation, QuotaOptions quo

Func<string, Task<long>> createFunc = (_) => volumeDir.GetPhysicalStorageUsageAsync(cancellationToken);

driver.OnBeforeArchive += (file) =>
driver.OnBeforeArchive.Add((file) =>
{
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand All @@ -711,9 +711,9 @@ protected virtual void InterceptArchive(IInvocation invocation, QuotaOptions quo
proceeded = true;
return Task.CompletedTask;
};
});

driver.OnAfterArchive += async (file) =>
driver.OnAfterArchive.Add(async (file) =>
{
if (storageCache == null) return;
await file.RefreshAsync(cancellationToken);
Expand All @@ -734,7 +734,7 @@ protected virtual void InterceptArchive(IInvocation invocation, QuotaOptions quo
storageCache.Storage += archiveLength;
storageManager.Unlock(storageCache);
storageCache = null;
};
});
}

try
Expand Down Expand Up @@ -774,7 +774,7 @@ protected virtual void InterceptExtract(IInvocation invocation, QuotaOptions quo

long extractLength = 0;

driver.OnBeforeExtractFile += async (entry, destFile, isOverwrite) =>
driver.OnBeforeExtractFile.Add(async (entry, destFile, isOverwrite) =>
{
(storageCache, _) = storageManager.Lock(volume.RootDirectory, createFunc);
Expand All @@ -788,16 +788,16 @@ protected virtual void InterceptExtract(IInvocation invocation, QuotaOptions quo
throw new QuotaException(maximum.Value, storageCache.Storage, quotaOptions);
proceeded = true;
};
});

driver.OnAfterExtractFile += (entry, destFile, isOverwrite) =>
driver.OnAfterExtractFile.Add((entry, destFile, isOverwrite) =>
{
if (storageCache == null) return Task.CompletedTask;
storageCache.Storage += extractLength;
storageManager.Unlock(storageCache);
storageCache = null;
return Task.CompletedTask;
};
});
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/trannamtrung1st/elFinder.Net.Core</RepositoryUrl>
<RepositoryType>OSS</RepositoryType>
<PackageTags>elFinder, connector, file-manager, driver, plugins</PackageTags>
<Version>1.4.2</Version>
<Version>1.4.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit adc5012

Please sign in to comment.