Skip to content

Commit 6a799e9

Browse files
committed
Updated to WFE 4.0
1 parent 61ed532 commit 6a799e9

837 files changed

Lines changed: 10833 additions & 8772 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Providers/NETCore_OptimaJet.Workflow.MSSQL/MSSQLProvider.cs

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace OptimaJet.Workflow.DbPersistence
1717
{
18-
public class MSSQLProvider : IPersistenceProvider, ISchemePersistenceProvider<XElement>, IWorkflowGenerator<XElement>
18+
public class MSSQLProvider : IWorkflowProvider
1919
{
2020
public string ConnectionString { get; set; }
2121
private WorkflowRuntime _runtime;
@@ -140,6 +140,18 @@ public void SavePersistenceParameters(ProcessInstance processInstance)
140140
}
141141
}
142142
}
143+
144+
public void SetProcessStatus(Guid processId, ProcessStatus newStatus)
145+
{
146+
if (newStatus == ProcessStatus.Running)
147+
{
148+
SetRunningStatus(processId);
149+
}
150+
else
151+
{
152+
SetCustomStatus(processId,newStatus);
153+
}
154+
}
143155

144156
public void SetWorkflowIniialized(ProcessInstance processInstance)
145157
{
@@ -153,27 +165,8 @@ public void SetWorkflowIdled(ProcessInstance processInstance)
153165

154166
public void SetWorkflowRunning(ProcessInstance processInstance)
155167
{
156-
using (SqlConnection connection = new SqlConnection(ConnectionString))
157-
{
158-
var instanceStatus = WorkflowProcessInstanceStatus.SelectByKey(connection, processInstance.ProcessId);
159-
160-
if (instanceStatus == null)
161-
throw new StatusNotDefinedException();
162-
163-
if (instanceStatus.Status == ProcessStatus.Running.Id)
164-
165-
throw new ImpossibleToSetStatusException();
166-
167-
var oldLock = instanceStatus.Lock;
168-
169-
instanceStatus.Lock = Guid.NewGuid();
170-
instanceStatus.Status = ProcessStatus.Running.Id;
171-
172-
var cnt = WorkflowProcessInstanceStatus.ChangeStatus(connection, instanceStatus, oldLock);
173-
174-
if (cnt != 1)
175-
throw new ImpossibleToSetStatusException();
176-
}
168+
var processId = processInstance.ProcessId;
169+
SetRunningStatus(processId);
177170
}
178171

179172
public void SetWorkflowFinalized(ProcessInstance processInstance)
@@ -281,16 +274,40 @@ public ProcessStatus GetInstanceStatus(Guid processId)
281274
return status;
282275
}
283276
}
277+
278+
private void SetRunningStatus(Guid processId)
279+
{
280+
using (SqlConnection connection = new SqlConnection(ConnectionString))
281+
{
282+
var instanceStatus = WorkflowProcessInstanceStatus.SelectByKey(connection, processId);
283+
284+
if (instanceStatus == null)
285+
throw new StatusNotDefinedException();
284286

287+
if (instanceStatus.Status == ProcessStatus.Running.Id)
285288

286-
private void SetCustomStatus(Guid processId, ProcessStatus status, bool createIfnotDefined = false)
289+
throw new ImpossibleToSetStatusException();
290+
291+
var oldLock = instanceStatus.Lock;
292+
293+
instanceStatus.Lock = Guid.NewGuid();
294+
instanceStatus.Status = ProcessStatus.Running.Id;
295+
296+
var cnt = WorkflowProcessInstanceStatus.ChangeStatus(connection, instanceStatus, oldLock);
297+
298+
if (cnt != 1)
299+
throw new ImpossibleToSetStatusException();
300+
}
301+
}
302+
303+
private void SetCustomStatus(Guid processId, ProcessStatus status, bool createIfNotDefined = false)
287304
{
288305
using (SqlConnection connection = new SqlConnection(ConnectionString))
289306
{
290307
var instanceStatus = WorkflowProcessInstanceStatus.SelectByKey(connection, processId);
291308
if (instanceStatus == null)
292309
{
293-
if (!createIfnotDefined)
310+
if (!createIfNotDefined)
294311
throw new StatusNotDefinedException();
295312

296313
instanceStatus = new WorkflowProcessInstanceStatus()
@@ -613,6 +630,15 @@ public List<ProcessHistoryItem> GetProcessHistory(Guid processId)
613630
}
614631
}
615632

633+
public IEnumerable<ProcessTimer> GetTimersForProcess(Guid processId)
634+
{
635+
using (var connection = new SqlConnection(ConnectionString))
636+
{
637+
var timers = WorkflowProcessTimer.SelectByProcessId(connection, processId);
638+
return timers.Select(t => new ProcessTimer { Name = t.Name, NextExecutionDateTime = t.NextExecutionDateTime });
639+
}
640+
}
641+
616642
#endregion
617643

618644
#region ISchemePersistenceProvider
@@ -711,7 +737,7 @@ public void SaveScheme(SchemeDefinition<XElement> scheme)
711737
{
712738
if (oldSchemes.Any(oldScheme => oldScheme.DefiningParameters == definingParameters))
713739
{
714-
throw SchemeAlredyExistsException.Create(scheme.SchemeCode, SchemeLocation.WorkflowProcessScheme, scheme.DefiningParameters);
740+
throw SchemeAlreadyExistsException.Create(scheme.SchemeCode, SchemeLocation.WorkflowProcessScheme, scheme.DefiningParameters);
715741
}
716742
}
717743

@@ -733,21 +759,24 @@ public void SaveScheme(SchemeDefinition<XElement> scheme)
733759
}
734760
}
735761

