Code cleanup (#413)
This commit is contained in:
parent
65c5e875b5
commit
cfcbc3d762
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -22,7 +22,7 @@ namespace Elsa.Activities.ControlFlow.Activities
|
|||
{
|
||||
public Join()
|
||||
{
|
||||
InboundTransitions = new List<string>().AsReadOnly();
|
||||
InboundTransitions = new List<string>();
|
||||
}
|
||||
|
||||
public enum JoinMode
|
||||
|
|
@ -50,7 +50,7 @@ namespace Elsa.Activities.ControlFlow.Activities
|
|||
|
||||
protected override ActivityExecutionResult OnExecute(WorkflowExecutionContext workflowContext)
|
||||
{
|
||||
var recordedInboundTransitions = InboundTransitions ?? new List<string>();
|
||||
var recordedInboundTransitions = InboundTransitions ?? Enumerable.Empty<string>();
|
||||
var workflow = workflowContext.Workflow;
|
||||
var inboundConnections = workflow.GetInboundConnections(Id);
|
||||
var done = false;
|
||||
|
|
|
|||
|
|
@ -22,12 +22,11 @@ namespace Elsa.Activities.ControlFlow.Activities
|
|||
public class Switch : Activity
|
||||
{
|
||||
private readonly IWorkflowExpressionEvaluator expressionEvaluator;
|
||||
|
||||
|
||||
|
||||
public Switch(IWorkflowExpressionEvaluator expressionEvaluator)
|
||||
{
|
||||
this.expressionEvaluator = expressionEvaluator;
|
||||
Cases = new List<string>()
|
||||
Cases = new List<string>
|
||||
{
|
||||
"default"
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Expressions;
|
||||
|
|
@ -39,13 +39,12 @@ namespace Elsa.Activities.ControlFlow.Activities
|
|||
{
|
||||
var loop = await expressionEvaluator.EvaluateAsync(ConditionExpression, context, cancellationToken);
|
||||
|
||||
if(HasStarted)
|
||||
if (HasStarted)
|
||||
context.EndScope();
|
||||
|
||||
if (loop)
|
||||
{
|
||||
if (!HasStarted)
|
||||
HasStarted = true;
|
||||
HasStarted = true;
|
||||
|
||||
context.BeginScope();
|
||||
return Outcome(OutcomeNames.Iterate);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using Elsa.Activities.Dropbox.Activities;
|
||||
using Elsa.Activities.Dropbox.Handlers;
|
||||
using Elsa.Activities.Dropbox.Options;
|
||||
using Elsa.Activities.Dropbox.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -20,7 +19,6 @@ namespace Elsa.Activities.Dropbox.Extensions
|
|||
options?.Invoke(optionsBuilder);
|
||||
|
||||
services
|
||||
.AddTransient<DropboxApiHandler>()
|
||||
.AddHttpClient<IFilesApi, FilesApi>()
|
||||
.ConfigureHttpClient(ConfigureHttpClient);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elsa.Activities.Dropbox.Handlers
|
||||
{
|
||||
public class DropboxApiHandler : DelegatingHandler
|
||||
{
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
//request.Content = new ByteArrayContent(request.Content.);
|
||||
var response = await base.SendAsync(request, cancellationToken);
|
||||
var error = await response.Content.ReadAsStringAsync();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities.Email.Options;
|
||||
using Elsa.Activities.Email.Services;
|
||||
|
|
@ -59,13 +59,13 @@ namespace Elsa.Activities.Email.Activities
|
|||
|
||||
protected override async Task<ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext workflowContext, CancellationToken cancellationToken)
|
||||
{
|
||||
var from = (await expressionEvaluator.EvaluateAsync(From, workflowContext, cancellationToken)) ?? options.Value.DefaultSender;
|
||||
var from = await expressionEvaluator.EvaluateAsync(From, workflowContext, cancellationToken) ?? options.Value.DefaultSender;
|
||||
var to = await expressionEvaluator.EvaluateAsync(To, workflowContext, cancellationToken);
|
||||
var subject = await expressionEvaluator.EvaluateAsync(Subject, workflowContext, cancellationToken);
|
||||
var body = await expressionEvaluator.EvaluateAsync(Body, workflowContext, cancellationToken);
|
||||
var message = new MimeMessage();
|
||||
|
||||
message.From.Add(new MailboxAddress(@from));
|
||||
message.From.Add(new MailboxAddress(from));
|
||||
message.Subject = subject;
|
||||
|
||||
message.Body = new TextPart(TextFormat.Html)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ namespace Elsa.Activities.MassTransit.Activities
|
|||
set => SetState(value);
|
||||
}
|
||||
|
||||
|
||||
protected override bool OnCanExecute(WorkflowExecutionContext context)
|
||||
{
|
||||
return TokenId != null && options.SchedulerAddress != null;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@ namespace Elsa.Activities.MassTransit.Activities
|
|||
/// the conversation and correlation id.
|
||||
/// </remarks>
|
||||
protected IPublishEndpoint PublishEndpoint =>
|
||||
consumeContext != null
|
||||
? (IPublishEndpoint)consumeContext
|
||||
: (IPublishEndpoint)bus;
|
||||
consumeContext ?? (IPublishEndpoint)bus;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the send endpoint provider to use.
|
||||
|
|
@ -35,9 +33,7 @@ namespace Elsa.Activities.MassTransit.Activities
|
|||
/// the conversation and correlation id.
|
||||
/// </remarks>
|
||||
protected ISendEndpointProvider SendEndpointProvider =>
|
||||
consumeContext != null
|
||||
? (ISendEndpointProvider)consumeContext
|
||||
: (ISendEndpointProvider)bus;
|
||||
consumeContext ?? (ISendEndpointProvider)bus;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Results;
|
||||
|
|
@ -44,13 +42,12 @@ namespace Elsa.Activities.MassTransit.Activities
|
|||
return Halt(true);
|
||||
}
|
||||
|
||||
protected override Task<ActivityExecutionResult> OnResumeAsync(WorkflowExecutionContext context,
|
||||
CancellationToken cancellationToken)
|
||||
protected override ActivityExecutionResult OnResume(WorkflowExecutionContext context)
|
||||
{
|
||||
var message = context.Workflow.Input.GetVariable(Constants.MessageInputKey);
|
||||
context.SetLastResult(message);
|
||||
|
||||
return Task.FromResult(Done());
|
||||
return Done();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
|
@ -50,7 +51,7 @@ namespace Elsa.Activities.Reflection.Activities
|
|||
if (type == null)
|
||||
return Fault($"Type {TypeName} not found.");
|
||||
|
||||
var inputValues = await context.EvaluateAsync(Arguments, cancellationToken) ?? new object[0];
|
||||
var inputValues = await context.EvaluateAsync(Arguments, cancellationToken) ?? Array.Empty<object>();
|
||||
|
||||
var method = type
|
||||
.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Expressions;
|
||||
|
|
@ -76,8 +76,7 @@ namespace Elsa.Activities.Timers.Activities
|
|||
var schedule = CrontabSchedule.Parse(cronExpression);
|
||||
var now = clock.GetCurrentInstant();
|
||||
|
||||
if (StartTime == null)
|
||||
StartTime = now;
|
||||
StartTime ??= now;
|
||||
|
||||
var nextOccurrence = schedule.GetNextOccurrence(StartTime.Value.ToDateTimeUtc());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Attributes;
|
||||
|
|
@ -64,8 +64,7 @@ namespace Elsa.Activities.Timers.Activities
|
|||
{
|
||||
var now = clock.GetCurrentInstant();
|
||||
|
||||
if (StartTime == null)
|
||||
StartTime = now;
|
||||
StartTime ??= now;
|
||||
|
||||
var timeSpan = await expressionEvaluator.EvaluateAsync(TimeoutExpression, context, cancellationToken);
|
||||
var expiresAt = StartTime.Value.ToDateTimeUtc() + timeSpan;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Elsa.Attributes;
|
||||
using Elsa.Design;
|
||||
|
|
@ -23,7 +23,7 @@ namespace Elsa.Activities.UserTask.Activities
|
|||
)]
|
||||
public string[] Actions
|
||||
{
|
||||
get => GetState(() => new string[0]);
|
||||
get => GetState(() => Array.Empty<string>());
|
||||
set => SetState(value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Elsa.Persistence.Memory
|
|||
|
||||
public Task<WorkflowInstance> GetByIdAsync(string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var instance = workflowInstances.ContainsKey(id) ? workflowInstances[id] : default;
|
||||
workflowInstances.TryGetValue(id, out var instance);
|
||||
return Task.FromResult(instance);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using Elsa.Metadata;
|
||||
using Elsa.WorkflowDesigner.Models;
|
||||
using Elsa.WorkflowDesigner.ViewModels;
|
||||
|
|
@ -17,7 +18,7 @@ namespace Elsa.WorkflowDesigner.ViewComponents
|
|||
{
|
||||
var model = new WorkflowDesignerViewComponentModel(
|
||||
id,
|
||||
Serialize(activityDefinitions ?? new ActivityDescriptor[0]),
|
||||
Serialize(activityDefinitions ?? Array.Empty<ActivityDescriptor>()),
|
||||
Serialize(workflow ?? new WorkflowModel()),
|
||||
isReadonly.GetValueOrDefault()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Elsa.Scripting.JavaScript.Converters
|
||||
|
|
@ -8,13 +8,9 @@ namespace Elsa.Scripting.JavaScript.Converters
|
|||
/// </summary>
|
||||
public class TruncatingNumberJsonConverter : JsonConverter
|
||||
{
|
||||
public TruncatingNumberJsonConverter()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CanRead => false;
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
|
||||
public override bool CanConvert(Type objectType) => (objectType == typeof(decimal) || objectType == typeof(float) || objectType == typeof(double));
|
||||
public override bool CanConvert(Type objectType) => objectType == typeof(decimal) || objectType == typeof(float) || objectType == typeof(double);
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => writer.WriteRawValue(IsWholeValue(value) ? JsonConvert.ToString(Convert.ToInt64(value)) : JsonConvert.ToString(value));
|
||||
|
||||
private static bool IsWholeValue(object value)
|
||||
|
|
@ -27,7 +23,7 @@ namespace Elsa.Scripting.JavaScript.Converters
|
|||
|
||||
if (value is float || value is double)
|
||||
{
|
||||
var doubleValue = (double) value;
|
||||
var doubleValue = Convert.ToDouble(value);
|
||||
return doubleValue == Math.Truncate(doubleValue);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
|
@ -41,7 +41,7 @@ namespace Elsa.Scripting.Liquid.Handlers
|
|||
}
|
||||
|
||||
private Task<FluidValue> ToFluidValue(IDictionary<string, Variable> dictionary, string key)
|
||||
=> Task.FromResult(!dictionary.ContainsKey(key) ? default : FluidValue.Create(dictionary[key].Value));
|
||||
=> Task.FromResult(!dictionary.TryGetValue(key, out var variable) ? default : FluidValue.Create(variable.Value));
|
||||
|
||||
private async Task<object> GetActivityOutput(LiquidObjectAccessor<IActivity> accessor, string activityName, string outputKey)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Scripting.Liquid.Extensions;
|
||||
|
|
@ -26,16 +26,16 @@ namespace Elsa.Scripting.Liquid.Services
|
|||
|
||||
public async Task<object> EvaluateAsync(string expression, Type type, WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken)
|
||||
{
|
||||
var templateContext = await CreateTemplateContextAsync(workflowExecutionContext);
|
||||
var templateContext = await CreateTemplateContextAsync(workflowExecutionContext, cancellationToken);
|
||||
var result = await liquidTemplateManager.RenderAsync(expression, templateContext);
|
||||
return string.IsNullOrWhiteSpace(result) ? default : type != null ? Convert.ChangeType(result, type) : result;
|
||||
}
|
||||
|
||||
private async Task<TemplateContext> CreateTemplateContextAsync(WorkflowExecutionContext workflowContext)
|
||||
private async Task<TemplateContext> CreateTemplateContextAsync(WorkflowExecutionContext workflowContext, CancellationToken cancellationToken)
|
||||
{
|
||||
var context = new TemplateContext();
|
||||
context.SetValue("WorkflowExecutionContext", workflowContext);
|
||||
await mediator.Publish(new EvaluatingLiquidExpression(context, workflowContext));
|
||||
await mediator.Publish(new EvaluatingLiquidExpression(context, workflowContext), cancellationToken);
|
||||
context.Model = workflowContext;
|
||||
return context;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue