mirror of https://github.com/Squidex/squidex.git
Browse Source
* Refactor domain objects and add deleted flag to asset content. * Fix command flow. * Fix archive.pull/1016/head
committed by
GitHub
36 changed files with 646 additions and 595 deletions
@ -0,0 +1,16 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Infrastructure.Commands; |
|||
|
|||
public enum DomainObjectState |
|||
{ |
|||
Undefined, |
|||
Empty, |
|||
Created, |
|||
Deleted |
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Assets; |
|||
|
|||
namespace TestSuite.Utils; |
|||
|
|||
public sealed class PauseStream : DelegateStream |
|||
{ |
|||
private readonly int maxLength; |
|||
private long totalRead; |
|||
private long totalRemaining; |
|||
private long seekStart; |
|||
|
|||
public override long Length |
|||
{ |
|||
get => Math.Min(maxLength, totalRemaining); |
|||
} |
|||
|
|||
public override long Position |
|||
{ |
|||
get => base.Position - seekStart; |
|||
set => throw new NotSupportedException(); |
|||
} |
|||
|
|||
public PauseStream(Stream innerStream, double pauseAfter) |
|||
: base(innerStream) |
|||
{ |
|||
maxLength = (int)Math.Floor(innerStream.Length * pauseAfter) + 1; |
|||
|
|||
totalRemaining = innerStream.Length; |
|||
} |
|||
|
|||
public override long Seek(long offset, SeekOrigin origin) |
|||
{ |
|||
var position = seekStart = base.Seek(offset, origin); |
|||
|
|||
totalRemaining = base.Length - position; |
|||
|
|||
return position; |
|||
} |
|||
|
|||
public void Reset() |
|||
{ |
|||
totalRead = 0; |
|||
} |
|||
|
|||
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var remaining = Length - totalRead; |
|||
|
|||
if (remaining <= 0) |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
if (remaining < buffer.Length) |
|||
{ |
|||
var remainingBytes = (int)remaining; |
|||
|
|||
buffer = buffer[..remainingBytes]; |
|||
} |
|||
|
|||
var bytesRead = await base.ReadAsync(buffer, cancellationToken); |
|||
|
|||
totalRead += bytesRead; |
|||
|
|||
return bytesRead; |
|||
} |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.ClientLibrary; |
|||
|
|||
namespace TestSuite.Utils; |
|||
|
|||
public sealed class ProgressHandler : IAssetProgressHandler |
|||
{ |
|||
public string FileId { get; private set; } = Guid.NewGuid().ToString(); |
|||
|
|||
public List<int> Progress { get; } = new List<int>(); |
|||
|
|||
public List<int> Uploads { get; } = new List<int>(); |
|||
|
|||
public Exception Exception { get; private set; } |
|||
|
|||
public AssetDto Asset { get; private set; } |
|||
|
|||
public AssetUploadOptions AsOptions(string id = null) |
|||
{ |
|||
var options = default(AssetUploadOptions); |
|||
options.ProgressHandler = this; |
|||
options.FileId = FileId; |
|||
options.Id = id; |
|||
|
|||
return options; |
|||
} |
|||
|
|||
public void Uploaded() |
|||
{ |
|||
Uploads.Add(Progress.LastOrDefault()); |
|||
} |
|||
|
|||
public Task OnCompletedAsync(AssetUploadCompletedEvent @event, |
|||
CancellationToken ct) |
|||
{ |
|||
Asset = @event.Asset; |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task OnCreatedAsync(AssetUploadCreatedEvent @event, |
|||
CancellationToken ct) |
|||
{ |
|||
FileId = @event.FileId; |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task OnProgressAsync(AssetUploadProgressEvent @event, |
|||
CancellationToken ct) |
|||
{ |
|||
Progress.Add(@event.Progress); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task OnFailedAsync(AssetUploadExceptionEvent @event, |
|||
CancellationToken ct) |
|||
{ |
|||
Exception = @event.Exception; |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue