Resolve warnings

This commit is contained in:
Sipke Schoorstra 2021-06-19 11:51:06 +02:00
parent 6050c99c23
commit 67c230a2af
13 changed files with 34 additions and 27 deletions

View file

@ -322,6 +322,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elsa.Samples.FaultyWorkflow
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Activities.Conductor", "src\activities\Elsa.Activities.Conductor\Elsa.Activities.Conductor.csproj", "{4D4022DD-244B-47EE-95FA-7071EC687B24}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "aspnetcore", "aspnetcore", "{39DE1EE2-DF4F-44EB-9F5A-551BEADD6673}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -876,6 +878,8 @@ Global
{6A03B177-09E0-4421-9704-945E6248AB69} = {D86B94DC-A53C-4A67-A820-828DD359C49B}
{84751112-C2B7-41D4-98F5-D87D7C2E1DAE} = {22E75696-6FE9-436A-9097-EE21C603F818}
{4D4022DD-244B-47EE-95FA-7071EC687B24} = {B43B546E-23F3-46E8-ACB7-D04F05CDA180}
{39DE1EE2-DF4F-44EB-9F5A-551BEADD6673} = {4673732F-2853-47BD-91B8-C95C229D2C89}
{F1EF5639-021A-4D22-9D4A-73D57C88EBFA} = {39DE1EE2-DF4F-44EB-9F5A-551BEADD6673}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B0975FD-7050-48B0-88C5-48C33378E158}

View file

@ -12,14 +12,14 @@ namespace Elsa
{
public static T? GetState<T>(this IDictionary<string, object?>? state, string key) => state.GetState<T>(key, () => default!);
public static T? GetState<T>(this IDictionary<string, object?>? state, string key, Func<T> defaultValue)
public static T GetState<T>(this IDictionary<string, object?>? state, string key, Func<T> defaultValue)
{
var item = state?.ContainsKey(key) == true ? state![key] : default;
if (item == null)
return defaultValue();
return item.ConvertTo<T>();
return item.ConvertTo<T>()!;
}
public static object? GetState(this IDictionary<string, object?>? state, string key, Type targetType)

View file

@ -68,7 +68,7 @@ namespace Elsa.Services.Models
return data.GetState<T>(propertyName);
}
public T? GetState<T>(string propertyName, Func<T> defaultValue)
public T GetState<T>(string propertyName, Func<T> defaultValue)
{
var data = GetData();
return data.GetState(propertyName, defaultValue);

View file

@ -51,7 +51,7 @@ namespace Elsa.Services
protected virtual RegisterTaskResult RegisterTask(Func<WorkflowExecutionContext, CancellationToken, ValueTask> task) => new(task);
protected virtual T? GetState<T>([CallerMemberName] string name = null!) => Data.GetState<T>(name);
protected virtual T? GetState<T>(Func<T> defaultValue, [CallerMemberName] string name = null!) => Data.GetState(name, defaultValue);
protected virtual T GetState<T>(Func<T> defaultValue, [CallerMemberName] string name = null!) => Data.GetState(name, defaultValue);
protected virtual void SetState(object? value, [CallerMemberName] string name = null!) => Data.SetState(name, value);
}
}

View file

@ -58,7 +58,7 @@ namespace Elsa.Activities.ControlFlow
if (notification.EvictedScope.Type != nameof(If))
return Task.CompletedTask;
var data = notification.WorkflowExecutionContext.WorkflowInstance.ActivityData.GetItem(notification.EvictedScope.Id, () => new Dictionary<string, object>());
var data = notification.WorkflowExecutionContext.WorkflowInstance.ActivityData.GetItem(notification.EvictedScope.Id, () => new Dictionary<string, object?>());
data.SetState(nameof(EnteredScope), false);
return Task.CompletedTask;

View file