736-
public void SaveScheme(string schemaCode, string scheme)
762+
public void SaveScheme(string schemaCode,bool canBeInlined, List<string> inlinedSchemes, string scheme)
737763
{
738764
using (SqlConnection connection = new SqlConnection(ConnectionString))
739765
{
740766
WorkflowScheme wfScheme = WorkflowScheme.SelectByKey(connection, schemaCode);
741767
if (wfScheme == null)
742768
{
743-
wfScheme = new WorkflowScheme();
744-
wfScheme.Code = schemaCode;
745-
wfScheme.Scheme = scheme;
769+
wfScheme = new WorkflowScheme
770+
{
771+
Code = schemaCode, Scheme = scheme, CanBeInlined = canBeInlined, InlinedSchemes = inlinedSchemes.Any() ? JsonConvert.SerializeObject(inlinedSchemes) : null
772+
};
746773
wfScheme.Insert(connection);
747774
}
748775
else
749776
{
750777
wfScheme.Scheme = scheme;
778+
wfScheme.CanBeInlined = canBeInlined;
779+
wfScheme.InlinedSchemes = inlinedSchemes.Any() ? JsonConvert.SerializeObject(inlinedSchemes) : null;
751780
wfScheme.Update(connection);
752781
}
753782

@@ -768,6 +797,22 @@ public XElement GetScheme(string code)
768797
}
769798
}
770799

800+
public List<string> GetInlinedSchemeCodes()
801+
{
802+
using (SqlConnection connection = new SqlConnection(ConnectionString))
803+
{
804+
return WorkflowScheme.GetInlinedSchemeCodes(connection);
805+
}
806+
}
807+
808+
public List<string> GetRelatedByInliningSchemeCodes(string schemeCode)
809+
{
810+
using (SqlConnection connection = new SqlConnection(ConnectionString))
811+
{
812+
return WorkflowScheme.GetRelatedSchemeCodes(connection,schemeCode);
813+
}
814+
}
815+
771816
#endregion
772817

773818
#region IWorkflowGenerator

Providers/NETCore_OptimaJet.Workflow.MSSQL/Models/WorkflowProcessTimer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ public static WorkflowProcessTimer SelectByProcessIdAndName(SqlConnection connec
117117
return Select(connection, selectText, p1, p2).FirstOrDefault();
118118
}
119119

