Blob storage formatting

This commit is contained in:
Sipke Schoorstra 2021-04-15 19:28:35 +02:00
parent d6ed56ca07
commit 7fa0a3b8d7
7 changed files with 72 additions and 77 deletions

View file

@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props"/>
<Import Project="..\..\..\configureawait.props"/>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Description>
Elsa is a set of workflow libraries and tools that enable lean and mean workflowing capabilities in any .NET Core application.
This package provides activities to send and receive messages using Azure Service Bus.
</Description>
</Description>
<PackageTags>elsa, workflows</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.1.2" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.1.2"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\core\Elsa.Core\Elsa.Core.csproj" />
<ProjectReference Include="..\..\core\Elsa.Core\Elsa.Core.csproj"/>
</ItemGroup>
</Project>

View file

@ -1,10 +1,8 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System;
using System.Threading.Tasks;
using Elsa.ActivityResults;
using Elsa.Attributes;
using Elsa.Expressions;
using Elsa.Services;
using Elsa.Services.Models;
using Storage.Net.Blobs;
@ -14,27 +12,26 @@ namespace Elsa.Activities.BlobStorage
{
[Action(
Category = "BlobStorage",
Description = "Check if a blob exists on the storage engine.",
Outcomes = new[] { OutcomeNames.True, OutcomeNames.False }
)]
public class BlobExists : Activity
{
public BlobExists(IBlobStorage storage)
{
_storage = storage;
}
private readonly IBlobStorage _storage;
public BlobExists(IBlobStorage storage) => _storage = storage;
[ActivityProperty(Hint = "The Id of the blob")]
public string BlobId { get; set; }
[ActivityProperty(Hint = "The ID of the blob.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
public string BlobId { get; set; } = default!;
protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
{
if (string.IsNullOrWhiteSpace(BlobId))
throw new System.Exception($"BlobId must have a value");
throw new Exception($"{nameof(BlobId)} must have a value");
if (await _storage.ExistsAsync(BlobId))
return Outcome(OutcomeNames.True);
else
return Outcome(OutcomeNames.False);
return Outcome(OutcomeNames.False);
}
}
}

View file

@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Elsa.ActivityResults;
@ -15,27 +13,27 @@ using Storage.Net.Blobs;
namespace Elsa.Activities.BlobStorage
{
[Action(
Category = "BlobStorage",
Category = "BlobStorage",
Description = "Delete a blob from the storage engine.",
Outcomes = new[] { OutcomeNames.Done }
)]
public class DeleteBlob : Activity
{
public DeleteBlob(IBlobStorage storage)
{
_storage = storage;
}
private readonly IBlobStorage _storage;
public DeleteBlob(IBlobStorage storage) => _storage = storage;
[ActivityProperty(Hint = "The Ids of the blobs",
UIHint = ActivityPropertyUIHints.MultiText,
[ActivityProperty(
Hint = "The IDs of the blobs.",
UIHint = ActivityPropertyUIHints.MultiText,
DefaultSyntax = SyntaxNames.Json,
SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript, SyntaxNames.Liquid })]
SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript, SyntaxNames.Liquid }
)]
public IList<string> BlobIds { get; set; } = new List<string>();
protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
{
if (BlobIds==default || !BlobIds.Any())
throw new System.Exception($"BlobID or BlobIds must have a value");
if (BlobIds == default || !BlobIds.Any())
throw new System.Exception($"BlobID or BlobIds must have a value");
await _storage.DeleteAsync(BlobIds, context.CancellationToken);
return Done();
}

View file

@ -1,6 +1,4 @@
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Elsa.ActivityResults;
using Elsa.Attributes;
@ -13,34 +11,30 @@ namespace Elsa.Activities.BlobStorage
{
[Action(
Category = "BlobStorage",
Description = "Reads a blob from the storage engine",
Description = "Reads a blob from the storage engine.",
Outcomes = new[] { OutcomeNames.Done }
)]
public class ReadBlob : Activity
{
public ReadBlob(IBlobStorage storage)
{
_storage = storage;
}
private readonly IBlobStorage _storage;
public ReadBlob(IBlobStorage storage) => _storage = storage;
[ActivityProperty(Hint = "The Id assigned to the blob.")]
[Required]
public string BlobId { get; set; }
public string BlobId { get; set; } = default!;
[ActivityProperty(Hint = "If set, the output of this activity is written into the specified file, alternatively the outcome contains the bytes of the blob")]
public string FilePath { get; set; }
[ActivityProperty(Hint = "If set, the output of this activity is written to the specified file. Otherwise, the bytes of the blob will be set as the activity output.")]
public string? DestinationFilePath { get; set; }
protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
{
if (string.IsNullOrWhiteSpace(BlobId))
throw new System.Exception($"BlobId must have a value");
if (!string.IsNullOrWhiteSpace(FilePath))
await _storage.ReadToFileAsync(BlobId, FilePath, context.CancellationToken);
else
{
Done(await _storage.ReadBytesAsync(BlobId, context.CancellationToken));
}
throw new System.Exception($"{nameof(BlobId)} must have a value");
if (string.IsNullOrWhiteSpace(DestinationFilePath))
return Done(await _storage.ReadBytesAsync(BlobId, context.CancellationToken));
await _storage.ReadToFileAsync(BlobId, DestinationFilePath, context.CancellationToken);
return Done();
}
}

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using Elsa.ActivityResults;
using Elsa.Attributes;
using Elsa.Expressions;
using Elsa.Services;
using Elsa.Services.Models;
using Storage.Net.Blobs;
@ -13,7 +14,7 @@ namespace Elsa.Activities.BlobStorage
{
[Action(
Category = "BlobStorage",
Description = "Write a blob to the storage engine",
Description = "Write a blob to the storage engine.",
Outcomes = new[] { OutcomeNames.Done }
)]
public class WriteBlob : Activity
@ -22,26 +23,24 @@ namespace Elsa.Activities.BlobStorage
{
_storage = storage;
}
private readonly IBlobStorage _storage;
[ActivityProperty(Hint = "The ID to be assigned to the blob. It's needed to retrieve the blob")]
[ActivityProperty(Hint = "The ID to be assigned to the blob.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
[Required]
public string BlobID { get; set; }
public string BlobId { get; set; } = default!;
[ActivityProperty(Hint = "The bytes")]
public byte[] Bytes { get; set; }
[ActivityProperty(Hint = "The file path")]
public string FilePath { get; set; }
[ActivityProperty(Hint = "The bytes to write.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript }, DefaultSyntax = SyntaxNames.JavaScript)]
public byte[]? Bytes { get; set; }
protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
{
if (string.IsNullOrWhiteSpace(BlobID))
throw new System.Exception($"BlobID must have a value");
if (!string.IsNullOrWhiteSpace(FilePath))
await _storage.WriteFileAsync(BlobID, FilePath, context.CancellationToken);
if(Bytes!=default && Bytes.Any())
await _storage.WriteAsync(BlobID, new MemoryStream(Bytes), default, context.CancellationToken);
if (string.IsNullOrWhiteSpace(BlobId))
throw new System.Exception($"{nameof(BlobId)} must have a value");
if (Bytes != default && Bytes.Any())
await _storage.WriteAsync(BlobId, new MemoryStream(Bytes), default, context.CancellationToken);
return Done();
}
}

View file

@ -1,16 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>Luca Pisano</Authors>
</PropertyGroup>
<Import Project="..\..\..\common.props"/>
<Import Project="..\..\..\configureawait.props"/>
<ItemGroup>
<PackageReference Include="Storage.Net" Version="9.2.7" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>Luca Pisano, Elsa Contributors</Authors>
<Description>
Elsa is a set of workflow libraries and tools that enable lean and mean workflowing capabilities in any .NET Core application.
This package provides activities to read and write files to blob storage using Storage.Net that provides a generic interface for popular cloud storage providers like Amazon S3, Azure Service Bus, Azure Event Hub, Azure Storage, Azure Data Lake Store thus abstracting Blob and Messaging services.
</Description>
<PackageTags>elsa, workflows, blob storage</PackageTags>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\core\Elsa.Core\Elsa.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Storage.Net" Version="9.2.7"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\core\Elsa.Core\Elsa.Core.csproj"/>
</ItemGroup>
</Project>

View file

@ -1,6 +1,4 @@
using System;
using System.IO;
using System.Linq;
using Elsa;
using Elsa.Activities.BlobStorage;
using Storage.Net.Blobs;
@ -10,10 +8,11 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static ElsaOptions AddBlobStorageActivities(this ElsaOptions options, Func<IServiceProvider, IBlobStorage> implementation=default)
public static ElsaOptionsBuilder AddBlobStorageActivities(this ElsaOptionsBuilder options, Func<IServiceProvider, IBlobStorage>? configureBlobStorage = default)
{
if (implementation != default)
options.UseStorage(implementation);
if (configureBlobStorage != default)
options.UseStorage(configureBlobStorage);
options
.AddActivity<WriteBlob>()
.AddActivity<ReadBlob>()