@ -159,7 +159,7 @@ namespace Elsa.Activities.ControlFlow
var inboundConnections = inboundTransitionsQuery.ToList();
var joinBlueprint = inboundConnections.FirstOrDefault()?.Target.Activity;
var joinActivityData = joinBlueprint != null ? workflowExecutionContext.WorkflowInstance.ActivityData.GetItem(joinBlueprint.Id, () => new Dictionary<string, object>()) : default;
var joinActivityData = joinBlueprint != null ? workflowExecutionContext.WorkflowInstance.ActivityData.GetItem(joinBlueprint.Id, () => new Dictionary<string, object?>()) : default;
if (joinActivityData == null)
return;

View file

@ -66,7 +66,7 @@ namespace Elsa.Activities.ControlFlow
if (notification.EvictedScope.Type != nameof(Switch))
return Task.CompletedTask;
var data = notification.WorkflowExecutionContext.WorkflowInstance.ActivityData.GetItem(notification.EvictedScope.Id, () => new Dictionary<string, object>());
var data = notification.WorkflowExecutionContext.WorkflowInstance.ActivityData.GetItem(notification.EvictedScope.Id, () => new Dictionary<string, object?>());
data.SetState(nameof(EnteredScope), false);
data.SetState("Unwinding", false);

View file

@ -38,7 +38,7 @@ namespace Elsa.Providers.WorkflowStorage
return new ValueTask();
}
private IDictionary<string, object> GetData(WorkflowStorageContext context) => context.WorkflowInstance.ActivityData.GetItem(context.ActivityId, () => new Dictionary<string, object>());
private IDictionary<string, object?> GetData(WorkflowStorageContext context) => context.WorkflowInstance.ActivityData.GetItem(context.ActivityId, () => new Dictionary<string, object?>());
private void SetState(WorkflowStorageContext context, string propertyName, object? value) => GetData(context)!.SetState(propertyName, value);
public object? GetState(WorkflowStorageContext context, string propertyName) => GetData(context)!.GetState(propertyName);
}

View file

@ -50,8 +50,8 @@ namespace Elsa.Scripting.JavaScript.Handlers
engine.SetValue("getWorkflowDefinitionIdByTag", (Func<string, string?>) (tag => GetWorkflowDefinitionIdByTag(activityExecutionContext, tag)));
engine.SetValue("getActivity", (Func<string, object?>) (idOrName => GetActivityModel(activityExecutionContext, idOrName)));
// Using .Result because Jint doesn't support Task-based functions yet.
engine.SetValue("getActivityProperty", (Func<string, string?, object?>) ((activityId, propertyName) => GetActivityPropertyAsync(activityId, propertyName, activityExecutionContext).Result));
// Using .Result because Jint doesn't support Task-based functions.
engine.SetValue("getActivityProperty", (Func<string, string, object?>) ((activityId, propertyName) => GetActivityPropertyAsync(activityId, propertyName, activityExecutionContext).Result));
// Global variables.
engine.SetValue("activityExecutionContext", activityExecutionContext);
@ -127,7 +127,7 @@ namespace Elsa.Scripting.JavaScript.Handlers
foreach (var activity in workflowBlueprint.Activities.Where(x => !string.IsNullOrWhiteSpace(x.Name)))
{
var state = new Dictionary<string, object>(activityExecutionContext.GetActivityData(activity.Id));
var state = new Dictionary<string, object?>(activityExecutionContext.GetActivityData(activity.Id));
engine.SetValue(activity.Name, state);
}
}

View file

