diff --git a/WorkFlowCore/Commons/Common.BackgroundWorker/Common.BackgroundWorker.csproj b/WorkFlowCore/Commons/Common.BackgroundWorker/Common.BackgroundWorker.csproj
index 7d6b96f14e466f24d1e854e07a028ec12dd3d751..0a3b92c384b8ca360b3606d12d78656370669470 100644
--- a/WorkFlowCore/Commons/Common.BackgroundWorker/Common.BackgroundWorker.csproj
+++ b/WorkFlowCore/Commons/Common.BackgroundWorker/Common.BackgroundWorker.csproj
@@ -17,6 +17,7 @@
+
diff --git a/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs b/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs
index eddfd03507748038596be93d8674e0616eaf6f95..61ee086e801d4f2298a9d13a3025bdd45c84df14 100644
--- a/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs
+++ b/WorkFlowCore/Commons/Common.BackgroundWorker/QuartzImplement/CustomerJob.cs
@@ -1,6 +1,7 @@
using Common.EventBus;
using Common.IBaseRepositories;
using Common.QuartzImplement.BackgroundWorker;
+using Common.UnitOfWork;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using System;
@@ -40,7 +41,7 @@ namespace Common.BackgroundWorker.QuartzImplement
try
{
await job.Execute(context);
- if (unitOfWork.Commit()) domainEventBusService?.Trigger();
+ if (unitOfWork==null||unitOfWork.Commit()) domainEventBusService?.Trigger();
}
catch (Exception ex)
{
diff --git a/WorkFlowCore/Commons/Common.BaseRepositories4EF/BaseRepositories4EFModule.cs b/WorkFlowCore/Commons/Common.BaseRepositories4EF/BaseRepositories4EFModule.cs
index 3735f59c16df1515d2c0cfa8699e6bf364c2ad03..f2d3bd1da40ca89c0fe3984c9aba4c35a80b43d4 100644
--- a/WorkFlowCore/Commons/Common.BaseRepositories4EF/BaseRepositories4EFModule.cs
+++ b/WorkFlowCore/Commons/Common.BaseRepositories4EF/BaseRepositories4EFModule.cs
@@ -1,5 +1,6 @@
using Common.IBaseRepositories;
using Common.IBaseRepositories4EF;
+using Common.UnitOfWork4EntityFramework;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
@@ -14,9 +15,7 @@ namespace Common.BaseRepositories4EF
services.AddScoped(typeof(IBasicRepository<,>), typeof(BasicRepository4EF<,>));
services.AddScoped(typeof(IBasicRepository<>), typeof(BasicRepository4EF<>));
services.AddScoped(typeof(IBasicRepository4EF<,>), typeof(BasicRepository4EF<,>));
- services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork4EF));
- //services.AddScoped(typeof(UnitOfWork4EF));
- services.AddScoped(typeof(IUnitOfWorkManager), typeof(UnitOfWorkManager4EF));
+ services.AddUnitOfWork4EntityFramework();
return services;
}
}
diff --git a/WorkFlowCore/Commons/Common.BaseRepositories4EF/BasicRepository4EF.cs b/WorkFlowCore/Commons/Common.BaseRepositories4EF/BasicRepository4EF.cs
index 7d367a8537160faa64b5a8e4b27077fa39093e2c..938b7743da3e4b9a4c99fc9e2c3b0379dde78224 100644
--- a/WorkFlowCore/Commons/Common.BaseRepositories4EF/BasicRepository4EF.cs
+++ b/WorkFlowCore/Commons/Common.BaseRepositories4EF/BasicRepository4EF.cs
@@ -14,6 +14,8 @@ using Common.Authorization;
using Common.IBaseRepositories4EF.Conditons;
using Common.IBaseRepositories4EF;
using Microsoft.EntityFrameworkCore;
+using Common.UnitOfWork4EntityFramework;
+using Common.UnitOfWork;
namespace Common.BaseRepositories4EF
{
diff --git a/WorkFlowCore/Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj b/WorkFlowCore/Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj
index 2c19711803a4aad59d4ae4f1918d6602454ae307..7d33f57650fecf94ec773e2f4f72303521d517f1 100644
--- a/WorkFlowCore/Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj
+++ b/WorkFlowCore/Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj
@@ -4,6 +4,11 @@
netcoreapp3.1
+
+
+
+
+
@@ -15,6 +20,7 @@
+
diff --git a/WorkFlowCore/Commons/Common.Configuration.Extension/ConfigurationExtension.cs b/WorkFlowCore/Commons/Common.Configuration.Extension/ConfigurationExtension.cs
index 03f6120a425230bb7075777f72acc7a2bcf76a4c..8e8956581f56846c990258b87e88eef768cdb590 100644
--- a/WorkFlowCore/Commons/Common.Configuration.Extension/ConfigurationExtension.cs
+++ b/WorkFlowCore/Commons/Common.Configuration.Extension/ConfigurationExtension.cs
@@ -16,6 +16,7 @@ namespace Microsoft.Extensions.Configuration
private static string GetEnvironmentVariable(string value, IConfiguration configuration)
{
+ if (string.IsNullOrEmpty(value)) return value;
var result = value;
var param = GetParameters(result).FirstOrDefault();
if (!string.IsNullOrEmpty(param))
@@ -24,7 +25,7 @@ namespace Microsoft.Extensions.Configuration
var console = configuration[param];
if (!string.IsNullOrEmpty(console))
{
- return console;
+ return GetRealValue(console, console);
}
//其次充环境变量取值
var env = Environment.GetEnvironmentVariable(param);
@@ -32,13 +33,20 @@ namespace Microsoft.Extensions.Configuration
if (string.IsNullOrEmpty(env))
{
//最后从配置文件取值
- var arrayData = value.ToString().Split("|");
- result = arrayData.Length == 2 ? arrayData[1] : env;
+ result = GetRealValue(value, env);
}
}
return result;
}
+ private static string GetRealValue(string value, string env)
+ {
+ string result;
+ var arrayData = value.ToString().Split("|");
+ result = arrayData.Length == 2 ? arrayData[1] : env;
+ return result;
+ }
+
private static List GetParameters(string text)
{
var matchVale = new List();
diff --git a/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs b/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs
index 3288b1c810b6b655b5d3fc99b45e18fab12c97e2..cfe1783a9d0748691862672755377ee54af439a3 100644
--- a/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs
+++ b/WorkFlowCore/Commons/Common.DynamicApi/DynamicApiInterceptors/UnitOfWorkApiInterceptor.cs
@@ -1,5 +1,6 @@
using Common.EventBus;
using Common.IBaseRepositories;
+using Common.UnitOfWork;
using System;
using System.Collections.Generic;
using System.Text;
@@ -24,7 +25,7 @@ namespace Common.DynamicApi.DynamicApiInterceptors
public void Executed()
{
- if (unitOfWork.Commit()) domainEventBusService.Trigger();
+ //if (unitOfWork.Commit()) domainEventBusService.Trigger();
}
}
}
diff --git a/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBus.cs b/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBus.cs
index cba0aacc24aa268ef0b9e761e3a1cd047af5d70a..4db67dd11b77abab647f0a982a8cb8ef238c1251 100644
--- a/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBus.cs
+++ b/WorkFlowCore/Commons/Common.EventBus.Default/DefaultEventBus.cs
@@ -1,4 +1,4 @@
-using Common.IBaseRepositories;
+using Common.UnitOfWork;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System;
@@ -175,7 +175,7 @@ namespace Common.EventBus.Default
var unitOfWork = scope.ServiceProvider.GetService();
var domainEventBusService = scope.ServiceProvider.GetService();
- if (unitOfWork.Commit()) domainEventBusService?.Trigger();
+ if (unitOfWork==null||unitOfWork.Commit()) domainEventBusService?.Trigger();
}
});
diff --git a/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBus.cs b/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBus.cs
index 8f60eec691d59c04aa79aa12ef3c2c7420fe2b6f..2c2ffbcedd03b3546c3be372f6345e763877244b 100644
--- a/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBus.cs
+++ b/WorkFlowCore/Commons/Common.EventBus.Kafka/KafkaEventBus.cs
@@ -1,5 +1,4 @@
-using Common.EventBus.Implements.Kafka;
-using Common.IBaseRepositories;
+using Common.UnitOfWork;
using Confluent.Kafka;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -99,7 +98,7 @@ namespace Common.EventBus.Kafka
var unitOfWork = scope.ServiceProvider.GetService();
var domainEventBusService = scope.ServiceProvider.GetService();
- if (unitOfWork.Commit()) domainEventBusService?.Trigger();
+ if (unitOfWork == null || unitOfWork.Commit()) domainEventBusService?.Trigger();
}
c.Commit(cr);
diff --git a/WorkFlowCore/Commons/Common.EventBus/Common.EventBus.csproj b/WorkFlowCore/Commons/Common.EventBus/Common.EventBus.csproj
index 3215fd65c93a7502be6102883ec425af0a03da2f..2991563f7f25e231051ab340e95061b0715747e9 100644
--- a/WorkFlowCore/Commons/Common.EventBus/Common.EventBus.csproj
+++ b/WorkFlowCore/Commons/Common.EventBus/Common.EventBus.csproj
@@ -14,7 +14,7 @@
-
+
diff --git a/WorkFlowCore/Commons/Common.EventBus/EventBusMiddleware.cs b/WorkFlowCore/Commons/Common.EventBus/EventBusMiddleware.cs
new file mode 100644
index 0000000000000000000000000000000000000000..60b52e0a882b68837236adfddca49f46c45b25c9
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.EventBus/EventBusMiddleware.cs
@@ -0,0 +1,25 @@
+using Common.UnitOfWork;
+using Microsoft.AspNetCore.Http;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Common.EventBus
+{
+ public class EventBusMiddleware
+ {
+ private readonly RequestDelegate next;
+
+ public EventBusMiddleware( RequestDelegate next)
+ {
+ this.next = next;
+ }
+
+ public async Task Invoke(HttpContext context,IUnitOfWork unitOfWork, DomainEventBusService domainEventBusService)
+ {
+ await next(context);
+ if (unitOfWork.HasCommitted()) domainEventBusService.Trigger();
+ }
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs b/WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs
index 3deac7cb277e44d18c9c9d51a64229c667a3c83c..bcff8706e3703f74eb197cace85c81d9567daca7 100644
--- a/WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs
+++ b/WorkFlowCore/Commons/Common.EventBus/EventBusModule.cs
@@ -1,5 +1,4 @@
-using Common.EventBus.Implements.Kafka;
-using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
@@ -25,5 +24,18 @@ namespace Common.EventBus
return app;
}
+ ///
+ /// 在 UseUnitOfWork之前执行;
+ ///
+ ///
+ ///
+ public static IApplicationBuilder UseEventBus(this IApplicationBuilder app)
+ {
+ //注册普通事件,该事件订阅在单应用有效无法分布式
+ DomainEventBusManager.Init(app.ApplicationServices);
+ app.UseMiddleware();
+ return app;
+
+ }
}
}
diff --git a/WorkFlowCore/Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj b/WorkFlowCore/Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj
index 9b05c3d187b20773fd49d02bfd3418fbfb47d966..a598388c6e1f0f3d7b7eb3af6580b28a3f0cf82e 100644
--- a/WorkFlowCore/Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj
+++ b/WorkFlowCore/Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj
@@ -1,9 +1,14 @@
-
+
netcoreapp3.1
+
+
+
+
+
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork/Common.UnitOfWork.csproj b/WorkFlowCore/Commons/Common.UnitOfWork/Common.UnitOfWork.csproj
new file mode 100644
index 0000000000000000000000000000000000000000..0b8973c2c9ee734c1e322472d7d75234e7ed1dec
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork/Common.UnitOfWork.csproj
@@ -0,0 +1,11 @@
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork/IUnitOfWork.cs b/WorkFlowCore/Commons/Common.UnitOfWork/IUnitOfWork.cs
new file mode 100644
index 0000000000000000000000000000000000000000..9498982c963c6e2046ba03130a75eaa9914071d2
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork/IUnitOfWork.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Common.UnitOfWork
+{
+ public interface IUnitOfWork:IDisposable
+ {
+
+ bool Commit();
+ bool HasCommitted();
+ bool IsActive();
+ void Enabled();
+ void BeginWithoutLevel();
+ }
+
+ public static class IUnitOfWorkExtension
+ {
+ public static T Commit(this IUnitOfWork unitOfWork, T succeedResult, T failedResult)
+ {
+ return unitOfWork.Commit() ? succeedResult : failedResult;
+ }
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork/IUnitOfWorkManager.cs b/WorkFlowCore/Commons/Common.UnitOfWork/IUnitOfWorkManager.cs
new file mode 100644
index 0000000000000000000000000000000000000000..bacc66e2552ee73f615962282c0d9bcfdf7e42ce
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork/IUnitOfWorkManager.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Common.UnitOfWork
+{
+ public interface IUnitOfWorkManager
+ {
+ IUnitOfWork Begin();
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork/UnitOfWorkMiddleware.cs b/WorkFlowCore/Commons/Common.UnitOfWork/UnitOfWorkMiddleware.cs
new file mode 100644
index 0000000000000000000000000000000000000000..f9a46b3c0170a54350e21514c723c326a5e16dff
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork/UnitOfWorkMiddleware.cs
@@ -0,0 +1,26 @@
+using Microsoft.AspNetCore.Http;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Common.UnitOfWork
+{
+ public class UnitOfWorkMiddleware
+ {
+ private readonly RequestDelegate next;
+
+ public UnitOfWorkMiddleware( RequestDelegate next)
+ {
+ this.next = next;
+ }
+
+ public async Task Invoke(HttpContext context,IUnitOfWork unitOfWork)
+ {
+
+ unitOfWork.Enabled();
+ await next(context);
+ unitOfWork.Commit();
+ }
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork/UnitOfWorkModule.cs b/WorkFlowCore/Commons/Common.UnitOfWork/UnitOfWorkModule.cs
new file mode 100644
index 0000000000000000000000000000000000000000..59fff74396152784ff12838ba3eb680a03431253
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork/UnitOfWorkModule.cs
@@ -0,0 +1,17 @@
+using Microsoft.AspNetCore.Builder;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Common.UnitOfWork
+{
+ public static class UnitOfWorkModule
+ {
+ public static IApplicationBuilder UseUnitOfWork(this IApplicationBuilder app)
+ {
+ app.UseMiddleware();
+ return app;
+
+ }
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/Common.UnitOfWork4EntityFramework.csproj b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/Common.UnitOfWork4EntityFramework.csproj
new file mode 100644
index 0000000000000000000000000000000000000000..e38bcfc93eed9a76b8a3ecb211ce9e08608100f5
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/Common.UnitOfWork4EntityFramework.csproj
@@ -0,0 +1,15 @@
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EF.cs b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EF.cs
new file mode 100644
index 0000000000000000000000000000000000000000..978658abca5a8b9d9f338e36b0329b535a1f8ba5
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EF.cs
@@ -0,0 +1,95 @@
+using Common.UnitOfWork;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Storage;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Common.UnitOfWork4EntityFramework
+{
+ public class UnitOfWork4EF : IUnitOfWork
+ {
+
+ private bool isActive = false;
+ private bool isEnabled = false;
+ private bool hasCommitted = false;
+ public readonly DbContext dbContext;
+ private IDbContextTransaction dbContextTransaction=null;
+ private int beginLevel = 0;
+
+ public UnitOfWork4EF(DbContext dbContext)
+ {
+ this.dbContext = dbContext;
+ }
+
+
+ public bool Commit()
+ {
+ beginLevel--;
+ //如果开启了多层事务,则最外层才提交
+ if (beginLevel > 0||!isActive)
+ {
+
+ hasCommitted = true;
+ return hasCommitted;
+ }
+
+ isActive = false;
+ try
+ {
+ dbContext.SaveChanges();
+ dbContextTransaction.Commit();
+ hasCommitted = true;
+ return hasCommitted;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.ToString());
+ //回滚
+ dbContextTransaction.Rollback();
+ return false;
+ }
+
+ }
+
+ public void Dispose()
+ {
+ if(isActive)
+ Commit();
+ if (!isActive)
+ dbContextTransaction?.Dispose();
+ }
+
+ public bool IsActive()
+ {
+ return isEnabled && isActive;
+ }
+
+ public void Begin()
+ {
+ if (!isEnabled) return;
+ beginLevel++;
+ if (this.isActive) return;
+ this.dbContextTransaction = dbContext.Database.BeginTransaction();
+ isActive = true;
+ }
+ public void BeginWithoutLevel()
+ {
+ if (!isEnabled) return;
+ //TODO暂时先注释掉这个事务
+ if (this.isActive) return;
+ this.dbContextTransaction = dbContext.Database.BeginTransaction();
+ isActive = true;
+ }
+
+ public void Enabled()
+ {
+ this.isEnabled = true;
+ }
+
+ public bool HasCommitted()
+ {
+ return isEnabled&&hasCommitted;
+ }
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EntityFrameworkModule.cs b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EntityFrameworkModule.cs
new file mode 100644
index 0000000000000000000000000000000000000000..1ca566521cc1d04e5d8f0d12a95116ab69e9bed7
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWork4EntityFrameworkModule.cs
@@ -0,0 +1,18 @@
+using Common.UnitOfWork;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Common.UnitOfWork4EntityFramework
+{
+ public static class UnitOfWork4EntityFrameworkModule
+ {
+ public static IServiceCollection AddUnitOfWork4EntityFramework(this IServiceCollection services)
+ {
+ services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork4EF));
+ services.AddScoped(typeof(IUnitOfWorkManager), typeof(UnitOfWorkManager4EF));
+ return services;
+ }
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWorkManager4EF.cs b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWorkManager4EF.cs
new file mode 100644
index 0000000000000000000000000000000000000000..2fdd12d4e91995152dd9a1c68ddb40559e855c3e
--- /dev/null
+++ b/WorkFlowCore/Commons/Common.UnitOfWork4EntityFramework/UnitOfWorkManager4EF.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Common.UnitOfWork;
+
+namespace Common.UnitOfWork4EntityFramework
+{
+ public class UnitOfWorkManager4EF : IUnitOfWorkManager
+ {
+ private readonly UnitOfWork4EF unitOfWork;
+
+ public UnitOfWorkManager4EF(IUnitOfWork unitOfWork)
+ {
+ this.unitOfWork = (UnitOfWork4EF)unitOfWork;
+ }
+
+ public IUnitOfWork Begin()
+ {
+ unitOfWork.Begin();
+ return unitOfWork;
+ }
+ }
+}
diff --git a/WorkFlowCore/Dockerfile4DynamicForm b/WorkFlowCore/Dockerfile4DynamicForm
index a55c586d6518cb52caab57b16d33e66e550e7f0f..779ab2c2ddf9f3069af0307a600ad3a2b7ad9f18 100644
--- a/WorkFlowCore/Dockerfile4DynamicForm
+++ b/WorkFlowCore/Dockerfile4DynamicForm
@@ -10,22 +10,22 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
-COPY ["DynamicForm/DynamicForm.Host/DynamicForm.Host.csproj", "DynamicForm/DynamicForm.Host/"]
-COPY ["DynamicForm/DynamicForm.Framework/DynamicForm.Framework.csproj", "DynamicForm/DynamicForm.Framework/"]
-COPY ["DynamicForm/DynamicForm.Core/DynamicForm.Core.csproj", "DynamicForm/DynamicForm.Core/"]
-COPY ["Commons/Common.IBaseRepositories4EF/Common.IBaseRepositories4EF.csproj", "Commons/Common.IBaseRepositories4EF/"]
-COPY ["Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj", "Commons/Common.IBaseRepositories/"]
-COPY ["Commons/Common.Authorization/Common.Authorization.csproj", "Commons/Common.Authorization/"]
-COPY ["Commons/Common.MicroService/Common.MicroService.csproj", "Commons/Common.MicroService/"]
-COPY ["Commons/Common.WebApi/Common.WebApi.csproj", "Commons/Common.WebApi/"]
-COPY ["Commons/Common.EventBus/Common.EventBus.csproj", "Commons/Common.EventBus/"]
-COPY ["Commons/Common.DynamicApi/Common.DynamicApi.csproj", "Commons/Common.DynamicApi/"]
-COPY ["Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj", "Commons/Common.BaseRepositories4EF/"]
-COPY ["DynamicForm/DynamicForm.AppService/DynamicForm.AppService.csproj", "DynamicForm/DynamicForm.AppService/"]
-COPY ["DynamicForm/DynamicForm.IAppService/DynamicForm.IAppService.csproj", "DynamicForm/DynamicForm.IAppService/"]
-COPY ["Commons/Common.AppService/Common.AppService.csproj", "Commons/Common.AppService/"]
-COPY ["Commons/Common.DependencyInjection/Common.DependencyInjection.csproj", "Commons/Common.DependencyInjection/"]
-RUN dotnet restore "DynamicForm/DynamicForm.Host/DynamicForm.Host.csproj"
+# COPY ["DynamicForm/DynamicForm.Host/DynamicForm.Host.csproj", "DynamicForm/DynamicForm.Host/"]
+# COPY ["DynamicForm/DynamicForm.Framework/DynamicForm.Framework.csproj", "DynamicForm/DynamicForm.Framework/"]
+# COPY ["DynamicForm/DynamicForm.Core/DynamicForm.Core.csproj", "DynamicForm/DynamicForm.Core/"]
+# COPY ["Commons/Common.IBaseRepositories4EF/Common.IBaseRepositories4EF.csproj", "Commons/Common.IBaseRepositories4EF/"]
+# COPY ["Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj", "Commons/Common.IBaseRepositories/"]
+# COPY ["Commons/Common.Authorization/Common.Authorization.csproj", "Commons/Common.Authorization/"]
+# COPY ["Commons/Common.MicroService/Common.MicroService.csproj", "Commons/Common.MicroService/"]
+# COPY ["Commons/Common.WebApi/Common.WebApi.csproj", "Commons/Common.WebApi/"]
+# COPY ["Commons/Common.EventBus/Common.EventBus.csproj", "Commons/Common.EventBus/"]
+# COPY ["Commons/Common.DynamicApi/Common.DynamicApi.csproj", "Commons/Common.DynamicApi/"]
+# COPY ["Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj", "Commons/Common.BaseRepositories4EF/"]
+# COPY ["DynamicForm/DynamicForm.AppService/DynamicForm.AppService.csproj", "DynamicForm/DynamicForm.AppService/"]
+# COPY ["DynamicForm/DynamicForm.IAppService/DynamicForm.IAppService.csproj", "DynamicForm/DynamicForm.IAppService/"]
+# COPY ["Commons/Common.AppService/Common.AppService.csproj", "Commons/Common.AppService/"]
+# COPY ["Commons/Common.DependencyInjection/Common.DependencyInjection.csproj", "Commons/Common.DependencyInjection/"]
+
COPY . .
WORKDIR "/src/DynamicForm/DynamicForm.Host"
RUN dotnet build "DynamicForm.Host.csproj" -c Release -o /app/build
diff --git a/WorkFlowCore/Dockerfile4InternalGetaway b/WorkFlowCore/Dockerfile4InternalGetaway
index fff4383f9dc89fb90384ff86aeabc67155fa1d03..c43feecc3995cdaf2cba345094501caf8a0ba5a6 100644
--- a/WorkFlowCore/Dockerfile4InternalGetaway
+++ b/WorkFlowCore/Dockerfile4InternalGetaway
@@ -6,8 +6,8 @@ EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
-COPY ["Gateways/InternalGateway.Host/InternalGateway.Host.csproj", "Gateways/InternalGateway.Host/"]
-RUN dotnet restore "Gateways/InternalGateway.Host/InternalGateway.Host.csproj"
+# COPY ["Gateways/InternalGateway.Host/InternalGateway.Host.csproj", "Gateways/InternalGateway.Host/"]
+# RUN dotnet restore "Gateways/InternalGateway.Host/InternalGateway.Host.csproj"
COPY . .
WORKDIR "/src/Gateways/InternalGateway.Host"
RUN dotnet build "InternalGateway.Host.csproj" -c Release -o /app/build
diff --git a/WorkFlowCore/Dockerfile4Organization b/WorkFlowCore/Dockerfile4Organization
index 02995b0e011e64fa14f4fa448f5208f38e12f38f..ae5af0b93ccd0c6a3c9a7e58ef7ee965562896ac 100644
--- a/WorkFlowCore/Dockerfile4Organization
+++ b/WorkFlowCore/Dockerfile4Organization
@@ -8,22 +8,22 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
-COPY ["UserOrganization/Organization.Host/Organization.Host.csproj", "UserOrganization/Organization.Host/"]
-COPY ["Commons/Common.IBaseRepositories4EF/Common.IBaseRepositories4EF.csproj", "Commons/Common.IBaseRepositories4EF/"]
-COPY ["Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj", "Commons/Common.IBaseRepositories/"]
-COPY ["UserOrganization/Organization.Framework/Organization.Framework.csproj", "UserOrganization/Organization.Framework/"]
-COPY ["Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj", "Commons/Common.BaseRepositories4EF/"]
-COPY ["Commons/Common.Authorization/Common.Authorization.csproj", "Commons/Common.Authorization/"]
-COPY ["UserOrganization/Organization.Core/Organization.Core.csproj", "UserOrganization/Organization.Core/"]
-COPY ["Commons/Common.EventBus/Common.EventBus.csproj", "Commons/Common.EventBus/"]
-COPY ["UserOrganization/Organization.AppService/Organization.AppService.csproj", "UserOrganization/Organization.AppService/"]
-COPY ["UserOrganization/Organization.IAppService/Organization.IAppService.csproj", "UserOrganization/Organization.IAppService/"]
-COPY ["Commons/Common.AppService/Common.AppService.csproj", "Commons/Common.AppService/"]
-COPY ["Commons/Common.DynamicApi/Common.DynamicApi.csproj", "Commons/Common.DynamicApi/"]
-COPY ["Commons/Common.WebApi/Common.WebApi.csproj", "Commons/Common.WebApi/"]
-COPY ["Commons/Common.MicroService/Common.MicroService.csproj", "Commons/Common.MicroService/"]
-COPY ["Commons/Common.DependencyInjection/Common.DependencyInjection.csproj", "Commons/Common.DependencyInjection/"]
-RUN dotnet restore "UserOrganization/Organization.Host/Organization.Host.csproj"
+# COPY ["UserOrganization/Organization.Host/Organization.Host.csproj", "UserOrganization/Organization.Host/"]
+# COPY ["Commons/Common.IBaseRepositories4EF/Common.IBaseRepositories4EF.csproj", "Commons/Common.IBaseRepositories4EF/"]
+# COPY ["Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj", "Commons/Common.IBaseRepositories/"]
+# COPY ["UserOrganization/Organization.Framework/Organization.Framework.csproj", "UserOrganization/Organization.Framework/"]
+# COPY ["Commons/Common.BaseRepositories4EF/Common.BaseRepositories4EF.csproj", "Commons/Common.BaseRepositories4EF/"]
+# COPY ["Commons/Common.Authorization/Common.Authorization.csproj", "Commons/Common.Authorization/"]
+# COPY ["UserOrganization/Organization.Core/Organization.Core.csproj", "UserOrganization/Organization.Core/"]
+# COPY ["Commons/Common.EventBus/Common.EventBus.csproj", "Commons/Common.EventBus/"]
+# COPY ["UserOrganization/Organization.AppService/Organization.AppService.csproj", "UserOrganization/Organization.AppService/"]
+# COPY ["UserOrganization/Organization.IAppService/Organization.IAppService.csproj", "UserOrganization/Organization.IAppService/"]
+# COPY ["Commons/Common.AppService/Common.AppService.csproj", "Commons/Common.AppService/"]
+# COPY ["Commons/Common.DynamicApi/Common.DynamicApi.csproj", "Commons/Common.DynamicApi/"]
+# COPY ["Commons/Common.WebApi/Common.WebApi.csproj", "Commons/Common.WebApi/"]
+# COPY ["Commons/Common.MicroService/Common.MicroService.csproj", "Commons/Common.MicroService/"]
+# COPY ["Commons/Common.DependencyInjection/Common.DependencyInjection.csproj", "Commons/Common.DependencyInjection/"]
+# RUN dotnet restore "UserOrganization/Organization.Host/Organization.Host.csproj"
COPY . .
WORKDIR "/src/UserOrganization/Organization.Host"
RUN dotnet build "Organization.Host.csproj" -c Release -o /app/build
diff --git a/WorkFlowCore/Dockerfile4Workflow b/WorkFlowCore/Dockerfile4Workflow
index a727027150e62ae70b78140fffc2abf54acc09dd..a02200c55db1089822aed04fe9585b6082a19ba4 100644
--- a/WorkFlowCore/Dockerfile4Workflow
+++ b/WorkFlowCore/Dockerfile4Workflow
@@ -7,19 +7,19 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
-COPY ["Workflow/WorkFlowCore.Host/WorkFlowCore.Host.csproj", "Workflow/WorkFlowCore.Host/"]
-COPY ["Workflow/WorkFlowCore/WorkFlowCore.csproj", "Workflow/WorkFlowCore/"]
-COPY ["Commons/Common.EventBus/Common.EventBus.csproj", "Commons/Common.EventBus/"]
-COPY ["Commons/Common.MicroService/Common.MicroService.csproj", "Commons/Common.MicroService/"]
-COPY ["Workflow/WorkFlowCore.Framework/WorkFlowCore.Framework.csproj", "Workflow/WorkFlowCore.Framework/"]
-COPY ["Workflow/WorkFlowCore.AppService/WorkFlowCore.AppService.csproj", "WorkFlowCore.AppService/"]
-COPY ["Workflow/WorkFlowCore.IAppService/WorkFlowCore.IAppService.csproj", "WorkFlowCore.IAppService/"]
-COPY ["Commons/Common.DynamicApi/Common.DynamicApi.csproj", "Commons/Common.DynamicApi/"]
-COPY ["Commons/Common.WebApi/Common.WebApi.csproj", "Commons/Common.WebApi/"]
-COPY ["Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj", "Commons/Common.IBaseRepositories/"]
-COPY ["Commons/Common.IBaseRepositories4EF/Common.IBaseRepositories4EF.csproj", "Commons/Common.IBaseRepositories4EF/"]
-COPY ["Commons/Common.DependencyInjection/Common.DependencyInjection.csproj", "Commons/Common.DependencyInjection/"]
-RUN dotnet restore "Workflow/WorkFlowCore.Host/WorkFlowCore.Host.csproj"
+# COPY ["Workflow/WorkFlowCore.Host/WorkFlowCore.Host.csproj", "Workflow/WorkFlowCore.Host/"]
+# COPY ["Workflow/WorkFlowCore/WorkFlowCore.csproj", "Workflow/WorkFlowCore/"]
+# COPY ["Commons/Common.EventBus/Common.EventBus.csproj", "Commons/Common.EventBus/"]
+# COPY ["Commons/Common.MicroService/Common.MicroService.csproj", "Commons/Common.MicroService/"]
+# COPY ["Workflow/WorkFlowCore.Framework/WorkFlowCore.Framework.csproj", "Workflow/WorkFlowCore.Framework/"]
+# COPY ["Workflow/WorkFlowCore.AppService/WorkFlowCore.AppService.csproj", "WorkFlowCore.AppService/"]
+# COPY ["Workflow/WorkFlowCore.IAppService/WorkFlowCore.IAppService.csproj", "WorkFlowCore.IAppService/"]
+# COPY ["Commons/Common.DynamicApi/Common.DynamicApi.csproj", "Commons/Common.DynamicApi/"]
+# COPY ["Commons/Common.WebApi/Common.WebApi.csproj", "Commons/Common.WebApi/"]
+# COPY ["Commons/Common.IBaseRepositories/Common.IBaseRepositories.csproj", "Commons/Common.IBaseRepositories/"]
+# COPY ["Commons/Common.IBaseRepositories4EF/Common.IBaseRepositories4EF.csproj", "Commons/Common.IBaseRepositories4EF/"]
+# COPY ["Commons/Common.DependencyInjection/Common.DependencyInjection.csproj", "Commons/Common.DependencyInjection/"]
+# RUN dotnet restore "Workflow/WorkFlowCore.Host/WorkFlowCore.Host.csproj"
COPY . .
WORKDIR "/src/Workflow/WorkFlowCore.Host"
RUN dotnet build "WorkFlowCore.Host.csproj" -c Release -o /app/build
diff --git a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs
index fdc4bd5bbfe6b9c3697fa5bcf77f2c84f60499f6..350affed78ccf8eda7a71b23ff029eb0e46994c7 100644
--- a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs
+++ b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/TaskStateChangeEventHandler.cs
@@ -1,5 +1,4 @@
using Common.EventBus;
-using Common.EventBus.Implements.Kafka;
using Common.IBaseRepositories;
using Microsoft.Extensions.Logging;
using System;
diff --git a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/UserChangeEventHandler.cs b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/UserChangeEventHandler.cs
index 67ef5b968f60625387330d05441bb353ff3acaed..c1395ae20d2e2d20072bc4cf927e53d25f9b47bc 100644
--- a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/UserChangeEventHandler.cs
+++ b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/UserChangeEventHandler.cs
@@ -1,6 +1,5 @@
using Common.DependencyInjection;
using Common.EventBus;
-using Common.EventBus.Implements.Kafka;
using Common.IBaseRepositories;
using DynamicForm.Core.Users;
using Newtonsoft.Json;
diff --git a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/WorkflowVersionChangeEventHandler.cs b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/WorkflowVersionChangeEventHandler.cs
index 8d9de064836a88e189587016da957b5fb5c7da22..6104996eec825e404f173a50eb90a26aaf135368 100644
--- a/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/WorkflowVersionChangeEventHandler.cs
+++ b/WorkFlowCore/DynamicForm/DynamicForm.AppService/EventHandlers/WorkflowVersionChangeEventHandler.cs
@@ -1,6 +1,5 @@
using Common.DependencyInjection;
using Common.EventBus;
-using Common.EventBus.Implements.Kafka;
using Common.IBaseRepositories;
using DynamicForm.Core.Workflows;
using System;
diff --git a/WorkFlowCore/DynamicForm/DynamicForm.Host/DynamicForm.Host.csproj b/WorkFlowCore/DynamicForm/DynamicForm.Host/DynamicForm.Host.csproj
index ee7d2bea62623272382d5828de5b34dbd811c777..c1e9c52fe7bbaf2d0157bcc94999a19dfe86e94c 100644
--- a/WorkFlowCore/DynamicForm/DynamicForm.Host/DynamicForm.Host.csproj
+++ b/WorkFlowCore/DynamicForm/DynamicForm.Host/DynamicForm.Host.csproj
@@ -1,4 +1,4 @@
-
+
netcoreapp3.1
@@ -22,7 +22,8 @@
-
+
+
diff --git a/WorkFlowCore/DynamicForm/DynamicForm.Host/Startup.cs b/WorkFlowCore/DynamicForm/DynamicForm.Host/Startup.cs
index bce54bcd6d7a5b128d994482dce7e755d4e4e74e..e1715d014d7f20f66fe11bc943fcabc1b70c71fb 100644
--- a/WorkFlowCore/DynamicForm/DynamicForm.Host/Startup.cs
+++ b/WorkFlowCore/DynamicForm/DynamicForm.Host/Startup.cs
@@ -3,6 +3,7 @@ using Common.BackgroundWorker;
using Common.EventBus;
using Common.EventBus.Kafka;
using Common.MicroService.Registers;
+using Common.UnitOfWork;
using DynamicForm.AppService;
using DynamicForm.Core;
using DynamicForm.Framework;
@@ -103,13 +104,15 @@ namespace DynamicForm.Host
app.UseRouting();
app.UseAuthorization();
-
+ app.UseEventBus();
+ app.RunKafkaEventBus();
+ app.UseUnitOfWork();
+
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
- app.RunEventBus();
- app.RunKafkaEventBus();
+
//עconsul
app.RunConsulRegister(options =>
{
diff --git "a/WorkFlowCore/ReadmeImges/\345\255\220\345\237\237\345\205\263\347\263\273\345\233\276.png" "b/WorkFlowCore/ReadmeImges/\345\255\220\345\237\237\345\205\263\347\263\273\345\233\276.png"
new file mode 100644
index 0000000000000000000000000000000000000000..cfcf93463e4a18e962d41d2d567871e2f5e49e92
Binary files /dev/null and "b/WorkFlowCore/ReadmeImges/\345\255\220\345\237\237\345\205\263\347\263\273\345\233\276.png" differ
diff --git "a/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\347\263\273\347\273\237\345\222\214\344\270\232\345\212\241\347\263\273\347\273\237\345\205\263\347\263\273.png" "b/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\347\263\273\347\273\237\345\222\214\344\270\232\345\212\241\347\263\273\347\273\237\345\205\263\347\263\273.png"
new file mode 100644
index 0000000000000000000000000000000000000000..5485a87c5f67a2d92440c5d8fbfbc65d5445f144
Binary files /dev/null and "b/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\347\263\273\347\273\237\345\222\214\344\270\232\345\212\241\347\263\273\347\273\237\345\205\263\347\263\273.png" differ
diff --git "a/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\347\274\226\350\276\221.png" "b/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\347\274\226\350\276\221.png"
new file mode 100644
index 0000000000000000000000000000000000000000..0cea0fd3bb9cc83f912d5728f26143b2399487fc
Binary files /dev/null and "b/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\347\274\226\350\276\221.png" differ
diff --git "a/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\350\256\276\350\256\241.png" "b/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\350\256\276\350\256\241.png"
new file mode 100644
index 0000000000000000000000000000000000000000..b96cb523ef460de0771e86631a78071919773ada
Binary files /dev/null and "b/WorkFlowCore/ReadmeImges/\346\265\201\347\250\213\350\256\276\350\256\241.png" differ
diff --git a/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs b/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs
index 308af0dcd1f607ed9c31f45eba2b2d85a326dc99..4855a9591542729aa35943262a7ffdc61155a36a 100644
--- a/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs
+++ b/WorkFlowCore/UserOrganization/Organization.AppService/OrganizationAppModule.cs
@@ -22,7 +22,7 @@ namespace Organization.AppService
options?.Invoke(serviceConfig);
services.AddDependencyServices(Assembly.GetExecutingAssembly());
- services.AddOrganizationCore(serviceConfig.CoreOptions);
+
services.AddDefautEventBus(Assembly.GetExecutingAssembly(), typeof(OrganizationCoreModule).Assembly);
@@ -51,10 +51,6 @@ namespace Organization.AppService
/// kafka连接地址配置
///
public string KafkaBootstrapServers { get; set; }
- ///
- /// 领域层配置
- ///
- public Action CoreOptions { get; set; }
}
}
}
diff --git a/WorkFlowCore/UserOrganization/Organization.Framework/Repositories/OrganizationRepository.cs b/WorkFlowCore/UserOrganization/Organization.Framework/Repositories/OrganizationRepository.cs
index c3ccec2ee1324d512b670cfb40342717a1d447b2..05dfcea953830dde4c55a218e64f0ccac538c8a5 100644
--- a/WorkFlowCore/UserOrganization/Organization.Framework/Repositories/OrganizationRepository.cs
+++ b/WorkFlowCore/UserOrganization/Organization.Framework/Repositories/OrganizationRepository.cs
@@ -1,6 +1,7 @@
using Common.Authorization;
using Common.BaseRepositories4EF;
using Common.IBaseRepositories;
+using Common.UnitOfWork;
using Microsoft.EntityFrameworkCore;
using Organization.Core.Organizations.IRepositories;
using System;
diff --git a/WorkFlowCore/UserOrganization/Organization.Host/Organization.Host.csproj b/WorkFlowCore/UserOrganization/Organization.Host/Organization.Host.csproj
index 26d474cb25449ea5735e2afa4e0644e3ca8f9890..72ec77cd231ab10ecddc3836b5c69afe41e9996f 100644
--- a/WorkFlowCore/UserOrganization/Organization.Host/Organization.Host.csproj
+++ b/WorkFlowCore/UserOrganization/Organization.Host/Organization.Host.csproj
@@ -23,10 +23,10 @@
-
+
diff --git a/WorkFlowCore/UserOrganization/Organization.Host/Startup.cs b/WorkFlowCore/UserOrganization/Organization.Host/Startup.cs
index c0bd593a4a1a8ffe3fccc38a6c84d67c99b3f780..bafdc022beafa881533558e3774c6b4ca524bdd0 100644
--- a/WorkFlowCore/UserOrganization/Organization.Host/Startup.cs
+++ b/WorkFlowCore/UserOrganization/Organization.Host/Startup.cs
@@ -3,8 +3,10 @@ using Common.BackgroundWorker;
using Common.BaseRepositories4EF;
using Common.DynamicApi;
using Common.EventBus;
+using Common.EventBus.Kafka;
using Common.MicroService;
using Common.MicroService.Registers;
+using Common.UnitOfWork;
using Common.WebApi.Filters;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@@ -47,14 +49,14 @@ namespace Organization.Host
options.DbConnectionString = Configuration.GetValueFromManyChanels("ConnectionStrings:Default");
});
+ services.AddOrganizationCore(options =>
+ {
+ options.MicroServiceGateway = Configuration.GetValueFromManyChanels("Gateway");
+ });
services.AddOrganizationApp(options =>
{
options.AddDynamicControllers();
options.KafkaBootstrapServers = Configuration.GetValueFromManyChanels("Kafka:BootstrapServers");
- options.CoreOptions = coreOptions =>
- {
- coreOptions.MicroServiceGateway = Configuration.GetValueFromManyChanels("Gateway");
- };
});
services.AddSwaggerGen(c =>
{
@@ -100,7 +102,9 @@ namespace Organization.Host
app.UseRouting();
app.UseAuthorization();
-
+ app.UseEventBus();
+ app.RunKafkaEventBus();
+ app.UseUnitOfWork();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
@@ -117,7 +121,7 @@ namespace Organization.Host
options.ServiceName = Configuration.GetValueFromManyChanels("Service:Name");
}, lifetime);
//ע��ȫ���¼�����
- app.RunEventBus();
+
//������̨��������
app.RunBackgroundWorker();
}
diff --git a/WorkFlowCore/WorkFlowCore.Common/EventBus/BaseEventData.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/BaseEventData.cs
new file mode 100644
index 0000000000000000000000000000000000000000..c9654545552743bb1284c732ba015f706a57e57d
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/BaseEventData.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WorkFlowCore.Common.EventBus
+{
+ public class BaseEventData
+ {
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Common/EventBus/EventBusManager.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/EventBusManager.cs
new file mode 100644
index 0000000000000000000000000000000000000000..9ed0bff7b6f5c704de00d39ed3c448a0e20d50f9
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/EventBusManager.cs
@@ -0,0 +1,41 @@
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WorkFlowCore.Common.EventBus
+{
+ ///
+ /// 全局静态事件帮助类,便于在其它非注入渠道发起事件
+ ///
+ public class EventBusManager
+ {
+ private static IServiceProvider serviceProvider;
+ internal static void Init(IServiceProvider serviceProvider)
+ {
+ EventBusManager.serviceProvider = serviceProvider;
+ }
+
+ public IEventBus Instance()
+ {
+ return (IEventBus)serviceProvider.GetService(typeof(IEventBus));
+ }
+
+ public void Trigger(TData data) where TData:BaseEventData
+ {
+ if (data == null) return;
+ var services =serviceProvider.GetServices();
+ foreach (var service in services)
+ {
+ try
+ {
+ service.Trigger(data);
+ }
+ catch (Exception ex)
+ {
+ Console.Error.WriteLine(ex.ToString());
+ }
+ }
+ }
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Common/EventBus/EventBusService.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/EventBusService.cs
new file mode 100644
index 0000000000000000000000000000000000000000..25dbe32bae0a37654d6c5954fb0c3032a8e9e1dc
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/EventBusService.cs
@@ -0,0 +1,53 @@
+using WorkFlowCore.Common.EventBus.Implements.Kafka;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Text;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.Configuration;
+
+namespace WorkFlowCore.Common.EventBus
+{
+ public static class EventBusService
+ {
+
+ public static IServiceCollection AddDefautEventBus(this IServiceCollection services,params Assembly[] assemblies)
+ {
+ services.AddSingleton(typeof(IEventBus), typeof(DefaultEventBus));
+ services.AddSingleton(typeof(DefaultEventBus));
+ foreach (var assembly in assemblies)
+ {
+ DefaultEventBus.RegistSubscriptions(assembly);
+ }
+ services.AddSingleton();
+ return services;
+ }
+ public static IServiceCollection AddKafkaEventBus(this IServiceCollection services, Action options)
+ {
+ services.AddSingleton(typeof(IEventBus), typeof(KafkaEventBus));
+ services.AddSingleton(typeof(KafkaEventBus));
+ var config = new KafkaEventConfig();
+ options?.Invoke(config);
+ services.AddSingleton(provider => config);
+ services.AddSingleton();
+ return services;
+ }
+ public static IApplicationBuilder InitGlobalEventBus(this IApplicationBuilder app)
+ {
+ //注册普通事件,该事件订阅在单应用有效无法分布式
+ EventBusManager.Init(app.ApplicationServices);
+
+ //注册kafka作为分布式事件
+ var kafkaEventBus = app.ApplicationServices.GetService();
+ var config = app.ApplicationServices.GetService();
+ var configuration = app.ApplicationServices.GetService();
+ Console.WriteLine("servers:" + configuration["KafkaBootstrapServers"]);
+ if (kafkaEventBus!=null&&config!=null && config.RegisterAssemblies != null)
+ kafkaEventBus.RegistSubscriptions(config.RegisterAssemblies);
+
+ return app;
+
+ }
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Common/EventBus/IEventBus.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/IEventBus.cs
new file mode 100644
index 0000000000000000000000000000000000000000..29de4f25ded7171e11b584909d0c59d1aca6b6ab
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/IEventBus.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WorkFlowCore.Common.EventBus
+{
+ public interface IEventBus
+ {
+ void SubscribeEventHandler(Type eventDataType, Type handlerType);
+ void UnsubscribeEventHandler(Type eventDataType, Type handlerType);
+ void SubscribeEventHandler() where THandler : IEventHandler where TData : BaseEventData;
+ void UnsubscribeEventHandler() where THandler : IEventHandler where TData : BaseEventData;
+ void Trigger(TData data);
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Common/EventBus/IEventHandler.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/IEventHandler.cs
new file mode 100644
index 0000000000000000000000000000000000000000..b560364622065b4542b16516d76bdf23177d3dfd
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/IEventHandler.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WorkFlowCore.Common.EventBus
+{
+ public interface IEventHandler
+ {
+
+ }
+
+ public interface IEventHandler: IEventHandler where TData:BaseEventData
+ {
+ void Handle(TData data);
+ }
+}
diff --git a/WorkFlowCore/Commons/Common.EventBus/Implements/Default/DefaultEventBus.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Default/DefaultEventBus.cs
similarity index 40%
rename from WorkFlowCore/Commons/Common.EventBus/Implements/Default/DefaultEventBus.cs
rename to WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Default/DefaultEventBus.cs
index 377a4c7c92b891570e9eaf92b1b28bf0c57cbffc..9ccc7941e20105370a309437c36bf604f9df13b9 100644
--- a/WorkFlowCore/Commons/Common.EventBus/Implements/Default/DefaultEventBus.cs
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Default/DefaultEventBus.cs
@@ -1,42 +1,14 @@
-using Common.IBaseRepositories;
-using Microsoft.Extensions.DependencyInjection;
-using Newtonsoft.Json;
+using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
-namespace Common.EventBus
+namespace WorkFlowCore.Common.EventBus
{
-
public class DefaultEventBus : IEventBus
{
- private class ConsumerInfo
- {
- public ConsumerInfo()
- {
- }
-
- public ConsumerInfo(string groupId, Type handlerType, Type dataType, string toptic)
- {
- GroupId = groupId;
- HandlerType = handlerType;
- DataType = dataType;
- Toptic = toptic;
- }
-
- public string Toptic { get; set; }
- public string GroupId { get; set; }
- public Type HandlerType { get; set; }
- public Type DataType { get; set; }
-
- public override int GetHashCode()
- {
- return $"{GroupId},{HandlerType?.FullName},{DataType?.FullName}".GetHashCode();
- }
- }
-
private IServiceProvider serviceProvider;
private static object objLock = new object();
@@ -45,72 +17,31 @@ namespace Common.EventBus
this.serviceProvider = serviceProvider;
}
- private static Dictionary> eventSubscribes;
+ private static Dictionary> eventSubscribes;
static DefaultEventBus()
{
- eventSubscribes = new Dictionary>();
- }
-
- private static ConsumerInfo GetConsumerInfo( Type handlerType, Type eventDataType)
- {
- string toptic = GetToptic(eventDataType, handlerType);
-
- var groupId = handlerType.FullName;
- var groupIdAttr = handlerType.GetCustomAttribute();
- if (groupIdAttr != null)
- {
- groupId = string.IsNullOrEmpty(groupIdAttr.GroupId) ? handlerType.FullName : groupIdAttr.GroupId;
- }
- var newConsumerInfo = new ConsumerInfo(groupId, handlerType, eventDataType, toptic);
- return newConsumerInfo;
+ eventSubscribes = new Dictionary>();
}
- private static string GetToptic(Type eventDataType, Type handlerType=null)
+ private static void Subscribe(Type eventDataType, Type handlerType)
{
- var toptic = eventDataType.FullName;
- var topicAttrOfData = eventDataType.GetCustomAttribute();
- var topicAttrOfHandler = handlerType?.GetCustomAttribute();
- if (topicAttrOfHandler != null && !string.IsNullOrEmpty(topicAttrOfHandler.Topic))
+ lock (objLock)
{
- toptic = topicAttrOfHandler.Topic;
+ if (!eventSubscribes.ContainsKey(eventDataType))
+ eventSubscribes.Add(eventDataType, new List { });
}
- if (topicAttrOfData != null && !string.IsNullOrEmpty(topicAttrOfData.Topic))
- {
- toptic = topicAttrOfData.Topic;
- }
+ eventSubscribes[eventDataType].Add(handlerType);
- return toptic;
- }
- private static void Subscribe(Type eventDataType, Type handlerType)
- {
- try
- {
- var newConsumerInfo = GetConsumerInfo(handlerType, eventDataType);
- lock (objLock)
- {
- if (!eventSubscribes.ContainsKey(newConsumerInfo.Toptic))
- eventSubscribes.Add(newConsumerInfo.Toptic, new List());
-
-
- if (!eventSubscribes[newConsumerInfo.Toptic].Any(s => s.Equals(newConsumerInfo)))
- eventSubscribes[newConsumerInfo.Toptic].Add(newConsumerInfo);
- }
- }
- catch (Exception e)
- {
-//
- }
}
private static void Unsubscribe(Type eventDataType, Type handlerType)
{
- var newConsumerInfo = GetConsumerInfo(handlerType, eventDataType);
+ if (!eventSubscribes.ContainsKey(eventDataType)) return;
- if (!eventSubscribes.ContainsKey(newConsumerInfo.Toptic)) return;
- if (!eventSubscribes[newConsumerInfo.Toptic].Any(s => s.Equals(newConsumerInfo))) return;
- eventSubscribes[newConsumerInfo.Toptic] = eventSubscribes[newConsumerInfo.Toptic].Where(s => !s.Equals(newConsumerInfo)).ToList();
+ if (eventSubscribes[eventDataType].Contains(handlerType))
+ eventSubscribes[eventDataType].Remove(handlerType);
}
public static void Subscribe() where THandler : IEventHandler where TData:BaseEventData
@@ -153,29 +84,17 @@ namespace Common.EventBus
}
}
- public void Trigger(TData data)where TData : new()
+ public void Trigger(TData data)
{
- var toptic = GetToptic(data.GetType());
-
- if (!eventSubscribes.ContainsKey(toptic)) return;
- //消费者按groupid 分组,即同 一组的消费者只能有一个去事件
- var consumers = eventSubscribes[toptic]?.GroupBy(c => c.GroupId).Select(g => g.First()).ToList();
-
- var dataStr = JsonConvert.SerializeObject(data);
- consumers.ForEach(consumer =>
+ var eventDataType =typeof(TData);
+ if (!eventSubscribes.ContainsKey(eventDataType)) return;
+ var handlerTypes = eventSubscribes[eventDataType];
+ handlerTypes.ForEach(handlerType =>
{
using(var scope = serviceProvider.CreateScope())
{
- var handlerType = consumer.HandlerType;
var handler = scope.ServiceProvider.GetService(handlerType);
- var eventDataType = consumer.DataType;
- if (handler == null) return;
- handlerType.GetMethod("Handle", new Type[] { eventDataType }).Invoke(handler, new object[] { JsonConvert.DeserializeObject(dataStr, eventDataType) });
- //统一工作单元提交,无需事件单独处理
- var unitOfWork = scope.ServiceProvider.GetService();
-
- var domainEventBusService = scope.ServiceProvider.GetService();
- if (unitOfWork.Commit()) domainEventBusService?.Trigger();
+ handlerType.GetMethod("Handle", new Type[] { eventDataType }).Invoke(handler, new object[] { data });
}
});
diff --git a/WorkFlowCore/Commons/Common.EventBus/Implements/Kafka/KafkaEventBus.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventBus.cs
similarity index 73%
rename from WorkFlowCore/Commons/Common.EventBus/Implements/Kafka/KafkaEventBus.cs
rename to WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventBus.cs
index 8cc9b0fc4568972e99c297aded3f13fc0b54b3bc..1fd2b84df63f625f57ffd1aa3ba2dd41de89c122 100644
--- a/WorkFlowCore/Commons/Common.EventBus/Implements/Kafka/KafkaEventBus.cs
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventBus.cs
@@ -1,8 +1,6 @@
-using Common.EventBus.Implements.Kafka;
-using Common.IBaseRepositories;
+using WorkFlowCore.Common.EventBus.Implements.Kafka;
using Confluent.Kafka;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -12,20 +10,18 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
-namespace Common.EventBus
+namespace WorkFlowCore.Common.EventBus
{
public class KafkaEventBus : IEventBus
{
private IServiceProvider serviceProvider;
private readonly KafkaEventConfig eventConfig;
- private readonly ILogger logger;
private static object objLock = new object();
- public KafkaEventBus(IServiceProvider serviceProvider, KafkaEventConfig eventConfig,ILogger logger)
+ public KafkaEventBus(IServiceProvider serviceProvider, KafkaEventConfig eventConfig)
{
this.serviceProvider = serviceProvider;
this.eventConfig = eventConfig;
- this.logger = logger;
Console.WriteLine(eventConfig.Servers);
}
@@ -37,31 +33,21 @@ namespace Common.EventBus
eventSubscribeCancellationTokenSources = new Dictionary();
}
- private async Task SubscribeAsync(Type eventDataType, Type handlerType)
+ private void SubscribeAsync(Type eventDataType, Type handlerType)
{
- await Task.CompletedTask;
var subscribesKey = eventDataType.FullName + handlerType.FullName;
if (eventSubscribes.ContainsKey(subscribesKey)) return;
+ //不做标记的不处理
+ var topicAttr = eventDataType.GetCustomAttribute();
+ if (topicAttr == null) return;
+ var toptic = string.IsNullOrEmpty(topicAttr.Topic)?eventDataType.FullName: topicAttr.Topic;
- //topic 默认从Handler的标记获取,其次从eventData,最后才是全类名
- var toptic = eventDataType.FullName;
- var topicAttrOfData = eventDataType.GetCustomAttribute();
- var topicAttrOfHandler = handlerType.GetCustomAttribute();
- if (topicAttrOfHandler != null && !string.IsNullOrEmpty(topicAttrOfHandler.Topic))
- {
- toptic = topicAttrOfHandler.Topic;
- }
- if (topicAttrOfData != null&& !string.IsNullOrEmpty(topicAttrOfData.Topic))
- {
- toptic = topicAttrOfData.Topic;
- }
-
- var groupIdAttr = handlerType.GetCustomAttribute();
+ var groupIdAttr = handlerType.GetCustomAttribute();
if (groupIdAttr == null) return;
- var groupId = string.IsNullOrEmpty(groupIdAttr.GroupId) ? handlerType.FullName : groupIdAttr.GroupId;
+ var groupId = string.IsNullOrEmpty(groupIdAttr.GroupId)?handlerType.FullName: groupIdAttr.GroupId;
var conf = new ConsumerConfig
{
GroupId = groupId,
@@ -95,12 +81,6 @@ namespace Common.EventBus
{
var handler = scope.ServiceProvider.GetService(handlerType);
handlerType.GetMethod("Handle", new Type[] { eventDataType }).Invoke(handler, new object[] { data });
- //统一工作单元提交,无需事件单独处理
- var unitOfWork = scope.ServiceProvider.GetService();
-
- var domainEventBusService = scope.ServiceProvider.GetService();
- if (unitOfWork.Commit()) domainEventBusService?.Trigger();
-
}
c.Commit(cr);
}
@@ -184,50 +164,39 @@ namespace Common.EventBus
foreach (var type in types)
{
- try
- {
- Subscribe(type);
- }
- catch (Exception ex)
- {
- logger.LogError(ex.ToString());
- }
+ Subscribe(type);
}
}
}
- private void Callback(DeliveryReport r)
- {
- Console.WriteLine(!r.Error.IsError
- ? $"Delivered message to {r.TopicPartitionOffset}"
- : $"Delivery Error: {r.Error.Reason}");
-
-
- }
-
private void TriggerEvent(TData data)
{
if (data == null) return;
var conf = new ProducerConfig { BootstrapServers = eventConfig.Servers };
-
+ Action> handler = r =>
+ Console.WriteLine(!r.Error.IsError
+ ? $"Delivered message to {r.TopicPartitionOffset}"
+ : $"Delivery Error: {r.Error.Reason}");
//不做标记不处理
- var topicAttr = data.GetType().GetCustomAttribute();
- var toptic = topicAttr != null ? topicAttr.Topic : data.GetType().FullName;
+ var topicAttr = typeof(TData).GetCustomAttribute();
+ var toptic = topicAttr != null ? topicAttr.Topic : typeof(TData).FullName;
using (var p = new ProducerBuilder(conf).Build())
{
- p.Produce(toptic, new Message { Value = JsonConvert.SerializeObject(data) }, Callback);
+ p.Produce(toptic, new Message { Value = JsonConvert.SerializeObject(data) }, handler);
// wait for up to 10 seconds for any inflight messages to be delivered.
- p.Flush(TimeSpan.FromSeconds(30));
- //p.Flush();
+ p.Flush(TimeSpan.FromSeconds(10));
}
}
- public void Trigger(TData data) where TData : new()
+ public void Trigger(TData data)
{
- TriggerEvent(data);
+ Task.Run(() =>
+ {
+ TriggerEvent(data);
+ });
}
public void SubscribeEventHandler(Type eventDataType, Type handlerType)
diff --git a/WorkFlowCore/Commons/Common.EventBus/Implements/Kafka/KafkaEventConfig.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventConfig.cs
similarity index 33%
rename from WorkFlowCore/Commons/Common.EventBus/Implements/Kafka/KafkaEventConfig.cs
rename to WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventConfig.cs
index 6f2129e3b99987c6a03347bb20a219b6059df33d..a2fde47df22d86a6ae587fd6c37c46f7328ffd2a 100644
--- a/WorkFlowCore/Commons/Common.EventBus/Implements/Kafka/KafkaEventConfig.cs
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventConfig.cs
@@ -3,22 +3,11 @@ using System.Collections.Generic;
using System.Reflection;
using System.Text;
-namespace Common.EventBus.Implements.Kafka
+namespace WorkFlowCore.Common.EventBus.Implements.Kafka
{
public class KafkaEventConfig
{
- public KafkaEventConfig()
- {
- RegisterAssemblies = new List();
- }
-
public string Servers { get; set; }
- internal List RegisterAssemblies { get; set; }
-
- public void AddAssemblies(params Assembly[] assemblies)
- {
- if (assemblies != null) RegisterAssemblies.AddRange(assemblies);
- }
-
+ public Assembly[] RegisterAssemblies { get; set; }
}
}
diff --git a/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventConsumerAttribute.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventConsumerAttribute.cs
new file mode 100644
index 0000000000000000000000000000000000000000..7e773a7e65c1c910008b4f66aac8744576cf983e
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventConsumerAttribute.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WorkFlowCore.Common.EventBus.Implements.Kafka
+{
+ public class KafkaEventConsumerAttribute : Attribute
+ {
+ public string GroupId { get; set; }
+
+ public KafkaEventConsumerAttribute(string groupId=null)
+ {
+ GroupId = groupId;
+ }
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventTopicAttribute.cs b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventTopicAttribute.cs
new file mode 100644
index 0000000000000000000000000000000000000000..cc2f244ff4f569a5dbc5cb7eae93483d6542e569
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/EventBus/Implements/Kafka/KafkaEventTopicAttribute.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WorkFlowCore.Common.EventBus.Implements.Kafka
+{
+ public class KafkaEventTopicAttribute: Attribute
+ {
+ public string Topic { get; set; }
+
+ public KafkaEventTopicAttribute(string topic=null)
+ {
+ Topic = topic;
+ }
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Common/WorkFlowCore.Common.csproj b/WorkFlowCore/WorkFlowCore.Common/WorkFlowCore.Common.csproj
new file mode 100644
index 0000000000000000000000000000000000000000..eb6327ac829433b7686a0ece63067d7c5088e6f3
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Common/WorkFlowCore.Common.csproj
@@ -0,0 +1,15 @@
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WorkFlowCore/WorkFlowCore.Framework/EventHandlers/SendTaskEventHandler.cs b/WorkFlowCore/WorkFlowCore.Framework/EventHandlers/SendTaskEventHandler.cs
new file mode 100644
index 0000000000000000000000000000000000000000..5ddde4f03e256920d308ffa649adb690486d1ac0
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Framework/EventHandlers/SendTaskEventHandler.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using WorkFlowCore.Common.EventBus;
+using WorkFlowCore.EventData;
+using WorkFlowCore.WorkTasks;
+
+namespace WorkFlowCore.Framework.EventHandlers
+{
+ public class SendTaskEventHandler : IEventHandler
+ {
+ public void Handle(SendTaskEventData data)
+ {
+ Console.WriteLine("SendTask");
+ }
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Framework/EventHandlers/TaskFinishedEventHandler.cs b/WorkFlowCore/WorkFlowCore.Framework/EventHandlers/TaskFinishedEventHandler.cs
new file mode 100644
index 0000000000000000000000000000000000000000..c4610b1c24803a7ab0e633f67bdc84c9c498481d
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Framework/EventHandlers/TaskFinishedEventHandler.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using WorkFlowCore.Common.EventBus;
+using WorkFlowCore.EventData;
+using WorkFlowCore.WorkTasks;
+
+namespace WorkFlowCore.Framework.EventHandlers
+{
+ public class TaskFinishedEventHandler : IEventHandler
+ {
+ public void Handle(TaskFinishedEventData data)
+ {
+ Console.WriteLine("TaskFinished");
+ }
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Framework/Repositories4EF/WorkStepRepository4EF.cs b/WorkFlowCore/WorkFlowCore.Framework/Repositories4EF/WorkStepRepository4EF.cs
new file mode 100644
index 0000000000000000000000000000000000000000..4c6bedef0fb6224208e5405dda594a5ca2accc1b
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Framework/Repositories4EF/WorkStepRepository4EF.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WorkFlowCore.Authorization;
+using WorkFlowCore.IRepositories;
+using WorkFlowCore.WorkTasks;
+
+namespace WorkFlowCore.Framework.Repositories4EF
+{
+ public class WorkStepRepository4EF : BasicRepository4EF, IWorkStepRepository
+ {
+ public WorkStepRepository4EF(WorkflowDbContext workflowDbContext, IUnitOfWork unitOfWork, IWorkflowSession session) : base(workflowDbContext, unitOfWork, session)
+ {
+ }
+
+ public async Task> GetUnHandlerWorkStepsOfUserAsync(string userId, int pageIndex = 1, int pageSize = -1)
+ {
+ var result = new PageResult
+ {
+ Total = (await GetCountAsync(ws => ws.HandleUser_Id == userId && !ws.IsHandled))
+ };
+ if (pageSize < 1)
+ result.Items = (await GetListAsync(ws => ws.HandleUser_Id == userId && !ws.IsHandled)).Select(w => w.ToWorkStep()).ToList();
+ else result.Items = (await GetPagedListAsync(ws => ws.HandleUser_Id == userId && !ws.IsHandled,(pageIndex-1)*pageSize,pageSize,"createdtime desc")).Select(w => w.ToWorkStep()).ToList();
+ return await Task.FromResult(result);
+ }
+ }
+}
diff --git a/WorkFlowCore/WorkFlowCore.Framework/WorkFlowCore.Framework.csproj b/WorkFlowCore/WorkFlowCore.Framework/WorkFlowCore.Framework.csproj
new file mode 100644
index 0000000000000000000000000000000000000000..a9f729199920ecf760be2e519e226be47d6adbc2
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Framework/WorkFlowCore.Framework.csproj
@@ -0,0 +1,20 @@
+
+
+
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WorkFlowCore/WorkFlowCore.Host/Controllers/WorkFlowController.cs b/WorkFlowCore/WorkFlowCore.Host/Controllers/WorkFlowController.cs
new file mode 100644
index 0000000000000000000000000000000000000000..fa3be5cc9d95af382e890f60d14545d1cefde5f8
--- /dev/null
+++ b/WorkFlowCore/WorkFlowCore.Host/Controllers/WorkFlowController.cs
@@ -0,0 +1,279 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using WorkFlowCore.Conditions;
+using WorkFlowCore.Framework.UserSelectors;
+using WorkFlowCore.Host.ViewModels;
+using WorkFlowCore.Host.ViewModels.WorkFlowCore;
+using WorkFlowCore.IRepositories;
+using WorkFlowCore.UserSelectors;
+using WorkFlowCore.Workflows;
+using WorkFlowCore.WorkTasks;
+
+namespace WorkFlowCore.Host.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class WorkFlowController : ControllerBase
+ {
+ private ConditionManager conditionManager;
+ private WorkflowManager workflowManager;
+ private IBasicRepository workflowRepository;
+ private IBasicRepository worktaskRepository;
+ private IBasicRepository versionRepository;
+ private IBasicRepository workStepRepository;
+
+
+ public WorkFlowController(ConditionManager conditionManager, WorkflowManager workflowManager, IBasicRepository workflowRepository, IBasicRepository worktaskRepository, IBasicRepository versionRepository, IBasicRepository workStepRepository)
+ {
+ this.conditionManager = conditionManager;
+ this.workflowManager = workflowManager;
+ this.workflowRepository = workflowRepository;
+ this.worktaskRepository = worktaskRepository;
+ this.versionRepository = versionRepository;
+ this.workStepRepository = workStepRepository;
+ }
+ ///
+ /// 获取所有条件
+ ///
+ ///
+ [HttpGet("GetAllconditions")]
+ public async Task>> GetAllconditions()
+ {
+ return OutputDto.Succeed(ConditionManager.AllConditions.Select(c => new ConditionDto { Id = c.Id, Name = c.Name,Description=c.Description }));
+ }
+ ///
+ /// 获取所有的用户选择器
+ ///
+ ///
+ [HttpGet("GetAllUserSelectors")]
+ public async Task>> GetAllUserSelectors()
+ {
+ return OutputDto.Succeed(UserSelectorManager.UserSelectors.Select(us => new UserSeletorDto { Id = us.Id, Name = us.Name, Description = us.Description }));
+ }
+ ///
+ /// 获取用户选择器所提供的选项
+ ///
+ ///
+ ///
+ [HttpGet("GetUserSelectionsOfUserSelector")]
+ public async Task>> GetUserSelectionsOfUserSelector(string userSelectorId)
+ {
+ return OutputDto.Succeed(workflowManager.GetUserSelectionsOfUserSelector(userSelectorId).Result);
+ }
+
+ ///
+ /// 创建新流程
+ ///
+ ///
+ ///
+ [HttpPost("CreateWorkFlow")]
+ public async Task> CreateWorkFlow(CreateWorkFlowInput input)
+ {
+ return OutputDto.Succeed(await workflowManager.CreateWorkflow($"WF{DateTime.Now.ToString("yyyMMddHHmmssfff")}", input.Name, input.Des));
+ }
+ ///
+ /// 获取所有流程列表
+ ///
+ ///
+ [HttpGet("GetAllWorkflows")]
+ public async Task>> GetAllWorkflows()
+ {
+ return OutputDto.Succeed((await workflowRepository.GetListAsync()).OrderByDescending(w=>w.CreationTime).ToList());
+ }
+ ///
+ /// 获取流程所有版本信息
+ ///
+ ///
+ ///
+ [HttpGet("GetAllWorkflowVersions")]
+ public async Task>> GetAllWorkflowVersions(Guid workflowId)
+ {
+ return OutputDto.Succeed((await versionRepository.GetListAsync(v => v.WorkflowId == workflowId)).Select(v => new GetAllWorkflowVersionOutput
+ {
+ WorkflowId = v.WorkflowId,
+ VersionNo = v.VersionNo,
+ Description = v.Description,
+ CreationTime = v.CreationTime,
+ ModifiedTime = v.ModifiedTime
+ }));
+ }
+ ///
+ /// 获取流程具体版本信息
+ ///
+ ///
+ ///
+ [HttpGet("GetWorkflowVersion")]
+ public async Task> GetWorkflowVersion(int versionId, Guid id)
+ {
+ return OutputDto.Succeed(await workflowManager.GetWorkflowVersion(id, versionId));
+ }
+ ///
+ /// 删除流程
+ ///
+ ///
+ ///
+ [HttpGet("DeleteWorkflowVersion")]
+ public async Task> GetWorkflowVersion(Guid id)
+ {
+ var result = await workflowManager.DeleteWorkflow(id);
+ return OutputDto.Result(result, result);
+ }
+ ///
+ /// 更新流程激活的版本
+ ///
+ ///
+ ///
+ [HttpPut("UpdateWorkflowActiveVersion")]
+ public async Task> UpdateWorkflowActiveVersion(UpdateWorkflowActiveVersionInput input)
+ {
+ var result =await workflowManager.UpdateWorkflowActiveVersion(input.WorkflowId, input.ActiveVersion);
+ return result?OutputDto.Succeed(true): OutputDto.Failed("");
+ }
+
+
+ ///
+ /// 更新流程
+ ///
+ ///
+ ///
+ [HttpPut("UpdateWorkFlow")]
+ public async Task> UpdateWorkFlow(UpdateWorkFlowInput input)
+ {
+ return OutputDto.Succeed(await workflowManager.UpdateWorkflow(input.WorkflowId.Id, input.Name, input.Des, input.WorkflowId.VersionId, input.DrawingInfo, input.VersionDescription
+ , input.WorkflowLines.Select(line => new WorkflowLine(line.Name, input.WorkflowId, line.FromNodeId, line.ToNodeId, line.Conditions)).ToList()
+ , input.WorkflowNodes.Select(node => new WorkflowNode(node.Id, input.WorkflowId, node.Name, node.NodeType, node.DrawingInfo, node.IsWaitingAllUser, node.UserSelectors, node.RejectNodes)).ToList()));
+ }
+
+
+ ///
+ /// 创建流程任务
+ ///
+ ///
+ ///
+ [HttpPost("CreateWorkTask")]
+ public async Task> CreateWorkTask(CreateWorkTaskInput input)
+ {
+ var worktask = await workflowManager.CreateWorkTask(input.WorkflowId, input.Name, input.FormData, input.EntityFullName, input.EntityKeyValue,input.CreatedUserId);
+ return OutputDto.Succeed(worktask);
+ }
+
+ ///
+ /// 获取流程任务
+ ///
+ ///
+ ///
+ [HttpGet("GetWorkTask")]
+ public async Task> GetWorkTask(Guid id)
+ {
+ var worktask = await workflowManager.GetWorkTaskAsync(id);
+ return OutputDto.Succeed(worktask);
+ }
+
+
+ ///
+ /// 发起流程
+ ///
+ ///
+ ///
+ [HttpPost("StartWorkTask")]
+ public async Task>> StartWorkTask(StartWorkTaskInput input)
+ {
+ var steps = await workflowManager.WorkTaskStart(input.WorktaskId);
+ return OutputDto.Succeed(steps);
+ }
+ ///
+ /// 通过审批
+ ///
+ ///
+ ///
+ [HttpPost("PassProve")]
+ public async Task>> PassProve(ProveInput input)
+ {
+ var proveResult = await workflowManager.PassApprove(input.StepId, input.Comment, input.ResourceIds);
+ if (proveResult.Code == ProveResult.ProveResultCode.SUCCESS)
+ return OutputDto.Succeed(proveResult.WorkSteps);
+ return OutputDto.Failed>(proveResult.Msg);
+ }
+ ///
+ /// 驳回审批
+ ///
+ ///
+ ///
+ [HttpPost("RejectProve")]
+ public async Task>> RejectProve(ProveInput input)
+ {
+ var proveResult = await workflowManager.RejectApprove(input.StepId, input.Comment, input.ResourceIds);
+ if (proveResult.Code == ProveResult.ProveResultCode.SUCCESS)
+ return OutputDto.Succeed(proveResult.WorkSteps);
+ return OutputDto.Failed>(proveResult.Msg);
+ }
+ ///
+ /// 撤回审批
+ ///
+ ///
+ ///
+ [HttpPost("WithdrawProve")]
+ public async Task>> WithdrawProve(ProveInput input)
+ {
+ var proveResult = await workflowManager.Withdraw(input.StepId, input.Comment);
+ if (proveResult.Code == ProveResult.ProveResultCode.SUCCESS)
+ return OutputDto.Succeed(proveResult.WorkSteps);
+ return OutputDto.Failed>(proveResult.Msg);
+ }
+ ///
+ /// 转发代办
+ ///
+ ///
+ ///
+ [HttpPost("ForwardProve")]
+ public async Task>> ForwardProve(ForwardProveInput input)
+ {
+ var proveResult = await workflowManager.Forward(input.StepId, input.UserSelectors, input.Comment);
+ if (proveResult.Code == ProveResult.ProveResultCode.SUCCESS)
+ return OutputDto.Succeed(proveResult.WorkSteps);
+ return OutputDto.Failed>(proveResult.Msg);
+ }
+ ///
+ /// 获取所有审批步骤
+ ///
+ ///
+ ///
+ [HttpGet("GetAllTaskStepsOfWorkTask")]
+ public async Task>> GetAllTaskStepsOfWorkTask(Guid worktaskId)
+ {
+ //获取所有过程输出
+ var historySteps =await workflowManager.GetAllTaskStepsOfWorkTaskAsync(worktaskId);
+ return OutputDto.Succeed(historySteps);
+ }
+ ///
+ /// 清除模拟 记录
+ ///
+ ///
+ [HttpPost("ClearSimulationRecord")]
+ public async Task> ClearSimulationRecord()
+ {
+ var worktasks = await worktaskRepository.GetListAsync(wt => wt.Name == "模拟流程");
+ var worktaskIds = worktasks.Select(wt => wt.Id);
+
+ await workStepRepository.DeleteManyAsync(ws => worktaskIds.Contains(ws.WorkTaskId));
+ await worktaskRepository.DeleteManyAsync(wt => worktaskIds.Contains(wt.Id));
+ return OutputDto.Succeed
-
+
diff --git a/WorkFlowCore/Workflow/WorkFlowCore.Test/Repositories/Repositories_Test.cs b/WorkFlowCore/Workflow/WorkFlowCore.Test/Repositories/Repositories_Test.cs
index 0be8f3d05d73cea3f04f778b528828bdcb822569..ab44659b3a70951f26cacf3ea500cf2e654eeba7 100644
--- a/WorkFlowCore/Workflow/WorkFlowCore.Test/Repositories/Repositories_Test.cs
+++ b/WorkFlowCore/Workflow/WorkFlowCore.Test/Repositories/Repositories_Test.cs
@@ -1,4 +1,5 @@
using Common.IBaseRepositories;
+using Common.UnitOfWork;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using System;
diff --git a/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs b/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs
index 758746249f4acebbc3478bf66d4d1d5b23ae86aa..e43388fdab0db58f5eb5015c475e15c4686b44d8 100644
--- a/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs
+++ b/WorkFlowCore/Workflow/WorkFlowCore/WorkTasks/WorkTaskManager.cs
@@ -1,6 +1,7 @@
using Common.DependencyInjection;
using Common.EventBus;
using Common.IBaseRepositories;
+using Common.UnitOfWork;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
diff --git a/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs b/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs
index 63701bed2dfaa58af1a0c58c8e178405adfc566e..3525e4a3621a1cadb5cf893fee849a9e0c36d488 100644
--- a/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs
+++ b/WorkFlowCore/Workflow/WorkFlowCore/Workflows/WorkflowManager.cs
@@ -1,6 +1,7 @@
using Common.DependencyInjection;
using Common.EventBus;
using Common.IBaseRepositories;
+using Common.UnitOfWork;
using System;
using System.Collections.Generic;
using System.Linq;
diff --git a/WorkFlowCore/image20.png b/WorkFlowCore/image20.png
new file mode 100644
index 0000000000000000000000000000000000000000..a1c5ce6447560f3571db26d6247c4408ce439c75
Binary files /dev/null and b/WorkFlowCore/image20.png differ
diff --git a/WorkFlowCore/image21.png b/WorkFlowCore/image21.png
new file mode 100644
index 0000000000000000000000000000000000000000..0f1d308b97e74799a53a2e0ff1b0a9b51fa80af7
Binary files /dev/null and b/WorkFlowCore/image21.png differ