120+
public static IEnumerable<WorkflowProcessTimer> SelectByProcessId(SqlConnection connection, Guid processId)
121+
{
122+
var selectText = string.Format("SELECT * FROM {0} WHERE [ProcessId] = @processid", ObjectName);
123+
124+
var p1 = new SqlParameter("processid", SqlDbType.UniqueIdentifier) { Value = processId };
125+
126+
return Select(connection, selectText, p1);
127+
}
128+
120129
public static int ClearTimersIgnore(SqlConnection connection)
121130
{
122131
var command = string.Format("UPDATE {0} SET [Ignore] = 0 WHERE [Ignore] = 1", ObjectName);

Providers/NETCore_OptimaJet.Workflow.MSSQL/Models/WorkflowScheme.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.SqlClient;
5+
using System.Linq;
6+
using System.Threading.Tasks;
27

38
// ReSharper disable once CheckNamespace
49

@@ -16,12 +21,19 @@ public WorkflowScheme()
1621
DbColumns.AddRange(new[]
1722
{
1823
new ColumnInfo {Name = "Code", IsKey = true},
19-
new ColumnInfo {Name = "Scheme", Size = -1}
24+
new ColumnInfo {Name = "Scheme", Size = -1},
25+
new ColumnInfo {Name = nameof(CanBeInlined), Type = SqlDbType.Bit},
26+
new ColumnInfo {Name = nameof(InlinedSchemes)}
27+
2028
});
2129
}
2230

2331
public string Code { get; set; }
2432
public string Scheme { get; set; }
33+
34+
public bool CanBeInlined { get; set; }
35+
36+
public string InlinedSchemes { get; set; }
2537

2638
public override object GetValue(string key)
2739
{
@@ -31,8 +43,12 @@ public override object GetValue(string key)
3143
return Code;
3244
case "Scheme":
3345
return Scheme;
46+
case nameof(CanBeInlined):
47+
return CanBeInlined;
48+
case nameof(InlinedSchemes):
49+
return InlinedSchemes;
3450
default:
35-
throw new Exception(string.Format("Column {0} is not exists", key));
51+
throw new Exception($"Column {key} is not exists");
3652
}
3753
}
3854

@@ -46,9 +62,29 @@ public override void SetValue(string key, object value)
4662
case "Scheme":
4763
Scheme = value as string;
4864
break;
65+
case nameof(CanBeInlined):
66+
CanBeInlined = (bool) value;
67+
break;
68+
case nameof(InlinedSchemes):
69+
InlinedSchemes = value as string;
70+
break;
4971
default:
50-
throw new Exception(string.Format("Column {0} is not exists", key));
72+
throw new Exception($"Column {key} is not exists");
5173
}
5274
}
75+
76+
public static List<string> GetInlinedSchemeCodes(SqlConnection connection)
77+
{
78+
var selectText = $"SELECT * FROM {ObjectName} WHERE [CanBeInlined] = 1";
79+
var schemes = Select(connection, selectText);
80+
return schemes.Select(sch => sch.Code).ToList();
81+
}
82+
83+
public static List<string> GetRelatedSchemeCodes(SqlConnection connection, string schemeCode)
84+
{
85+
var selectText = $"SELECT * FROM {ObjectName} WHERE [{nameof(InlinedSchemes)}] LIKE '%' + @search + '%'";
86+
var p = new SqlParameter("search", SqlDbType.NVarChar) {Value = $"\"{schemeCode}\""};
87+
return Select(connection, selectText, p).Select(sch=>sch.Code).Distinct().ToList();
88+
}
5389
}
5490
}