@ -9,15 +9,15 @@ namespace Elsa.Scripting.JavaScript.Services
{
public class ExpandoObjectToDictionaryWhenNoDesiredTypeResultConverter : IConvertsJintEvaluationResult
{
private readonly IConvertsJintEvaluationResult wrapped;
private readonly IConvertsEnumerableToObject enumerableConverter;
private readonly IConvertsJintEvaluationResult _wrapped;
private readonly IConvertsEnumerableToObject _enumerableConverter;
public object? ConvertToDesiredType(object? evaluationResult, Type desiredType)
{
if(evaluationResult is ExpandoObject expando && desiredType == typeof(object))
return RecursivelyPrepareExpandoObjectForReturn(expando);
return wrapped.ConvertToDesiredType(evaluationResult, desiredType);
return _wrapped.ConvertToDesiredType(evaluationResult, desiredType);
}
private object? RecursivelyPrepareExpandoObjectForReturn(ExpandoObject obj)
@ -35,7 +35,7 @@ namespace Elsa.Scripting.JavaScript.Services
let val = (IEnumerable) kvp.Value
let replacementValue = (val is ExpandoObject expando)
? RecursivelyPrepareExpandoObjectForReturn(expando)
: enumerableConverter.ConvertEnumerable(val)
: _enumerableConverter.ConvertEnumerable(val)
select new { Key = kvp.Key, Value = replacementValue })
.ToDictionary(k => k.Key, v => v.Value);
@ -48,8 +48,8 @@ namespace Elsa.Scripting.JavaScript.Services
public ExpandoObjectToDictionaryWhenNoDesiredTypeResultConverter(IConvertsEnumerableToObject enumerableConverter, IConvertsJintEvaluationResult wrapped)
{
this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
this.enumerableConverter = enumerableConverter ?? throw new ArgumentNullException(nameof(enumerableConverter));
this._wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
this._enumerableConverter = enumerableConverter ?? throw new ArgumentNullException(nameof(enumerableConverter));
}
}
}

View file

@ -4,17 +4,17 @@ namespace Elsa.Scripting.JavaScript.Services
{
public class NullResultConverter : IConvertsJintEvaluationResult
{
private readonly IConvertsJintEvaluationResult wrapped;
private readonly IConvertsJintEvaluationResult _wrapped;
public object? ConvertToDesiredType(object? evaluationResult, Type desiredType)
{
if(evaluationResult is null) return null;
return wrapped.ConvertToDesiredType(evaluationResult, desiredType);
return _wrapped.ConvertToDesiredType(evaluationResult, desiredType);
}
public NullResultConverter(IConvertsJintEvaluationResult wrapped)
{
this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
this._wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
}
}
}

View file

@ -4,22 +4,25 @@ namespace Elsa.Scripting.JavaScript.Services
{
public class PlainObjectResultConverter : IConvertsJintEvaluationResult
{
private readonly IConvertsJintEvaluationResult wrapped;
private readonly IConvertsJintEvaluationResult _wrapped;
public object? ConvertToDesiredType(object? evaluationResult, Type desiredType)
{
if (evaluationResult == null)
return null;
if(desiredType == typeof(object))
return evaluationResult;
if (evaluationResult.GetType() == desiredType || desiredType.IsAssignableFrom(evaluationResult.GetType()))
if (evaluationResult.GetType() == desiredType || desiredType.IsInstanceOfType(evaluationResult))
return evaluationResult;
return wrapped.ConvertToDesiredType(evaluationResult, desiredType);
return _wrapped.ConvertToDesiredType(evaluationResult, desiredType);
}
public PlainObjectResultConverter(IConvertsJintEvaluationResult wrapped)
{
this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
this._wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
}
}
}

View file

@ -5,7 +5,7 @@ namespace Elsa.Scripting.JavaScript.Services
{
public class TypeConverterResultConverter : IConvertsJintEvaluationResult
{
private readonly IConvertsJintEvaluationResult wrapped;
private readonly IConvertsJintEvaluationResult _wrapped;
public object? ConvertToDesiredType(object? evaluationResult, Type desiredType)
{
@ -22,12 +22,12 @@ namespace Elsa.Scripting.JavaScript.Services
if (targetConverter.CanConvertFrom(evaluationResult!.GetType()))
return targetConverter.ConvertFrom(evaluationResult!);
return wrapped.ConvertToDesiredType(evaluationResult, desiredType);
return _wrapped.ConvertToDesiredType(evaluationResult, desiredType);
}
public TypeConverterResultConverter(IConvertsJintEvaluationResult wrapped)
{
this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
this._wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
}
}
}