Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/StoragesBenchmark/OrchestrationBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task RunOrchestrations()
foreach (var instance in instances)
{
var state = await taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(30));
if (state == null || state.OrchestrationStatus != OrchestrationStatus.Completed)
if (state is null || state.OrchestrationStatus != OrchestrationStatus.Completed)
throw new Exception("Orchestration did not complete");
}
}
Expand Down
13 changes: 4 additions & 9 deletions samples/BpmnWorker/Activities/HttpRequestActivity.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using LLL.DurableTask.Worker;
using LLL.DurableTask.Worker.Attributes;
using Newtonsoft.Json;
Expand All @@ -21,15 +16,15 @@ public override async Task<Output> ExecuteAsync(Input input)
Method = input.Method
};

if (input.Headers != null)
if (input.Headers is not null)
{
foreach (var header in input.Headers)
{
httpRequest.Headers.Add(header.Key, header.Value);
}
}

if (input.Content != null)
if (input.Content is not null)
{
var json = JsonConvert.SerializeObject(input.Content);
httpRequest.Content = new StringContent(json, Encoding.UTF8, "application/json");
Expand All @@ -41,7 +36,7 @@ public override async Task<Output> ExecuteAsync(Input input)
string contentRaw = null;
object content = null;

if (httpResponse.Content != null)
if (httpResponse.Content is not null)
{
contentRaw = await httpResponse.Content.ReadAsStringAsync();

Expand Down
39 changes: 16 additions & 23 deletions samples/BpmnWorker/Orchestrations/BPMNOrchestrator.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Concurrent;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using BpmnWorker.Activities;
using BpmnWorker.Providers;
using LLL.DurableTask.Worker;
using LLL.DurableTask.Worker.Attributes;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using Spec.BPMN.MODEL;

Expand Down Expand Up @@ -218,14 +211,14 @@ private async Task VisitServiceTask(TServiceTask serviceTask)
private async Task<JObject> PrepareInput(XmlElement element)
{
var input = default(JObject);
if (element != null)
if (element is not null)
{
input = new JObject();
foreach (var inputParameter in element.ChildNodes.OfType<XmlElement>().Where(x => x.LocalName == "inputParameter"))
{
var name = inputParameter.GetAttribute("name");
var script = inputParameter.ChildNodes.OfType<XmlElement>().FirstOrDefault(x => x.LocalName == "script");
if (script != null)
if (script is not null)
{
var scriptFormat = script.GetAttribute("scriptFormat");
var scriptContent = script.InnerText;
Expand All @@ -247,14 +240,14 @@ private async Task<JObject> PrepareInput(XmlElement element)

private async Task ProcessOutput(XmlElement element, JToken output)
{
if (element == null)
if (element is null)
return;

foreach (var outputParameter in element.ChildNodes.OfType<XmlElement>().Where(x => x.LocalName == "outputParameter"))
{
var name = outputParameter.GetAttribute("name");
var script = outputParameter.ChildNodes.OfType<XmlElement>().FirstOrDefault(x => x.LocalName == "script");
if (script != null)
if (script is not null)
{
var scriptFormat = script.GetAttribute("scriptFormat");
var scriptContent = script.InnerText;
Expand Down Expand Up @@ -286,7 +279,7 @@ private async Task VisitScriptTask(TScriptTask scriptTask)
var output = await Context.ScheduleTask<JToken>("Script", string.Empty, input);

var resultVariable = scriptTask.AnyAttribute.FirstOrDefault(a => a.LocalName == "resultVariable")?.Value;
if (resultVariable != null)
if (resultVariable is not null)
{
_variables[resultVariable] = output;
}
Expand Down Expand Up @@ -357,7 +350,7 @@ private async Task VisitIntermediateCatchTimerEvent(
TIntermediateCatchEvent intermediateCatchEvent,
TTimerEventDefinition timerEventDefinition)
{
if (timerEventDefinition.TimeDate != null)
if (timerEventDefinition.TimeDate is not null)
{
var fireAt = XmlConvert.ToDateTime(timerEventDefinition.TimeDate.Text.First(), XmlDateTimeSerializationMode.Local);
_logger.LogWarning("Waiting for timer {fireAt}", fireAt);
Expand All @@ -366,7 +359,7 @@ private async Task VisitIntermediateCatchTimerEvent(

await VisitFlowNodes(GetParallelOutgoingNodes(intermediateCatchEvent));
}
else if (timerEventDefinition.TimeDuration != null)
else if (timerEventDefinition.TimeDuration is not null)
{
var duration = XmlConvert.ToTimeSpan(timerEventDefinition.TimeDuration.Text.First());
var fireAt = Context.CurrentUtcDateTime.Add(duration);
Expand All @@ -385,16 +378,16 @@ private async Task VisitIntermediateCatchTimerEvent(
private TFlowNode GetExclusiveOutgoingNode(TFlowNode flowNode)
{
var sequence = FindByIds<TSequenceFlow>(flowNode.Outgoing.Select(x => x.Name))
.Where(x => x.ConditionExpression != null)
.Where(x => x.ConditionExpression is not null)
.FirstOrDefault(EvaluateSequence);

if (sequence != null)
if (sequence is not null)
return FindById<TFlowNode>(sequence.TargetRef);

var defaultSequence = FindByIds<TSequenceFlow>(flowNode.Outgoing.Select(x => x.Name))
.FirstOrDefault(x => x.ConditionExpression == null);
.FirstOrDefault(x => x.ConditionExpression is null);

if (defaultSequence == null)
if (defaultSequence is null)
throw new Exception("No applicable exclusive outgoing node");

return FindById<TFlowNode>(defaultSequence.TargetRef);
Expand All @@ -403,17 +396,17 @@ private TFlowNode GetExclusiveOutgoingNode(TFlowNode flowNode)
private TFlowNode[] GetInclusiveOutgoingNodes(TFlowNode flowNode)
{
var sequences = FindByIds<TSequenceFlow>(flowNode.Outgoing.Select(x => x.Name))
.Where(x => x.ConditionExpression != null)
.Where(x => x.ConditionExpression is not null)
.Where(EvaluateSequence)
.ToArray();

if (sequences.Length > 0)
return FindByIds<TFlowNode>(sequences.Select(s => s.TargetRef));

var defaultSequence = FindByIds<TSequenceFlow>(flowNode.Outgoing.Select(x => x.Name))
.FirstOrDefault(x => x.ConditionExpression == null);
.FirstOrDefault(x => x.ConditionExpression is null);

if (defaultSequence == null)
if (defaultSequence is null)
throw new Exception("No applicable invlusive outgoing node");

return new TFlowNode[] {
Expand Down Expand Up @@ -451,7 +444,7 @@ private TFlowNode[] GetBoundaryFlowNodes(TBoundaryEvent boundaryEvent)
private bool EvaluateSequence(TSequenceFlow sequenceFlow)
{
var expression = sequenceFlow.ConditionExpression?.Text?.FirstOrDefault();
if (expression == null)
if (expression is null)
return true;

var result = _scriptExecutor.Execute<bool>("javascript", expression, new Dictionary<string, object>
Expand Down
6 changes: 2 additions & 4 deletions samples/BpmnWorker/Scripting/CSharpScriptEngine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Newtonsoft.Json;

namespace BpmnWorker.Scripting;
Expand All @@ -10,7 +8,7 @@ public class CSharpScriptEngine : IScriptEngine
public async Task<T> Execute<T>(string script, IDictionary<string, object> variables)
{
var output = await CSharpScript.EvaluateAsync(script);
if (output == null)
if (output is null)
return default;

if (output is T t)
Expand Down
11 changes: 4 additions & 7 deletions samples/BpmnWorker/Scripting/JavaScriptScriptEngine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.ClearScript.V8;
using Microsoft.ClearScript.V8;
using Newtonsoft.Json;

namespace BpmnWorker.Scripting;
Expand All @@ -11,11 +8,11 @@ public class JavaScriptScriptEngine : IScriptEngine
public Task<T> Execute<T>(string script, IDictionary<string, object> variables)
{
using var engine = new V8ScriptEngine();
if (variables != null)
if (variables is not null)
{
foreach (var kv in variables)
{
if (kv.Value != null)
if (kv.Value is not null)
{
var inputJson = JsonConvert.SerializeObject(kv.Value);
var inputJs = engine.Script.JSON.parse(inputJson);
Expand All @@ -27,7 +24,7 @@ public Task<T> Execute<T>(string script, IDictionary<string, object> variables)
engine.AddHostType("Console", typeof(Console));

var outputJs = engine.Evaluate(script);
if (outputJs == null)
if (outputJs is null)
return Task.FromResult(default(T));

if (engine.Script.JSON.stringify(outputJs) is not string outputJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static IServiceCollection AddDurableTaskApi(
{
services.AddOptions<DurableTaskApiOptions>();

if (configure != null)
if (configure is not null)
services.Configure<DurableTaskApiOptions>(configure);

return services;
Expand Down
4 changes: 2 additions & 2 deletions src/LLL.DurableTask.Api/Endpoints/EntrypointEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public static IReadOnlyList<IEndpointConventionBuilder> MapEntrypointEndpoint(
{
var durableTaskEndpointMetadata = endpoint.Metadata.GetMetadata<DurableTaskEndpointMetadata>();

if (durableTaskEndpointMetadata == null)
if (durableTaskEndpointMetadata is null)
continue;

var authorized = true;

var policies = endpoint.Metadata.OfType<AuthorizeAttribute>()
.Select(a => a.Policy)
.Where(p => p != null)
.Where(p => p is not null)
.ToArray();

if (policies.Length > 0)
Expand Down
4 changes: 2 additions & 2 deletions src/LLL.DurableTask.Api/Endpoints/OrchestrationsEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static IReadOnlyList<IEndpointConventionBuilder> MapOrchestrationEndpoint

var state = await taskHubClient.GetOrchestrationStateAsync(instanceId);

if (state == null)
if (state is null)
{
context.Response.StatusCode = 404;
return;
Expand All @@ -104,7 +104,7 @@ public static IReadOnlyList<IEndpointConventionBuilder> MapOrchestrationEndpoint

var state = await taskHubClient.GetOrchestrationStateAsync(instanceId, executionId);

if (state == null)
if (state is null)
{
context.Response.StatusCode = 404;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

var eventTypeToken = jObject.GetValue("EventType", StringComparison.OrdinalIgnoreCase);

if (eventTypeToken == null)
if (eventTypeToken is null)
throw new Exception("Expected EventType field in HistoryEvent");

var eventType = eventTypeToken.ToObject<EventType>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override async Task<Instance> LockInstanceForUpdate(OrchestrationDbContex
{
var instance = dbContext.Instances.Find(instanceId);

if (instance == null)
if (instance is null)
return null;

var lockedInstances = _lockedInstanes.GetOrAdd(dbContext, (d) => new HashSet<string>());
Expand Down Expand Up @@ -65,7 +65,7 @@ orderby b.AvailableAt
select b.Instance
).FirstOrDefault();

if (instance == null)
if (instance is null)
return Task.FromResult(default(Instance));

instance.LockId = Guid.NewGuid().ToString();
Expand All @@ -92,7 +92,7 @@ orderby b.AvailableAt
select b.Instance
).FirstOrDefault();

if (instance == null)
if (instance is null)
return Task.FromResult(default(Instance));

instance.LockId = Guid.NewGuid().ToString();
Expand All @@ -116,7 +116,7 @@ orderby message.LockedUntil
select message
).FirstOrDefault();

if (activityMessage == null)
if (activityMessage is null)
return Task.FromResult(default(ActivityMessage));

activityMessage.LockId = Guid.NewGuid().ToString();
Expand All @@ -142,7 +142,7 @@ orderby message.LockedUntil
select message
).FirstOrDefault();

if (activityMessage == null)
if (activityMessage is null)
return Task.FromResult(default(ActivityMessage));

activityMessage.LockId = Guid.NewGuid().ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ LIMIT 1
FOR UPDATE SKIP LOCKED
", DateTime.UtcNow).WithStraightJoin().ToArrayAsync()).FirstOrDefault();

if (instance == null)
if (instance is null)
return null;

instance.LockId = Guid.NewGuid().ToString();
Expand Down Expand Up @@ -84,7 +84,7 @@ LIMIT 1
FOR UPDATE SKIP LOCKED
", parameters).WithStraightJoin().ToArrayAsync()).FirstOrDefault();

if (instance == null)
if (instance is null)
return null;

instance.LockId = Guid.NewGuid().ToString();
Expand All @@ -106,7 +106,7 @@ LIMIT 1
FOR UPDATE SKIP LOCKED
", DateTime.UtcNow).ToArrayAsync()).FirstOrDefault();

if (instance == null)
if (instance is null)
return null;

instance.LockId = Guid.NewGuid().ToString();
Expand All @@ -133,7 +133,7 @@ LIMIT 1
FOR UPDATE SKIP LOCKED
", parameters).ToArrayAsync()).FirstOrDefault();

if (instance == null)
if (instance is null)
return null;

instance.LockId = Guid.NewGuid().ToString();
Expand Down Expand Up @@ -174,10 +174,10 @@ SELECT Executions.ExecutionId
FROM Executions
INNER JOIN Instances ON Executions.InstanceId = Instances.InstanceId
WHERE Executions.CreatedTime > {parameters.Add(filter.CreatedTimeFrom)}
{(filter.CreatedTimeTo != null ? $"AND Executions.CreatedTime < {parameters.Add(filter.CreatedTimeTo)}" : "")}
{(filter.CreatedTimeTo is not null ? $"AND Executions.CreatedTime < {parameters.Add(filter.CreatedTimeTo)}" : "")}
{(filter.RuntimeStatus.Any() ? $"AND Executions.Status IN ({string.Join(",", filter.RuntimeStatus.Select(s => parameters.Add(s.ToString())))})" : "")}
ORDER BY Executions.CreatedTime
{(limit != null ? $"LIMIT {parameters.Add(limit)}" : null)}
{(limit is not null ? $"LIMIT {parameters.Add(limit)}" : null)}
FOR UPDATE SKIP LOCKED
) T
);
Expand Down
Loading