Providers/NETCore_OptimaJet.Workflow.MSSQL/NETCore_OptimaJet.Workflow.MSSQL.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<AssemblyName>OptimaJet.Workflow.MSSQL</AssemblyName>
77
<SignAssembly>True</SignAssembly>
88
<AssemblyOriginatorKeyFile>Workflow.snk</AssemblyOriginatorKeyFile>
9-
<AssemblyVersion>3.5.0.0</AssemblyVersion>
10-
<FileVersion>3.5.0.0</FileVersion>
11-
<Version>3.5.0</Version>
9+
<AssemblyVersion>4.0.0.0</AssemblyVersion>
10+
<FileVersion>4.0.0.0</FileVersion>
11+
<Version>4.0.0</Version>
1212
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1313
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
1414
<Authors>OptimaJet, LLC</Authors>
@@ -24,7 +24,7 @@ Create WorkflowRuntime section.</Description>
2424
<PackageLicenseUrl>https://workflowengine.io/agreements/eula/</PackageLicenseUrl>
2525
<PackageProjectUrl>https://workflowengine.io</PackageProjectUrl>
2626
<PackageId>WorkflowEngine.NETCore-ProviderForMSSQL</PackageId>
27-
<PackageIconUrl>https://images.workflowengine.io/logos/favicon.png</PackageIconUrl>
27+
<PackageIconUrl>https://workflowengine.io/images/favicons/favicon.ico</PackageIconUrl>
2828
<PackageTags>workflow engine, ms sql, for sql</PackageTags>
2929
<PackageReleaseNotes>https://workflowengine.io/documentation/release-notes/</PackageReleaseNotes>
3030
</PropertyGroup>

Providers/NETCore_OptimaJet.Workflow.MSSQL/Scripts/CreatePersistenceObjects.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Company: OptimaJet
33
Project: WorkflowEngine.NET Provider for MSSQL and Azure SQL
4-
Version: 3.5
4+
Version: 4.0
55
File: CreatePersistenceObjects.sql
66
77
*/
@@ -145,8 +145,10 @@ IF NOT EXISTS (
145145
)
146146
BEGIN
147147
CREATE TABLE WorkflowScheme (
148-
[Code] NVARCHAR(256) NOT NULL CONSTRAINT PK_WorkflowScheme PRIMARY KEY
149-
,[Scheme] NVARCHAR(max) NOT NULL
148+
[Code] NVARCHAR(256) NOT NULL CONSTRAINT PK_WorkflowScheme PRIMARY KEY,
149+
[Scheme] NVARCHAR(max) NOT NULL,
150+
[CanBeInlined] [bit] NOT NULL DEFAULT(0),
151+
[InlinedSchemes] [nvarchar](max) NULL
150152
)
151153

152154
PRINT 'WorkflowScheme CREATE TABLE'

Providers/NETCore_OptimaJet.Workflow.MSSQL/Scripts/DropPersistenceObjects.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Company: OptimaJet
33
Project: WorkflowEngine.NET Provider for MSSQL
4-
Version: 3.5
4+
Version: 4.0
55
File: DropPersistenceObjects.sql
66
*/
77

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Company: OptimaJet
3+
Project: WorkflowEngine.NET Provider for SQLServer
4+
Version: 4.0
5+
File: update_4_0.sql
6+
*/
7+
8+
--WorkflowScheme
9+
IF NOT EXISTS (SELECT 1 FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = N'WorkflowScheme'
10+
AND [COLUMN_NAME] = N'CanBeInlined')
11+
BEGIN
12+
ALTER TABLE WorkflowScheme ADD CanBeInlined [bit] NOT NULL DEFAULT(0)
13+
PRINT 'ADD WorkflowScheme.CanBeInlined type bit'
14+
END
15+
GO
16+
17+
18+
IF NOT EXISTS (SELECT 1 FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = N'WorkflowScheme'
19+
AND [COLUMN_NAME] = N'InlinedSchemes')
20+
BEGIN
21+
ALTER TABLE WorkflowScheme ADD InlinedSchemes [nvarchar](max) NULL
22+
PRINT 'ADD WorkflowScheme.InlinedSchemes type [nvarchar](max)'
23+
END
24+
GO
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// ReSharper disable once CheckNamespace
22

3+
using System.Collections.Generic;
4+
35
namespace OptimaJet.Workflow.MongoDB
46
{
57
public class WorkflowScheme : DynamicEntity
68
{
79
public string Id { get; set; }
810
public string Code { get; set; }
911
public string Scheme { get; set; }
12+
public bool CanBeInlined { get; set; }
13+
public List<string> InlinedSchemes { get; set; }
1014
}
1115
}

0 commit comments

Comments
 (0)